How to setup LAMP stack in Ubuntu 16.04

Step 1: Update packages list
sudo apt-get update
Step 2: Installing apache server
sudo apt-get install apache2

Check the server installation by visiting http://localhost in the web browser

Step 3: [Optional]

If you are getting the error about “Fully qualified domain name”, you need to inform apache server that localhost is the domain name.

sudo vim /etc/apache2/apache2.conf

Add “Servername localhost” at the end of the file.

Step 4: Restart apache server
sudo systemctl restart apache2
Step 5: Installing MySql:sudo apt-get install
sudo apt-get install mysql-server

Give a password to the mysql “root” user

Step 6: Create a new user in Mysql
GRANT ALL PRIVILEGES ON *.* TO 'home'@'localhost' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
Step 7: Installing PHP
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
Step 8: Own the /var/www directory
sudo chown -R home:home /var/www
Step 9: Check PHP installation

Create a php file /var/www/html/index.php with the following text:
phpinfo();
Verify this by loading http://localhost in the web browser

Step 10: To run PHP in the Development settings
sudo mv /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini.bak
sudo cp -s /usr/share/php5/php.ini-development /etc/php5/apache2/php.ini
sudo systemctl restart apache2
Step 11: Install phpmyadmin
sudo apt-get install phpmyadmin php-mbstring php-gettext

select “apache2”
Select “Yes” when asked whether to use dbconfig-common to set up the database
[Optional] You will be prompted for your database administrator’s password
You will then be asked to choose and confirm a password for the phpMyAdmin application itself

sudo phpenmod mcrypt
sudo phpenmod mbstring
sudo systemctl restart apache2
Step 12: If you get a 404 error upon visiting http://localhost/phpmyadmin
sudo vim /etc/apache2/apache2.conf

Include the following line at the bottom of the file, save and quit.
Include /etc/phpmyadmin/apache.conf

sudo systemctl restart apache2
Step 13: [Optional]

You can add one more layer of security for using phpmyadmin using .htpasswd.
More details on this can be found in the digitalocean.com article.

References:

[1] https://help.ubuntu.com/community/ApacheMySQLPHP
[2] https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04

Leave a Reply

Your email address will not be published. Required fields are marked *