Verification: a143cc29221c9be0

Nginx php x powered by

Nginx php x powered by


  1. Fresh ubuntu server
  2. Root access or sudo privileged account
  3. A domain name pointed with server IP
  4. Internet connection to download applications

Install required packages and dependencies

Before installing the packages, update the Ubuntu system using the following command

$ sudo apt-get update -y

Once the system update is completed, configure apt to install MongoDB packages using the following command.

$ sudo apt-key adv --keyserver hkp:// --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
$ echo "deb [ arch=amd64 ] bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

Output :

Add Mongodb repository key

To configure Node.js to be able to install using apt package manager run the following command.

$ sudo apt-get -y update && sudo apt-get install -y curl && curl -sL | sudo bash -


Install Node.js

Now install the build tools Nodejs, MongoDB, and graphicsmagick :

$ sudo apt-get install -y build-essential mongodb-org nodejs graphicsmagick

Output :

Install graphicsmagick

Now install inherits and n, and the node version required by Rocketchat.

$ sudo npm install -g inherits n && sudo n 12.18.4

Install npmAdvertisement

To check the version of Nodejs installed, run the following command.

$ node --version



Install Rocketchat

We have already installed the required dependencies. Now in this step, we will download the Rocket Chat application and install it on Ubuntu 20.04.

Download the latest version of Rocketchat using the following command.

$ curl -L -o /tmp/
tar -xzf /tmp/ -C /tmp

Output :


Extract the downloaded application. You can choose your preferable directory to store the extracted file. In this example, I have extracted the file in the /tmp directory.

$ tar -xvzf /tmp/ -C /tmp

Now install Rocketchat. In this article /opt directory is used for installation. You can prefer any directory.

$ cd /tmp/bundle/programs/server && npm install


Unpack the archive and install Rocket Chat with npm package manager

$ sudo mv /tmp/bundle /opt/Rocket.Chat

Configure the Rocket.Chat service

Create a rocketchat user, set the correct permission to the Rocket.Chat application directory and create Rocket.Chat service.

$ sudo useradd -M rocketchat && sudo usermod -L rocketchat
$ sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat

To create rocketchat.service, run the following command on your terminal


Example: system file

Now we need to set up a MongoDB storage engine and replication. After this, enable and start mongoDB as:

$ sudo sed -i "s/^# engine:/ engine: mmapv1/" /etc/mongod.conf
$ sudo sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf
$ sudo systemctl enable mongod && sudo systemctl start mongod
$ mongo --eval "printjson(rs.initiate())"

Output :

setup mongo.db

Now start and enable Rocket.Chat service using the following command:

$ sudo systemctl enable rocketchat && sudo systemctl start rocketchat

Verify the Rocket.Chat service status”

$ sudo systemctl status rocketchat


systemctl status rocketchat

Nginx installation and Reverse proxy configuration

To configure nginx reverse proxy for Rocket.Chat, install nginx using the following command

$ sudo apt install nginx

Create nginx virtual host configuration for rocketchat.

$ sudo nano /etc/nginx/conf.d/rocketchat.conf

Now paste the following contents and save the file

upstream backend {

server {
listen 80;

server_name your_rocketchat_domain_name;
access_log /var/log/nginx/;
error_log /var/log/nginx/;

location / {
proxy_pass http://backend/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;

Check the nginx configuration file

$ sudo nginx -t

Configure nginx

Restart and enable nginx service

$ sudo systemctl restart nginx
$ sudo systemctl enable nginx

Now access your rocketchat domain as


You will get web setup wizard, complete it and start using Rocket.Chat

Nginx as SSL reverse proxy

We configured Rocket.Chat with only HTTP reverse proxy. To configure nginx as an SSL reverse proxy you will need certificate files. Edit the nginx vhost file and paste the following contents.

$ sudo nano /etc/nginx/conf.d/rocketchat.conf
upstream backend {

server {
listen 443 ssl;
Server_name your_rocketchat_domain_name;
client_max_body_size 200M;
access_log /var/log/nginx/;
error_log /var/log/nginx/;
ssl_certificate /etc/nginx/certificate.crt;
ssl_certificate_key /etc/nginx/private.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;

Note :

Generate or purchase ssl certificate and point the directory of your certificate file in the following configuration parameter.

ssl_certificate /etc/nginx/certificate.crt; [Your certificate file]
ssl_certificate_key /etc/nginx/private.key; [Your Private Key file]

Check the nginx configuration file

sudo nginx -t

Restart nginx service

sudo systemctl restart nginx

Accessing Rocketchat

Once the reverse proxy is configured, you can access your Rocket.Chat using the URL as:


You will get Rocket.Chat web setup wizard. Complete the setup and start using your self-hosted Rocket.Chat.


Shell access with sudo privileged account to Ubuntu 20.04 system.

Step 1 – Installing Nginx

Nginx packages are available under default repositories. SSH to your Ubuntu 20.04 LTS system with sudo privileges account and install Nginx web server from the official repository.

sudo apt update 
sudo apt install nginx

Step 2 – Installing PHP

For the PHP installation we recommend to use ppa:ondrej/php PPA, which provides latest PHP versions for Ubuntu systems. Use the below couple of commands to add the PPA to your system.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Then install PHP 7.4 the latest version available on the day of writing this tutorial. Simply execute follows commands for the installation of PHP and PHP-FPM packages.

apt update
sudo apt install php7.4 php7.4-fpm

Note:- When you are using PHP-FPM. All the PHP modules configurations are residing under /etc/php/7.4/fpm directory. You can read more about enable/disable PHP modules.

After installing above packages php7.4-fpm service will automatically be started. You can make sure by typing below command on terminal.

sudo systemctl status php7.4-fpm

● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2020-06-16 05:15:57 UTC; 1 day 10h ago
       Docs: man:php-fpm7.4(8)
   Main PID: 882699 (php-fpm7.4)
     Status: "Processes active: 0, idle: 2, Requests: 2, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 2283)
     Memory: 12.1M
     CGroup: /system.slice/php7.4-fpm.service
             ├─882699 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
             ├─882714 php-fpm: pool www
             └─882715 php-fpm: pool www

Jun 16 05:15:57 tecadmin systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
Jun 16 05:15:57 tecadmin systemd[1]: Started The PHP 7.4 FastCGI Process Manager.

Step 4 – Configuring NGINX with FPM

Next, create a Nginx server block configuration file to run PHP with FPM. Create and Edit a VirtualHost host configuration file in a text editor. You can create new VirtualHost as per your requirements, so make sure to enable any new VirtualHost.

sudo vim /etc/nginx/sites-available/

Use the below basic Nginx Virtual host configuration with php fpm settings. Update the configuration as followings.

server {

        listen 80;

        root /var/www/html;

        index index.php index.html index.htm;


        location / {

            try_files $uri $uri/ =404;


        location ~ \.php$ {

            include snippets/fastcgi-php.conf;

            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;



Save your changes to the configuration file and create a link to site enabled directory.

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/ 

Then restart Nginx service to reload the changes.

sudo systemctl restart nginx

Step 4 – Testing the Setup

Your server setup is completed now. Let’s create a PHP script with phpinfo() function and place it to your server document root. Use below command to create php script:

echo "" > /var/www/html/info.php

Then access info.php viausing server IP address (for default VirtualHost) or configured domain in Nginx VirtualHost.

how to setup nginx php fpm ubuntu 20.04

Slide down the page and see the value of $_SERVER[‘SERVER_SOFTWARE’]. This will the show the web server details.