Installing the webserver

If you’re running a standard webhosting business or have a lot of users that want random things, you might be better off getting Apache installed. However, if you all you want is a super fast, efficient webserver to server html or php pages I typically go with either Lighttpd or Nginx over Apache. Which one is better is debatable. I like Lighttpd over Nginx for the ease of use and the fact that CGI still works, but it’s no where near as fast as Nginx right now.

Since the current server I’m building just needs to serve PHP pages and nothing fancy with a possibility over 10k+ concurrent connections, I’m just going to install Nginx and document that.

Installing Nginx like a lot of things in Debain/Ubuntu is really simple. Just run:

apt-get install nginx
service nginx start
service nginx status

If it shows that it’s running you’re in the clear!

Time to configure the web server

Edit /etc/nginx/sites-available/default

Edit the following line to where ever the file path is to your web root

root /usr/share/nginx/www

Change the following line

Index index.html index.htm;


Index index.php index.html index.htm

Change server_name localhost to


Further down uncomment the lines

#location ~ \.php$ {

Make it so you it kinda resembles this

location ~ \.php$ {
         try_files $uri =404;
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         #       # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
         #       # With php5-cgi alone:
        #       fastcgi_pass;
         #       # With php5-fpm:
         fastcgi_pass unix:/var/run/php5-fpm.sock;
         fastcgi_index index.php;
         include fastcgi_params;

Note: try_files $uri =404; is a new line that should be added

To setup an alias so you can access something like phpmyadmin from all domains where you only need it installed once. Add the following

Location /phpmyadmin {
      alias /srv/www/phpmyadmin;
      index index.php index.htm index.html;
      location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$;
           fastcgi_pass unix:var/run/php5-fpm.sock;
           fastcgi_index index.php;
           include fastcgi_params;

Yes you have to add a sub location block inside your location block for your alias. Nginx is weird this way.

Test your config using nginx –t

Before we restart the server we might as well set the workers available to the system

Edit /etc/nginx/nginx.conf

Look for the line worker_processes and set it to the number of CPU cores you have available to you. IF you don’t know you can also use

or if you know you have say an i7 quad core with hyper threading enabled giving you 8 logical cores, you can use

worker_processes 8;

If you’re using a VPS with only 1 dedicated core just use:

worker_processes 1;

If you don’t know how many cpus you have use worker_processes auto; or just run lscpu to see how many cpus you have.

If you don’t get any errors run

Service nginx restart

<– Back to Step 4  |  Onwards to Step 6 –>