Wesbytes Knowledge Base

Search our articles or browse by category below

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

Last modified: July 2, 2022
You are here:
Estimated reading time: 2 min

Building dynamic websites and web apps is made possible by the LAMP software stack. The letters “L” and “A” in LAMP stand for Linux, the operating system of your Linux virtual private server, “M” for MySQL, a database management system, and “P” for PHP, a programming language.

Version 18.04 of Ubuntu is the Linux operating system used in this manual. Please take note that the software installations listed below all call for root access and SSH access to your VPS.

Apache2 Installation

Since we already have a VPS running Ubuntu, the next piece of software in the LAMP stack is “A.” So, installing Apache will be our first step. This manual makes use of Apache2 as the web server. To start the installation, we will first open the terminal application in Ubuntu by either searching through the apps list or using the right-click context menu to choose “Open Terminal” from the desktop. Then, update your repositories using the following command.

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
Apache Full
Apache Secure
OpenSSH

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

When prompted, enter your password to start the installation. Simply choose “Yes” when requested to finish the installation during the process. Use the following command to launch the MySQL terminal when MySQL has finished installing.

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.

FLUSH PRIVILEGES;

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-mbst

The primary directory will by default be the “index.html” file. To ensure that “index.php” loads as your main directory, however, open the configuration file in your preferred text editor. Use the following command to open the configuration file if you are using the nano text editor.

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

Replace “index.html” with “index.php” and move “index.cgi” to the very end of the directory sequence if you can see the order of the directories. Exit the text editor after saving your changes. You must use the following command to restart the Apache server in order to apply modifications.

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.

<?php
phpinfo();
?>

Add the created file to Apache’s “/var/www/html/” web root directory. Access the file by typing “http://public_ip_address/test.php” into your web browser, and check to see if any output is produced by the code you used for “test.php” to see if it is working.

Was this article helpful?
Dislike 0
Views: 9