HugeServer Knowledgebase

How to install LAMP (Apache, MySQL, PHP) Stack on Ubuntu 16

LAMP stack is a popular web platform commonly used to run websites and servers. (Linux,Apache,MySQL,PHP)

The LAMP Softwares are completely replaceable with other similar Softwares, and it’s not limited to the original bundle.
as a web stack, LAMP is suitable for building dynamic websites and web applications

We are assuming that you have root permission, otherwise, you may start commands with “sudo”.

Before You Begin

You have to update your repositories cache to get the latest versions. execute:

 apt‐get update

Install and configure Apache 2.4

Install apache 2.4:

 apt-get install apache2

You can change the configurations using a text editor (Optional)

 nano /etc/apache2/apache2.conf

And after changing the configurations you should restart apache2:

 systemctl restart apache2

Install MySQL

For installing MySQL type:

 apt‐get install mysql‐server

Input a secure password when prompted by the installation.
Run secure installation to remove the test database and any user permissions added during the installation.

 mysql_secure_installation

It’s recommended to select yes (y) for all questions. if you already have a secure root password you don’t need to change it.

Setup MySQL Database

Now you can create a database and grant your users permissions.
Login to MySQL:

 mysql ‐u root ‐p

For creating a database and granting permissions to users you can use following commands: (you may change the values of “dbname”,”username”,”password” to your own values)

mysql> create database dbname;
-> grant all on dbname.* to 'username' identified by 'password';

Exit MySQL

mysql> quit

Install PHP

In this section, we have 2 options to install PHP 7 or PHP 5, the official repository of  Ubuntu 16 only provides PHP 7 at the moment, as you will see we have to add an unofficial repository in order to install PHP 5.

Install PHP 7

Install PHP with the following command:

 apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi  php7.0 libapache2-mod-php7.0

Now it’s time to test the PHP software that you just installed. move to your public web directory:

 cd /var/www/html

Now use your favorite text editor to create a file named info.php

 nano info.php

Inside that file, type the following:

<?php phpinfo(); ?>

You can use your Domain or Private IP address to see the following page:
php info page ubuntu 16

Install PHP 5.6

In this tutorial we are using PPA repository:

apt-get install python-software-properties
add-apt-repository ppa:ondrej/php
apt-get update
apt-get install -y php5.6

Now you have to make our Apache to work with PHP 5:

a2enmod php5.6
systemctl restart apache2

Finally, we are going to test our PHP5:
move to your public web directory:

 cd /var/www/html

Now use your favorite text editor to create a file named info.php

 nano info.php

Inside that file, type the following:

<?php phpinfo(); ?>

You can use your Domain or Private IP address to see the following page:

ubuntu lam stack php5 test page info.php

Was this tutorial helpful?

Thank you for your vote.Thank you for your vote.

Similar Posts

Leave a Reply

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

*