How to install Joomla on a dedicated server with NGINX?
Tutorial for the Ubuntu 20.04 distribution.
To begin, you must connect to your server using the SSH protocol.
shh root@ip_address
After logging in, you have to make sure that our server has up-to-date software. We check this with the following command:
apt-get update
apt-get upgrade
Install Nginx server.
Joomla requires a webserver to operate. For this we will use Nginx, which is one of the most popular webservers. We install it using this command:
apt install nginx
To verify that the server has installed and is functioning correctly we enter:
systemctl status nginx
If everything is working properly we should get this result:
Installing PHP version 8.2 and the necessary patches.
Caution: We are installing php version 8.2, which is not supported by ubuntu 20.04 by default, so we need to add this package from the official php repository:
apt install software-properties-common
add-apt-repository ppa:ondrej/php
Add a repository, select option number 3 and confirm by clicking ENTER.
Now we have to install PHP and the necessary packages. We will use the command:
apt install php8.2 php8.2-common php8.2-cli php8.2-fpm php8.2-mysql php8.2-opcache php8.2-gmp php8.2-curl php8.2-intl php8.2-mbstring php8.2-xmlrpc php8.2-gd php8.2-xml php8.2-zip
To verify that the installation has performed correctly we enter:
php -v
Correct installation should give us the following result:
Then, in order to optimize Joomla's performance, some changes need to be made to the configuration file /etc/php/8.2/fpm/php.ini.
We find the following items in it and change the standard values as required. These can be the values presented below:
memory_limit = 512Mupload_max_filesize = 256Mpost_max_size = 256Mmax_execution_time = 300output_buffering = offdate.timezone = Europe/Warsaw
Save the file, and restart PHP, we can use the command for this:
systemctl restart php*
Installation of the MariaDB database.
Joomla requires a database in order to function. We will use MariaDB server for this by installing it with the following command:
apt install mariadb-server mariadb-client
Then, to complete the database installation we type:
mysql_secure_installation
Among other things, this script sets the password to the root user, disables remote logins to it or deletes anonymous users. Each time, we type "Y" for the previously mentioned tasks to take place.
Enter current password for root (enter for none):Set root password? [Y/n] YNew password:Re-enter new password:Remove anonymous users? [Y/n] YDisallow root login remotely? [Y/n] YRemove test database and access to it? [Y/n] YReload privilege tables now? [Y/n] Y
Create a database for Joomla.
When installing Joomla, a database will be required. So we should create a database as well as a user before installation. First we need to connect to the database:
mysql –u root -p
We then create the base and user with the following commands:
MariaDB [(none)]> CREATE DATABASE joomla;MariaDB [(none)]> GRANT ALL PRIVILEGES ON joomla.* TO 'joomla'@'localhost'IDENTIFIED BY ‘TwojeHaslo';MariaDB [(none)]> FLUSH PRIVILEGES;MariaDB [(none)]> EXIT;
In this way, we have a database prepared for Joomla.
Start Joomla installation.
We already have the environment prepared, so we can start installing Joomla. We download the latest available version (at the moment it is Joomla 4.3.4.) We download it using the command:
wget https://downloads.joomla.org/cms/joomla4/4-3-4/Joomla_4-3-4-Stable-Full_Package.zip?format=zip
After downloading the package, we extract the archive to the /var/www/html/joomla catalog. We use the command:
sudo unzip Joomla_4-3-4-Stable-Full_Package.zip?format=zip -d /var/www/html/joomla
At the very end, we change the user for the /var/www/html/joomla directory to the user www-data:
chown -R www-data:www-data /var/www/html/joomla/
NGINX configuration for Joomla.
One of the last steps is to create a virtual host file for the Joomla installation. We need to create the following file:
nano /etc/nginx/sites-available/joomla.conf
Add the following lines:
server {listen 80 default_server;listen [::]:80 default_server;root /var/www/html/joomla;index index.php index.html index.htm;server_name TWOJADOMENA.pl WWW.TWOJADOMENA.pl;location / {try_files $uri $uri/ =404;}location ~ \.php$ {include snippets/fastcgi-php.conf;fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;}}
You can test this file with the command to be sure the syntax is correct:
nginx -t
If the configuration is correct you should see a notification like this:
To activate our site, we create a symbolic link to the file we created earlier using the command:
ln -s /etc/nginx/sites-available/joomla.conf /etc/nginx/sites-enabled/
Finally, let's reset the Nginx server so that the saved changes will update:
systemctl restart nginx
We can now proceed to configure our Joomla. Type your domain name in the format "http://yourdomain.com" into your browser and begin the configuration process. We choose the language and the name of our site.
We then create the login details for the administrator account.
We now complete the database configuration as we created in the previous steps.
Once all the details have been entered, we can confirm the Joomla installation. After installation, it remains for us to click on the Open Site button to see our main homepage.
Congratulations! The installation of Joomla is now complete and you can use and modify it according to your needs.