Posts Learn Components Snippets Categories Tags Tools About

Commands To Install LAMP Stack on Ubtuntu 16.04 (Short Guides)

Get to know and learn all the commands to install LAMP stack Linux, Apache, MySQL, PHP on Ubuntu 16.04

Created on Nov 20, 2021


In this short snippet, you will learn all of the commands to install the LAMP stack on Ubuntu 16.04 so let's get started.

Step 1: Register VPS

You can either register Virtual Private Server (VPS) from Hetzner and SSH into the machine.

Step 2: Install Apache

To install Apache you can run the command below. The first one is to update and get the latest packages on Ubuntu and the 2nd one is to install apache2.
sudo apt-get update
sudo apt-get install apache2
Once it's installed configure apache using the command below.
sudo nano /etc/apache2/apache2.conf
From within the file add the following config. Do note that you need to place your server IP which you can retrieve from the VPS provider dashboard.
ServerName server_domain_or_IP
Test the config and restart apache.
sudo apache2ctl configtest
sudo systemctl restart apache2
Next, configure the firewall to allow incoming traffic by using the command below.
sudo ufw allow in "Apache Full"

Step 3: Install MySQL

The next step is to install the MySQL database and you can install it easily using the command below.
sudo apt-get install mysql-server
To fully complete the installation, run the command to display the configuration wizard. Within the installation configuration you will be prompted for the user name, password and etc so do read carefully on that.

Step 4: Install PHP

Next, you will have to install PHP by running the following command. Do note that the other packages / library such as "php-mcrypt" is necessary for PHP so it's a must to install all.
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
Now that you have it installed now we need to allow Apache to find PHP files. Do run the command below to edit the apache.
sudo nano /etc/apache2/mods-enabled/dir.conf
Then the content should be as follows. Do look at the "index.php" carefully, it's after the DirectoryIndex which means it's having more precedent.
<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.xhtml index.htm
Now to apply the changes do run the restart apache command.
sudo systemctl restart apache2
By now you will have the LAMP stack set up on your machine. Cheers and have a good one!

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️