Ubuntu 14.04 Server: Set up GNUMP server

NB! NB! NB! NB! NB! NB!
This article is undergoing a major re-write and testing. It is NOT consistent, coherent or correct!
Please do not use it yet!

Set up a GNUMP stack on Ubuntu Server 14.04: Galera, Nginx, Ubuntu, MariaDB, PHP

1. Set up nginx

Assuming web server IP is 10.42.0.75 and 3-node DB cluster is 10.42.0.62/63/64

First remove apache:

sudo apt-get purge apache2*
sudo apt-get autoremove -y

install nginx:

sudo apt-get install nginx

Start Nginx service:

sudo service nginx start

Sanity check: Navigate to http://10.42.0.75/ to see this:

Welcome to nginx! - Mozilla Firefox_005

Configure nginx

and check how many CPU's you have...

lscpu

...and chenge worker_threads to something apprpriate in nginx.conf:

sudo vi /etc/nginx/nginx.conf

Set no. worker processes (CPUs) to use:

worker_processes 1;

Restart nginx:

sudo service nginx restart

Set up virtual hosts in the sites-available directory:

sudo vi /etc/nginx/sites-available/default

Find server section and set up 3 virtual servers listening on ports 8001, 8002 and 8003 thusly:

  1. set port to listen on
  2. set the IP address for the server
  3. add index.php to the index line.

server {
      listen 80 default_server;
      listen [::]:80 default_server ipv6only=on;
      # root /usr/share/nginx/html;
      root /var/www/html;
      index index.php index.html index.htm;
      # Make site accessible from http://localhost/
      server_name localhost;
      ...
      }

 

Now, scroll down further and find the section #location ~ \.php$. Uncomment and modify the following lines as shown below.

 location ~ \.php$ {
         try_files $uri =404;   --------->
Add this line
         fastcgi_split_path_info
^(.+\.php)(/.+)$;
         #       #
NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
         #
         #       #
With php5-cgi alone:
         #      
fastcgi_pass 127.0.0.1:9000;
         #       #
With php5-fpm:
         fastcgi_pass
unix:/var/run/php5-fpm.sock;
         fastcgi_index index.php;
         include fastcgi.conf;
    }

Here, I added an extra line ‘try_files $uri =404;’ to prevent zero day exploits.

Save and exit the file.

Test nginx configuration

Test the nginx configuration for any syntax errors using command:

sudo nginx -t

Sample output:

nginx: the configuration file
/etc/nginx/nginx.conf syntax is ok
nginx:
configuration file /etc/nginx/nginx.conf test is successful

Finally restart nginx service

sudo service nginx
restart