Run Joomla with Nginx on a Centos VPS

run-joomla-on-nginx-on-centos-vpsToday we will show you how to install Joomla, one of the most popular open source Content Management Systems on your LNMP stack (Nginx, MySQL and PHP-FPM) Centos VPS.
Follow this article carefully and in no more than 10 minutes you will have a common Joomla CMS installed on your LNMP stack Centos VPS, and in the next article we will optimize the very same installation performance-wise, as an addition to several security tips that will provide safer hosting for you and your business.

Let’s get to work.

Before we start, let’s make sure the Apache webserver is stopped and autostart on boot is disabled:

# /etc/init.d/httpd stop
# chkconfig httpd off

In order to install Nginx, we need to add the epel repository. Find the correct architecture of your VPS by executing:

# uname -m

  • for a 32bit VPS:

# rpm -Uvh

  • for a 64bit VPS:

# rpm -Uvh

Next, make sure the system is up-to-date:

# yum update

Then Install the Nginx webserver:

# yum install nginx -y

Edit the /etc/nginx/nginx.conf file and replace the following lines:

# vim /etc/nginx/nginx.conf

# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;


# enabled sites
include /etc/nginx/sites-enabled/*;

Execute the following command to create the sites-enabled and sites-available directories:

# mkdir -p /etc/nginx/sites-{enabled,available}

Now, let’s set-up the default Nginx virtual host directive. Create the file and make it look like the one below:

# vim /etc/nginx/sites-available/default.conf

server {
listen 80 default_server;
server_name _;
location / {
root /usr/share/nginx/html;
index index.html index.htm; }
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html; }
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html; }

Now enable the default virtual host directive:

# cd /etc/nginx/sites-enabled

# ln -s /etc/nginx/sites-available/default.conf

Test your webserver configuration for typos and errors:

# nginx -t

If everything is ok, start Nginx and add it to the system startup.

# /etc/init.d/nginx start

# chkconfig nginx on

If you point your browser to your IP address/domain name you should see the Nginx default page. So far so good.

Let’s go on by installing MySQL:

# yum -y install mysql mysql-server

Start it and add it to system startup:

# service mysqld restart
# chkconfig mysqld on

Type the following for the initial mysql configuration:

# mysql_secure_installation

and follow the on-screen instructions to set the root password, remove the anonymous users, disallow remote root login and remove the test database.

Edit /etc/my.cnf and make sure the following line is in place:

# vim /etc/my.cnf

bind-address =

And restart mysql:

# /etc/init.d/mysqld restart

That’s it as far as the mysql installation and configuration is concerned. Next, we move on to installing php-fpm and a couple of it’s extensions.

# yum install php php-fpm php-gd php-mcrypt php-mysql -y

Make sure to set the following two lines inside the /etc/php.ini file. Match the timezone with your own:

# vim /etc/php.ini

date.timezone = America/New_York

Also, make sure these lines in /etc/php-fpm.conf are as follows:

# vim /etc/php-fpm.conf

emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 10

Crete php-fpm pool:

# mv -v /etc/php-fpm.d/www.conf{,.orig}

# vim /etc/php-fpm.d/www.conf

listen = /var/run/php-jml.socket
user = nginx
group = nginx
request_slowlog_timeout = 5s
slowlog = /var/log/php-fpm/jml.log
listen.allowed_clients =
pm = dynamic
pm.max_children = 8
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 400
listen.backlog = -1
pm.status_path = /status
request_terminate_timeout = 120s
rlimit_files = 131072
rlimit_core = unlimited
catch_workers_output = yes
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_admin_value[error_log] = /var/log/php-fpm/jml-error.log
php_admin_flag[log_errors] = on

Now restart php-fpm and add it to system startup:

# /etc/init.d/php-fpm restart

# chkconfig php-fpm on

and then create the vhost directive for your Joomla installation:

# vim /etc/nginx/sites-available/mydomain.tld.conf

server {
listen 80;
server_name mydomain.tld;
rewrite ^(.*) http://www.mydomain.tld$1 permanent; }

server {
listen 80;
server_name www.mydomain.tld;

client_max_body_size 5m;
client_body_timeout 60;

access_log /var/log/nginx/mydomain.tld-access;
error_log /var/log/nginx/mydomain.tld-error error;

root /usr/share/nginx/html/mydomain.tld;
index index.html index.php;

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

error_page 403 =404;
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ ~$ { access_log off; log_not_found off; deny all; }

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

location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; }
location ~* \.(woff|svg)$ { access_log off; log_not_found off; expires 30d; }
location ~* \.(js)$ { access_log off; log_not_found off; expires 7d; }

location ~ \.php?$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php-jml.socket;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(.*)$; }

After it is created, we need to enable the vhost directive, create the document root directory and restart Nginx:

# cd /etc/nginx/sites-enabled
# ln -s /etc/nginx/sites-available/mydomain.tld.conf
# mkdir /usr/share/nginx/html/mydomain.tld
# nginx -t
# /etc/init.d/nginx restart

Create index.php file inside your root directory and access it in a browser to test the installation:

# echo -e “<?php\n\tphpinfo();\n” > /usr/share/nginx/html/mydomain.tld/info.php

After the server setup we finally get to install Joomla. We can start with the database. Let’s create one:

# mysql -uroot -p
mysql> create database joomlaDB;
mysql> grant all on joomlaDB.* to user@localhost identified by “sEcReT_pASsWoRd”;
mysql> \q

Download the latest Joomla installation inside your document root directory, unzip it:

# cd /usr/share/nginx/html/mydomain.tld
# wget -O
# unzip
# rm

Set the correct owner of the files in the document root directory:

# chown -R nginx:nginx /usr/share/nginx/html/mydomain.tld

Point your browser to http://mydomain.tld/installation or http://<your IP address>/installation to finish the installation. Select your language and fill the text fields with the required information in the first step and click ‘Next’.

On the second screen, enter the correct database information:

db type: mysqli
hostname: localhost
user: user
pass: sEcReT_pASsWoRd
db: joomlaDB

Click ‘Next’. Choose pre-installed sample data of your liking and click ‘Install’. After you get the ‘Congratulations! Joomla! is now installed.’ notification, click the ‘Remove installation folder’ button and click ‘Site’ to visit your website or ‘Administrator’ to go to the administrator login form.

That’s it! You have just installed the latest Joomla version on your Centos VPS.

Of course, if you are one of our Linux VPS Hosting customers, you don’t have to do any of this, simply ask our admins, sit back and relax. Our admins will set this up for you immediately. You can also try reading our post on How to Install Joomla 3 on CentOS 7.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

8 thoughts on “Run Joomla with Nginx on a Centos VPS”

  1. Hey.

    The previous commenter sort of disappeared. I tried to go through this on CentOS 6.5 x64 and I cant get php to work.

    it all restarts fine, the nginx part works fine initially. but when I do the reverse proxy all I see on my test page is…an nginx error The page you are looking for is not found.

    Something has triggered missing webpage on your website. This is the default 404 error page for nginx that is distributed with EPEL. It is located

  2. Hi.

    I don’t understand on thing:
    in /etc/nginx/sites-available/mydomain.tld.conf file you added line – root /var/www/html/mydomain.tld/; , but info.php created in /usr/share/nginx/html/mydomain.tld/ folder. Why is that? Maybe root folder in /etc/nginx/sites-available/mydomain.tld.conf config should be /usr/share/nginx/html/mydomain.tld/ ?


Leave a Comment

To prove you are human please solve the following *