LAMP simply stands for Linux Apache MySQL PHP
This tutorial will not cover the installation of Linux, instead we will cover the following:
- Install Apache
- Install MySQL
- Install PHP
Step 1 – Install Apache
sudo apt-get install apache2
Some tutorials recommend editing /etc/apache2/mods-enabled/dir.conf and placing index.php before index.html. What this does is simply tell Apache to server PHP files before serving HTML files. E.g Apache will serve index.php before it serves index.html.
Step 2 – Install MySQL
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
To break this command down:
- mysql-server installs MySQL server (surprise surprise ?
- libapache2-mod-auth-mysql allows for HTTP authentication against a MySQL database
- php5-mysql allows PHP to communicate with MySQL
The MySQL installer will prompt you to enter a password for the root MySQL user.
Prior to securing MySQL, you will need to run a command which instructs MySQL to create the necessary tables for storage of its configuration:
sudo mysql_install_db
Next up is securing MySQL:
sudo mysql_secure_installation
Throughout the installation you will be prompted to enter the root password you entered above (if any). You will be further prompted to confirm the removal of test databases and demo users – simply hit enter to accept the default answer for all the questions.
Step 3 – Install PHP
sudo apt-get install php5 libapache2-mod-php5
To break this command down:
- php5 installs PHP version 5
- libapache2-mod-php5 installs the PHP module for Apache
Now for a quick restart of Apache
sudo service apache2 restart
The next step generally is to install common PHP modules. These are dependent on your requirements, but we suggest running the following command:
sudo apt-get install php5-curl php5-gd php5-common
To break this command down:
- php5-curl provides the ability for PHP to communicate with FTP, GOPHER, and web servers
- php5-gd gives PHP the ability handle graphics directly from PHP scripts
- php5-common provides common libraries for PHP
Now for a quick restart of Apache
sudo service apache2 restart
That completes the installation of AMP as part of the LAMP stack.
You may want to test that everything is in order by running the following commands:
sudo rm /var/www/html/index.html
This removes the index.html file in your web directory
sudo nano /var/www/html/index.php
This create index.php in your web directory
Now paste the following in the open Nano editor:
<?php
phpinfo();
?>```
This will display information pertaining to your installation in your web browser and allow you to determine whether things have been setup correctly.
Press CTRL + o and press ENTER to save the file
Press CTRL + x to exit the file
Open your web browser and paste the following:
http://localhost/index.php