This guide will teach you how to install LAMP, which stands for Linux, Apache, MySQL, and PHP. This will be done on an Ubuntu 16.xx server.
You may copy and paste the codes in your SSH client (Terminal, PuTTY, etc…) or you can just type it in.
Before anything, we will update all of our packages.
sudo apt update
Firstly, we will install the Apache web server on our Ubuntu server:
sudo apt install apache2
Second, we will install MySQL. You will be asked to create a MySQL password:
sudo apt install mysql-server
Thirdly, we will have to configure MySQL. You will be asked to enter your MySQL password that you created in the previous step:
You will be asked a few questions. You may respond to these questions as you wish. It will ask you if you want to install the Validate Password Plugin. I put no. It will then ask you if you want to change your existing password for root. I put no.
Then it will ask you a few questions. Here are the questions with the response I put (y is for yes).
Remove anonymous users?: y
Disallow root login remotely?: y
Remove test database and access to it?: y
Reload privilege tables now?: y
This is the fourth step now. We are going to have to install PHP:
sudo apt install php libapache2-mod-php php-mcrypt php-mysql
After you install PHP, you will have to edit the dir.conf file by doing this:
sudo nano /etc/apache2/mods-enabled/dir.conf
You want to replace this:
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
When you are done replacing the original code with the new one, you want to press Ctrl-X. This will ask you if you want to save the file. Type Y and then press Enter.
The fifth step is to restart Apache:
sudo systemctl restart apache2
Now you’re all done!
To test that PHP is working, you can create a file in your public directory (usually /var/www/html), and create a new file called test.php (or whatever you want to call it). Then paste in this code:
<?php phpinfo(); ?>
If a page with a lot of text and information about your server shows up, then it means it’s working. Good luck and have fun!
A few things you can enable or configure if you wish:
Enable mod_rewrite (for .htaccess):
sudo a2enmod rewrite
service apache2 restart
sudo nano /etc/apache2/apache2.conf
Go down to where it says:
and delete Indexes, and replace None with All and then save the file.
Then restart Apache by running this command: sudo service apache2 restart
sudo a2enmod ssl
sudo a2ensite default-ssl
Install zip and unzip (to zip and unzip files):
sudo apt install zip unzip
Install phpMyAdmin (to manage your databases easier):