vps header 1200x200

4.3 Install LAMP Server and Joomla on a VPS

We have not set up a bridged connection for ns03. We therefore will not be able to use it for our Hestia control panel. But we might be able to use it for local development. We do not want to install Apache server on our host or home LMDE laptop as it might conflict with the Hestia Apache server we will install on ns01 and ns02. But we can install Apache server on ns03 as we can make sure ns03 is turned off before using ns01 or ns02.

We have added ns03 to our etc/hosts file and it is a NAT so we can log into ns03 remotely with ssh ns03. No need to remember its IP address. We can then copy and paste commands when needed into our home terminal.


Running a web server means that website visitors will need to access your server from the outside. They’ll open up their web browser and type in http(s)://your-fully-qualified-domain-name in order to view web pages.

sudo apt install apache2

During the installation, Debian automatically enables and starts the Systemd service. To double-check that Systemd properly started the Apache HTTP server, you could run the command:

sudo systemctl status apache2

Pressing the q key, closes the command and gives you your terminal prompt back.

If you run your server online and not just for testing purposes, make sure to properly configure the FQDN. Step-by-step instructions on how to achieve this, can be found in section “Configure the hostname and FQDN” towards the end of the article about how to configure a domain name for your Linode VPS.

Visiting the Apache test web page

During the installation, Debian automatically enabled a default web site in the Apache configuration. It serves files from directory /var/www/html. If you list the files in this directory, you’ll find the file index.html there. This file serves as a test web page to verify the successful installation and enabling of the Apache HTTP server. As a final test to see if the Apache HTTP server runs as expected, open up your browser and visit the following URL:

http://<hostname> or http://<ip-address>>



Disable directory browsing

The default Apache configuration on Debian allows directory browsing. This means that when a visitor accesses a specific directory of your website, which does not contain an index.html or index.php file, it will list all its contents:

We do not want web site visitors to be allowed to see which files a specific directory holds. For this reason we should disable the directory browsing feature. To disable directory browsing, edit the Apache configuration file with super user privileges. For example with the Nano terminal text editor:

sudo nano /etc/apache2/apache2.conf

Use the down arrow to scroll down to the Directory section for /var/www/ and delete the word Indexes from the Options (but leaving FollowSymLinks). Afterwards, it should look like this:


Then press Control plus o then Enter to save the file.

To close the file, press Control plus x.

Since we just changed the Apache configuration, restart the Apache HTTP server to activate the changes:

sudo systemctl restart apache2

Enable Apache module mod_rewrite

Apache ships with several modules to extend its default functionality. One popular module is called mod_rewrite. The mod_rewrite module enables you to rewrite URLs based on a regular expression in for example a .htaccess file. Several web applications, including Joomla, make use of this feature. Without the mod_rewrite module, permalinks in Joomla wouldn’t work. For this reason we should enable the mod_rewrite module.To enable the mod_rewrite Apache module, run the following command:

sudo a2enmod rewrite

At this point, the mod_rewrite module is enabled, but rewrite rules can only be added directly in the Apache HTTP server’s configuration file. A lot of web applications count on the fact that the Apache HTTP server can also read and process these rewrite rules from a .htaccess file. For this to work, we need to still make one more update in the Apache configuration file:

sudo nano /etc/apache2/apache2.conf

Scroll down to the Directory section for /var/www/ again and change the AllowOverride None line to AllowOverride All. Afterwards, it should look like this:


Save the file with Control plus o then Enter.

Close the file with Control plus x.

Since we just changed the Apache configuration, restart the Apache HTTP server to activate the changes:

sudo systemctl restart apache2

This completes the Apache server installation. In the next section, we will install PHP.

Install PHP

With the Apache HTTP server up and running, we can continue with the next component in the LAMP stack. Copy and paste the following command to install PHP together with commonly use add-on modules:

sudo apt install php php-pear php-mysql php-curl php-mbstring php-imagick php-zip php-gd

When Debian installs PHP this way, it also installs and enables an extra module for the Apache HTTP server (libapache2-mod-php). For this reason we need to restart the Apache HTTP server:

sudo systemctl restart apache2

To test the successful installation of PHP, we should create a temporary PHP info page. Copy and paste this command to create the file.

sudo nano /var/www/html/info.php

Copy paste these contents:




Here is what the file will look like:


Save the file with Control plus o then Enter.

Close the file with Control plus x.

Once you saved the file, open your web browser and type in the URL:

http://<hostname>/info.php or http://<ip-address>/info.php

For example,


You will see a PHP info page that looks similar to this screenshot:


Then close the browser and remove the PHP info file by copy pasting:

sudo rm /var/www/html/info.php

We are done with the PHP install. Next we will install MariaDB.

Install MariaDB

Copy paste this command:

sudo apt install mariadb-server

Then copy paste this command:

sudo mysql_secure_installation

The script will ask you several questions:

“Enter current password for root (enter for none)”. Since we haven’t configured a password, simply press Enter.

“Set root password? [Y/n]”. Debian uses the unix_socket instead of password authentication. For this reason, we do not need to set a root password, so type n then press Enter here.

This essentially means that only Debian users with sudo privileges can log into MySQL. They can conveniently do so without having to specify a password. This is secure, because they still need to enter their password to obtain their super user privileges.

“Remove anonymous users? [Y/n]”. Allowing anonymous users access to the database system poses a security risk. Therefore, type Y and press Enter here.

“Disallow root login remotely? [Y/n]”. Theoretically this one doesn’t really matter, because thanks to the unix_socket authentication method, the MySQL root user cannot login with the usual username and password combination. In any case, I recommend typing Y then pressing Enter here to further lock down the MySQL access.

“Remove test database and access to it? [Y/n]”. We have no use for the test database, so better to remove it by typing Y and pressing Enter here.

“Reload privilege tables now? [Y/n]”. The security script made a few configuration changes, so type Y and press Enter here.

This ends the questions with

Thanks for using MariaDB! and brings back the command prompt. To verify the successful installation of MariaDB we can attempt to log in to it. From the SSH terminal, all users with sudo privileges can log in as the MySQL root user by copy pasting this command:

sudo mysql -u root


To exit the database screen, type exit. Then press Enter

We have now completed the LAMP basic installation. But there are a couple of additional steps we need to complete.

MySQL database and user creation

Since this article covers the topic of how to install a LAMP stack on Debian 10, I assume your plan on installing a PHP web application like Joomla that requires access to a MySQL database. When a PHP script from a web application requires MySQL database access, it executes this script as user www-data on Debian. For security reasons, the www-data user does not have sudo access. Consequently, we need to create a new database and user for this purpose.

Here follows an example of how you could create a new database and new user that can access the database. We will assume the following, but you can change these values to whatever you want:

Database name: joomladb

Database user: joomla-user

Database password: Joomlapwd

Copy paste this command:

sudo mysql -u root

Then copy paste this command:

CREATE DATABASE joomladb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Then press Enter. Then copy paste this command:

GRANT ALL ON joomladb.* TO 'joomla-user' IDENTIFIED BY 'Joomlapwd';

Then type exit and press Enter.

How to install Joomla on a Debian 10 server


Install the unzip program

sudo apt-get install zip unzip

Determine the latest version of Joomla by opening a browser and going to the Joomla Downloads page:


Click on Joomla 3 View releases.The latest release is 3.9.26.

Create a new directory ‘joomla’ in the webroot directory by copy pasting the following.

sudo mkdir -p /var/www/html/joomla

To, go to the /tmp/ folder and download from there.

cd /tmp/

sudo wget -c https://downloads.joomla.org/cms/joomla3/3-9-26/Joomla_3-9-26-Stable-Full_Package.zip

Then install the unzip program

sudo unzip Joomla_3-9-26-Stable-Full_Package.zip -d /var/www/html/joomla

Then return to the root folder with

cd /

See if it got installed into the joomla folder:

ls /var/www/html/joomla

In order for Joomla to run smoothly, you must change the permissions of the folder where it is installed. Also, the owner of the folder must be changed.

sudo chown -R www-data:www-data /var/www/html/joomla

sudo chmod -R 755 /var/www/html/joomla

To effect the changes, restart the Apache webserver.

sudo systemctl restart apache2

Finally, we need to configure the Apache webserver to serve Joomla web pages. To accomplish this, we will create a virtual host file for Joomla.

sudo nano /etc/apache2/sites-available/joomla.conf

Copy paste the configuration below into the file after changing the server domain name to your server domain name:

<VirtualHost *:80>

ServerName ns03.example.com

ServerAdmin This email address is being protected from spambots. You need JavaScript enabled to view it.

DocumentRoot /var/www/html/joomla

<Directory /var/www/html/joomla>

Options FollowSymlinks

AllowOverride All

Require all granted


ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined


Then save the changes and close the file.

Enable the new Virtualhost.

sudo ln -s /etc/apache2/sites-available/joomla.conf /etc/apache2/sites-enabled/joomla.conf

Enable the rewrite module too.

sudo a2enmod rewrite

Then restart the Apache webserver service for the changes to come into effect.

sudo systemctl restart apache2

To finalize the installation of Joomla. Launch your browser and browse your server’s URL as shown.

http://server-IP or server hostname/joomla

For example



Click Continue to HTTP Site. Here is the full url of the Install screen:



Fill in the required details such as Site name (call it Joomla 3 Test), Email address (This email address is being protected from spambots. You need JavaScript enabled to view it.), username (david) and password.

Then, click the ‘Next’ button. Fill in the database details that you specified earlier when creating a database for Joomla. These include database name, database user and password.Leave hostname as localhost.

Database name: joomladb

Database user: joomla-user

Database password: Joomlapwd

Leave the Table prefix at the assigned random value.


Then click ‘Next’. Leave Install Sample Data set for None. The final page will give you an overview of all the settings and allow you to perform a pre-installation check. Scroll down to the ‘Pre-installation Check’ and ‘Recommended settings’ sections and ensure all the settings and installed package versions are as per the recommended guidelines.


Then click the ‘Install’ button to begin Joomla setup. Upon completion, you will get the notification below indicating that Joomla has been installed.


Scroll down the success page to the orange button.


Click Remove installation folder. Then click on the Blue Administrator button to go to the Administrator log in page. Here is the full url of the administrator log in page.



Type your username (david) and password and click on the ‘Login’ button to access Joomla’s control panel.


Click on the Joomla 3 Test Site in the upper right corner to reach the front end of your website:

Go back to the Control Panel and click Log Out (in the upper right corner). Then close the browser. Turn close the VPS SSH session with sudo poweroff. Then close VMM.

Congratulations! You have successfully installed a LAMP server on your VPS and installed Joomla onto the same VPS.