Casbay Knowledge Base

Search our articles or browse by category below

Simple LAMP Stack Installation Guide On Linux VPS Server (Ubuntu 18.04)

Last modified: September 30, 2022
You are here:
  • KB Home
  • new
  • Simple LAMP Stack Installation Guide On Linux VPS Server (Ubuntu 18.04)
Estimated reading time: 2 min

LAMP is a stack of programs that works together to build dynamic websites and web applications. The “L” in LAMP stands for Linux, which is your Linux VPS server, “A” stands for Apache, a web server application, “M” for MySQL, a database management system, and P for PHP, a scripting language.

The Linux operating system used in this guide is Ubuntu version 18.04. Note that all of the software installations below require you to log into your VPS using SSH and root access.

Apache2 Installation

As we already have the Ubuntu based VPS, the software after the “L” in the LAMP stack is “A”. So we will start by installing Apache. The version of the Apache used in this guide is Apache2. To begin the installation, we will start by opening our terminal application in Ubuntu by searching through the applications list or right-clicking the desktop and selecting the “Open Terminal option”. Then, use the following command to update your repositories.

sudo apt update -y

Enter your Ubuntu password if you are requested from the terminal. After the repositories were updated, you may start installing the Apache2 web server on your Ubuntu using the following command.

sudo ufw app list

You will be able to see a list of available applications such as the example below.

Available applications:
Apache Full
Apache Secure

MySQL Installation

After completing the Apache installation, the next software in the LAMP stack is MySQL. To install the MySQL database, use the following command and run it in the terminal.

sudo apt install mysql-client-core-5.7

Enter your password when prompted and the installation will begin. During the installation, just select “Yes” when prompted to complete the installation. Once MySQL is done installing, open the MySQL terminal using the following command.

sudo mysql

To set a password for the root user in MySQL, use the following command in the MySQL terminal.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';

Replace the “your_password” with a password of your preference as long as it is complex to be more secure. To implement the changes made, you can use the flush command in MySQL such as the following command.


To close the MySQL terminal, just type in exit and run. Your installation for MySQL is now completed.

PHP Installation

The final software in the LAMP stack is PHP. To install PHP onto your system, run the following command in your terminal.

sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-xml php-mbstring php-xmlrpc php-zip php-soap php-intl -y

By default, the “index.html” file will be the main directory. However, you want “index.php” to be loaded as your main directory, and to do so, open the configuration file using any text editor of your preference. For the case of using nano text editor, use the following command to open the configuration file.

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

You should be able to see the sequence of the directories, replace “index.html” with “index.php” and move “index.cgi” to the far right of the sequence. Make save changes and exit the text editor. To implement changes made, you have to restart the Apache server by using the following command.

sudo systemctl restart apache2

To verify if PHP is installed correctly and working as intended, create a test PHP file naming it “test.php” and add the following code into the file.


Add the created file into the web root directory of Apache, “/var/www/html/”, and access the file by entering “http://public_ip_address/test.php” into your web browser and verify if it works by seeing if there’s any output from the code you had used for your “test.php”.

Was this article helpful?
Dislike 0
Previous: WordPress Installation Guide On Linux VPS Server For Ubuntu 18.04
Next: Server Hack with Exim spamming