Setup VPS / Server from beginning for WordPress sites with NGINX + MySQL Ubuntu


I will guide you about how to setup brand new VPS / Server to host WordPress with optimize configuration. I prefer use NGINX + MySQL here. Remember, I start from zero configuration with mean no software installed , no pre-installed program and default Ubuntu. If you want to install several VPS / Server, then you can try “terminator” console and set broadcast.

Installing Terminator :

1
sudo apt-get install terminator

Then, Let start to build Ubuntu servers :

1. Configure our DNS and Domain pointing

1
2
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install bind9

Make sure in your Domain registrar, you already pointed your domain into this servers. Here is mine for instance:

1
2
ns1.wpscale.com -> My brand new server IP
ns2.wpscale.com -> My brand new server IP

Go to bind folder and edit named.conf.local :

1
2
cd /etc/bind
sudo vim named.conf.local

We will append our domain in bind by inserting :

1
2
3
4
zone "wpscale.com" {
        type master;
        file "/etc/bind/db.wpscale.com";
};

Now, we create DB files which is pointed in named.conf.local (/etc/bind/db.wpscale.com) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
;
; BIND data file for local loopback interface
;
$TTL    3600
@       IN      SOA     wpscale.com. admin.wpscale.com. (
                              29        ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns1.wpscale.com.
@       IN      A       199.83.129.2
ns1     IN      A       199.83.129.2 ; My Server / Hosting IP
ns2     IN      A       199.83.129.2
www     IN      A       199.83.129.2

2. Install base packages

1
sudo apt-get install subversion git build-essential curl openssl libssl-dev pkg-config unzip zip ia32-libs imagemagick nmap libimage-exiftool-perl

Note : ia32-libs is need for 64-bit only.

3. Install NGINX + PHP5-FPM + MySQL

1
2
3
sudo apt-get install nginx php5-fpm php5-mysql
sudo apt-get install mysql-server php5-mysql phpmyadmin
sudo apt-get install apache2-threaded-dev php5-dev php-pear php5

Run PHP5-FPM as socket
Running PHP5-FPM as socket is better than running on default (port 9000). So, edit “/etc/php5/fpm/pool.d/www.conf” :

1
2
;listen = 127.0.0.1:9000
listen = /var/run/php5-fpm.sock

Configuring NGINX Virtualhost for WordPress

1
2
3
cd /etc/nginx
sudo rm -rf sites-enabled
sudo ln -s /etc/nginx/sites-available /etc/nginx/sites-enabled

For example, I create wpscale.com NGINX conf :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
server {
         server_name wpscale.com;
         rewrite ^ http://www.wpscale.com$request_uri? permanent;
}

server {
        listen   80;
        server_name www.wpscale.com;
        root    /var/www/wpscale.com;

        client_max_body_size 10m;
        access_log  /var/log/nginx/access.log;
        index  index.php index.html index.htm;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }
 
        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }
 
        location / {
                # This is cool because no php is touched for static content
                try_files $uri $uri/ /index.php?$args;
        }


        # Add trailing slash to */wp-admin requests.
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ .php$ {
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

        location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }

        # deny access to .htaccess files, if Apache’s document root
        # concurs with nginx’s one
        #
        location ~ /.ht {
                deny  all;
        }
}

4. PhantomJS
This is a must software for me 🙂

1
2
sudo apt-get install xvfb git build-essential gtk2-engines-pixbuf xfonts-100dpi x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
sudo apt-get install libqt4-dev libqtwebkit-dev qt4-qmake python-qt4

Now we are ready install PhantomJS

1
2
3
4
cd ~/
git clone git://github.com/ariya/phantomjs.git && cd phantomjs
qmake-qt4 && make
sudo cp bin/phantomjs /usr/local/bin/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.