Sunday, May 26, 2024
HomeTechnologyHow to Install Linux, Apache, MySQL, and PHP (LAMP) on Ubuntu 16

How to Install Linux, Apache, MySQL, and PHP (LAMP) on Ubuntu 16

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:

sudo mysql_secure_installation

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:

<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.php index.xhtml index.htm

with this:

<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi 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:

<Directory /var/www/>

and delete Indexes, and replace None with All and then save the file.

Then restart Apache by running this command: sudo service apache2 restart


Enable SSL:

sudo a2enmod ssl

sudo service apache2 restart


Enable default-ssl:

sudo a2ensite default-ssl

sudo service apache2 restart


Enable mod_expires and mod_headers (control caching for images and other resources on your site)

sudo a2enmod expires

sudo a2enmod headers

sudo service apache2 restart


Install zip and unzip (to zip and unzip files):

sudo apt install zip unzip

sudo service apache2 restart


Install sendmail (so your server can send emails):

sudo apt install sendmail

sudo service apache2 restart


Install phpMyAdmin (to manage your databases easier):

How to Install phpMyAdmin on Ubuntu 16 (Latest Version)


Comments (Facebook Comments)

TrueSpot Media
TrueSpot Media
The official TrueSpot Media writer and editor. We're a team of awesome people that loves to spend time with family, friends, and new people.
- Advertisment -

Most Popular