A LAMP is actually an acronym which represents the Linux operating system, with the Apache web server, data is stored in a MySQL database, and content is processed by PHP. In this guide, we’ll get a LAMP stack installed on an Ubuntu 16.04 virtual private server (VPS).

Before we get started, you need to login to your VPS as ‘root’ via SSH. You can use a SSH client like PuTTY. In this tutorial I’ve used MobaXterm which is a very good software bundled with SFTP and other clients.

Install Apache And Allow In Firewall

After you login to your VPS visa SSH, you’ll see a terminal like this.

Before we start, run a apt-get update

sudo apt-get update

The Apache web server is among the most popular web servers in the world which makes it a great default choice for hosting a website. We use apt to install apache2.

sudo apt-get install apache2

You will see the following prompt : “After this operation, 6,438 kB of additional disk space will be used. Do you want to continue? [Y/n]”

Press Y to continue.

We need edithe apache config file to get rid of a recurring error. To do this type the following on you terminal.

sudo nano /etc/apache2/apache2.conf

This will open up the config file in ‘nano’. Nano is a text editor that uses the command line interface to edit files. Here’s the basics, you can use the keyboard arrows/mouse scroll wheel to navigate in a document. Make the changes you need and once you are done, press Ctrl + x and then press Y to save changes.

How the file looks in Nano

Now we want to add our server’s IP address. Add this line to the bottom of the config file.

ServerName server_IP

Replace server_IP with the IP of your VPS server, you can also put your domain name here but make sure the domain A records are pointed towards this server. See the following image for a representation.

After you are done, save and exit. Now type the following command to restart apache and let the changes take effect.

sudo systemctl restart apache2

Now we need allow apache to receive requests in the firewall. If you have not yet set up a firewall, you should set it up via ‘ufw’. Assuming you have it set up, type the following command to let apache through.

sudo ufw allow in "Apache Full"

You can check right away to verify that everything went as planned by visiting your server’s public IP address in your web browser. If you see something similar, congrats your apache webserver is running !

Install MySQL And Configure

MySQL is an open-source relational database management system. This is absolutely necessary if you want to set a WordPress site or any other CMS. Installing MySQL is pretty easy. Run the following command.

sudo apt-get install mysql-server

You will be shown a list of the packages that will be installed, along with the amount of disk space they’ll take up. Press Y to continue.

During the installation, your server will ask you to select and confirm a password for the MySQL “root” user. Make you set a strong password for your admin user.

Install PHP And Configure

PHP will help us display dynamic content. It can run scripts, connect to our MySQL database. It is a crucial part of a webserver. Run the following command to install.

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

We want apache to prefer PHP files in a directory and serve that PHP file. To do this we edit the dir.conf file.

sudo nano /etc/apache2/mods-enabled/dir.conf

Put index.php at the front after DirectoryIndex.

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

Refer to the following photo for a demonstration.

Now we need restart the apache webserver.

sudo systemctl restart apache2

See the apache status.

sudo systemctl status apache2

You’ll see something similar which means your configuration is fine !

If you want to just create a LAMP stack then you can stop here. If you want to setup your MySQL server for wordpress or other CMS like Joomla, Drupal, Ghost, Magento etc continue reading.

Create MySQL Database and User for WordPress/Other CMS

Type the following to login into mysql account.

mysql -u root -p

We will now create a database. The following command will create a database named ‘wordpress’ . You can name it whatever you like.


Next, we are going to create a separate MySQL user account that we will use exclusively to operate on our new database. We name it ‘wordpressuser’ and set a strong password by changing ‘password’.

GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

We need to flush the privileges so that the current instance of MySQL knows about the recent changes we’ve made:


Exit the mysql prompt.


A thing you should notice is the semi colon after sql query. You need to type a semi colon after every sql query otherwise it would not work.

Install Additional PHP Extensions

We can download and install some of the most popular PHP extensions for use with WordPress by typing:

sudo apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc
sudo systemctl restart apache2

Allow for .htaccess Overrides and Rewrites

sudo nano /etc/apache2/apache2.conf

Towards the bottom of the file, add the following block.

<Directory /var/www/html/>
    AllowOverride All

Next, we can enable mod_rewrite so that we can utilize the WordPress permalink feature

sudo a2enmod rewrite

Restart apache for the changes to take effect.

sudo systemctl restart apache2

Wrapping Up

You can now use these mysql credentials to continue to install wordpress. If you liked this article, share it !