Skip to content

Instantly share code, notes, and snippets.

@shahalom
Last active January 22, 2022 16:03
Show Gist options
  • Save shahalom/5ddde09361dd59b0a7c5fcf39d5352f3 to your computer and use it in GitHub Desktop.
Save shahalom/5ddde09361dd59b0a7c5fcf39d5352f3 to your computer and use it in GitHub Desktop.
One by one steps to Install LAMP (with multiple PHP versions) in a fresh new UBUNTU operating system
Step 1: Update your distro
=> `$ sudo apt update`
Step 2: Add Repository and again update your distro
=> `$ sudo add-apt-repository ppa:ondrej/php`
Step 3: Install Apache2
=> `$ sudo apt install apache2`
Step 4: Here I am going to install PHP php5.6 and php7.4 versions
=> `$ sudo apt install php5.6 php7.4`
=> `$ sudo service apache2 restart`
Step 5: Lets check the available PHP versions and enabled PHP version [optional]
=> `sudo update-alternatives --config php`
Step 6: Use one of the following command to enable your chose PHP version
=> `$ sudo a2dismod php5.6 && sudo a2enmod php7.4`
OR,
=> `$ sudo a2dismod php7.4 && sudo a2enmod php5.6`
Restart the server: `$ sudo systemctl restart apache2`
Step 7: Install MySQL server
=> `$ sudo apt install mysql-common mysql-server`
Step 8: Install the following PHP modules
=> `$ sudo apt install php5.6-curl`
=> `$ sudo apt install php7.4-curl`
=> `$ sudo apt-get install php5.6-mbstring`
=> `$ sudo apt-get install php7.4-mbstring -y`
=> `$ sudo phpenmod -v 5.6 gettext`
=> `$ sudo phpenmod -v 7.4 gettext`
=> `$ sudo apt install php7.4-mysqli`
Restart the server: `$ sudo systemctl restart apache2`
Step 9: Install PhpMyadmin
=> `$ sudo apt install phpmyadmin -y`
=> `$ sudo phpenmod mbstring`
Restart the server: `$ sudo systemctl restart apache2`
Step 10: Check if soft link is created at `/etc/apache2/conf-available/phpmyadmin.conf`. if not created then create using the below command:
=> `$ sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf`
=> `$ sudo a2enconf phpmyadmin`
Step 11: If URL not found error (Optional)
Enter the following command to edit the Apache configuration file.
=> `$ sudo -H geany /etc/apache2/apache2.conf`
Now add the following line to the end of the file.
=> `Include /etc/phpmyadmin/apache.conf`
Restart the server: `$ sudo systemctl restart apache2`
Step 12: Create a Database User
=> `$ sudo mysql`
Create a new user (mohammadshah with password Qwerty) by typing the following command in the terminal.
=> `$ CREATE USER 'dbroot'@'localhost' IDENTIFIED BY 'MyPassword';`
Grant all permissions to the created user by running the following query.
=> `$ GRANT ALL PRIVILEGES ON *.* TO 'dbroot'@'localhost' WITH GRANT OPTION;`
=> `$ exit`
Step 13: Lets move `www` folder from `/var/www/html` to `/home/username/www`
=> Create `www` folder in user home folder.
=> Open the `/etc/apache2/sites-enabled/000-default` file, edit documentRoot as `/home/USERNAME/www` from `/var/www/html`.
=> Open the `/etc/apache2/apache2.conf` file where you would see `<Directory /var/www/>`, Change it to `<Directory /home/USERNAME/www/>`.
=> `$ sudo service apache2 restart`
Step 14: Enable `.htaccess` module
=> Open `/etc/apache2/apache2.conf` file and edit the "AllowOverride None" to "AllowOverride All"
under the `<Directory /var/www/>` or `<Directory /home/USERNAME/www/>`.
=> `$ sudo a2enmod rewrite`
=> `$ sudo systemctl restart apache2`
Cheers! Hope everything is fine ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment