NGINX on Ubuntu

NGINX is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and the most important, web server. NGINX uses PHP-FPM to process PHP files.

Official NGINX ppa is available for Ubuntu that installs the latest stable version of NGINX available for the specific version Ubuntu on your system is running.

If you are running Ubuntu Server (Ubuntu desktop build already comes with this package).

“`
sudo apt-get install software-properties-common
“`

Adding NGINX ppa to your system

“`
sudo apt-add repository ppa:nginx/stable
“`

Updating your local package manager database.

“`
sudo apt-get update
“`

Installing NGINX

“`
sudo apt-get install nginx-full
“`

Installing PHP-FPM (NGINX will process php files).

“`
sudo apt-get install php5-fpm
“`

Add the following lines to your nginx config `/etc/nginx/sites-enabled/default`.

```
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

    }

</div>If you prefer a much cleaner config add this instead.

<div class="highlighter-rouge">```
server {  
    server_name localhost;
    listen 80;
    root /usr/share/nginx/html;
    index index.php index.html;

    location / {
  try_files $uri $uri/ /index.html;
}

location ~ \.php$ {  
      try_files $uri =404;
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;

    }

}

Now we can start `PHP5-FPM`.

```
sudo /etc/init.d/php5-fpm start
```

Now you can create a `index.php` file in `/usr/share/nginx/html/` to test your web server configuration and add the lines below to it.

```
??>```

Now you have NGINX installed on your Ubuntu powered system. If you have any problem feel free to leave a comment below.

Published by Darryl

A visual effects artist and compositor, self learner, Linux enthusiast and Programmer and can write in Python and Rust. Contributor to open source projects.