The acronym LAMP defines a set of applications essential for a web server functioning : Linux + Apache + MySQL + PHP/Perl/Python.

This tutorial is made to set up and configure step-by-step a LAMP server with PHP.


Apache installation

At first, it is important to install Apache on the concerned machine via the following command :

 apt-get install apache2

It will be essential to know the machine’s IP address to install from ifconfig.

 ifconfig eth0 | grep inet | awk '{ print $2 }'
    addr:10.0.0.8

MySQL installation

Then, you need to install MySQL via the following command :

 apt-get install mysql-server

During the installation, you will be asked to choose a password root.

It is advised to carefully choose your password preferably alphanumeric and including special characters.

To continue with the installation, the following command must be executed :

 mysql_secure_installation

Enter your password root when requested and confirm the 4 following questions with yes :

 Enter current password for root (enter for none):
    OK, successfully used password, moving on...

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
... Success!

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

PHP installation

Finally, all there’s left is to install PHP via the following command.

 apt-get install php5 php-pear php5-mysql

By responding yes to the question, the installation operates.

To conclude, it is essential to restart the apache service :

 service apache2 restart

Use

At first, we are going to check that PHP works by creating our first file on the server :

 echo "<?php phpinfo(); ?>" >> /var/www/phpinfo.php

the page is available from the URL adapted to your IP address

PHP manual

Your LAMP server with PHP is now operational and usable.