How to Install Joomla with Nginx on Ubuntu 18.04

In this post, we will show you how to install Joomla on an Ubuntu 18.04 VPS with MySQL, PHP-FPM 7.2, and Nginx.

Joomla is a free and open-source content management system (CMS) for publishing web content written in PHP. Joomla is one of the most popular CMSs and it is used all over the world to power millions of websites of all shapes and sizes. Joomla can be used for small business and corporate websites, e-commerce stores, online magazines, personal blogs and portfolios and much more.

This guide should work on other Linux VPS systems as well, but it was tested and written for an Ubuntu 18.04 VPS.

Prerequisites:

  • Ubuntu 18.04 VPS
  • Administrative sudo user with root privileges, or access to the root user itself

Before you start:

Run the following command to update the packages list and upgrade the system packages:

sudo apt update && sudo apt upgrade

Install the necessary packages:

sudo apt install unzip

Step 1: Install MySQL and Create a Database

If you already have MySQL or MariaDB installed, you can skip this step and move onto the next one.

The following command will install the latest MySQL 5.7 server from the official Ubuntu repositories:

sudo apt-get install mysql-server

Once the installation is complete, issue the following command to secure your installation:

mysql_secure_installation

You will be prompted to answer several questions. These are the values we would use, but you are free to answer them based on your preferences:

  • Setup VALIDATE PASSWORD plugin? (Press y|Y for Yes, any other key for No) N
  • Change root password? (Press y|Y for Yes, any other key for No) N
  • Remove anonymous users? (Press y|Y for Yes, any other key for No) Y
  • Disallow root login remotely? (Press y|Y for Yes, any other key for No) Y
  • Remove test database and access to it? (Press y|Y for Yes, any other key for No) Y
  • Reload privilege tables now? (Press y|Y for Yes, any other key for No) Y

Next, we need to create a MySQL database and user for the new Joomla installation.

Log in to the MySQL console:

sudo mysql

Run the following commands to create a new database and user and to grant privileges to the user:

mysql> CREATE DATABASE joomla;

mysql> GRANT ALL PRIVILEGES ON joomla.* TO 'joomla'@'localhost' IDENTIFIED BY 'my_strong_password';
mysql> FLUSH PRIVILEGES;
mysql> \q

Make sure to replace “my_strong_password” with an actual strong password.

Step 2: Install PHP 7.2 and Required PHP Modules

The newer Joomla versions are fully compatible with the default PHP version 7.2 that comes with Ubuntu 18.04.

Install PHP 7.2 and all necessary PHP modules using the following command:

sudo apt install php7.2-fpm php7.2-cli php7.2-gd php7.2-opcache php7.2-mysql php7.2-json php7.2-mcrypt php7.2-xml php7.2-curl

Set the recommended PHP settings for Joomla:

sudo sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 128M/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/post_max_size = .*/post_max_size = 128M/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/max_execution_time = .*/max_execution_time = 3000/" /etc/php/7.2/fpm/php.ini

Step 3: Install Joomla

Installing Joomla is pretty easy and straightforward. First, download the Joomla zip archive from the Joomla download page:

wget https://downloads.joomla.org/cms/joomla3/3-9-1/joomla_3-9-1-stable-full_package-zip?format=zip -O joomla.zip

Once the download is completed, unzip the archive and move the extracted files to the /var/www/myjoomlasite.com directory, which will be the root directory of your new Joomla site:

sudo mkdir -p /var/www/myjoomlasite.com
sudo unzip joomla.zip -d /var/www/myjoomlasite.com

Make sure to replace “myjoomlasite.com” with the name of your unique registered domain name.

Finally change the ownership of the /var/www/myjoomlasite.com directory to the www-data user so that PHP and Nginx can read, write to, and edit files:

sudo chown -R www-data: /var/www/myjoomlasite.com

Step 4: Install and Configure Nginx

If you don’t have Nginx installed on your server, you can install the latest stable version from the official Ubuntu repositories:

sudo apt install nginx

Next, create a new Nginx server block:

sudo nano /etc/nginx/sites-available/myjoomlasite.com
server {
    listen 80;
    server_name myjoomlasite.com www.myjoomlasite.com;
    root /var/www/myjoomlasite.com;

    index index.html index.htm index.php;

    charset utf-8;

    access_log /var/log/nginx/myjoomlasite.com.access.log;
    error_log /var/log/nginx/myjoomlasite.com.error.log info;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~* /(images|cache|media|logs|tmp)/.*.(php|pl|py|jsp|asp|sh|cgi)$ {
        return 403;
        error_page 403 /403_error.html;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ .php$ {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi.conf;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Activate the server block by creating a symbolic link:

sudo ln -s /etc/nginx/sites-available/myjoomlasite.com /etc/nginx/sites-enabled/myjoomlasite.com

Once again, pay attention to replacing the example domain name with your unique one.

Test the Nginx configuration and restart the nginx service:

sudo nginx -t
sudo systemctl restart nginx

Open http://myjoomlasite.com/ in your favorite web browser and follow the on-screen instructions to complete the Joomla installation.

That’s it. You have successfully installed Joomla on Ubuntu 18.04! For more information about how to manage your Joomla installation, please refer to the official Joomla documentation.


Of course, you don’t have to install Joomla on Ubuntu 18.04 if you use one of our managed VPS hosting services or one of our Managed Joomla Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to install Joomla on Ubuntu 18.04, or if you found it helpful, please share it with your friends on the social networks using the sharing buttons, or simply leave a reply below. Thanks.

Leave a Comment

To prove you are human please solve the following *