VPS Notes

How To Install Wordpress

The most popular CMS as of the time of this writing is Wordpress. With this software, it is possible to create any type of website that has an easy to use interface.
It is assumed that the instructions here were followed to install a LEMP stack.

Common Configuration

For convenience, we can use a ready made configuration file that we can reuse later for NGINX + Wordpress type of sites.
$ cd /etc/nginx
$ wget -nc https://raw.github.com/vpsnotes/setup/master/nginx/wordpress.conf

If curious, the contents of the file is this:

# wordPress rules.

location = /favicon.ico { log_not_found off; access_log off; }

location = /robots.txt { allow all; log_not_found off; access_log off; }

# wordpress deny .php extension in the uploads dir location ~* /(?:uploads|files)/.*\.php$ { deny all; }

# no to source code type files location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ { return 444; }

# deny hidden files location ~ /\. { return 444; access_log off; log_not_found off; }

# deny cgi location ~* \.(pl|cgi|py|sh|lua)\$ { return 444; }

# now allowed location ~* (roundcube|webdav|smtp|http\:|soap|w00tw00t) { return 444; }

location / { try_files $uri $uri/ /index.php?$args; }

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

# Directives to send expires headers and turn off 404 error logging. location ~* ^.+\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; }

# Pass all .php files onto a php-fpm port 9000 location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; }

Create Database

Create a database schema. For example "vpsnotes". Change the "password" below with your MySQL root password.

$ echo "create schema vpsnotes;" | mysql -u root -ppassword

Wordpress Files

Create our generic web folder:
$ mkdir -p /var/www

Download the latest wordpress software and unzip it
$ cd /var/www
$ wget http://wordpress.org/latest.zip
$ unzip latest.zip
$ rm latest.zip

Rename wordpress folder to our domain, such that our site will point to /var/www/domain.tld. For example:
$ mv wordpress vpsnotes.com

Make www-data the owner of the directory, such that our webserver can have write access to it:
$ chown -R www-data: vpsnotes.com

Configure NGINX for our new Wordpress website.
$ nano /etc/nginx/sites-enabled/vpsnotes.conf

And use the following contents:

server {
    listen 80;
    server_name vpsnotes.com www.vpsnotes.com;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    root /var/www/vpsnotes.com;

index index.php index.htm index.html;

include wordpress.conf; }
The configuration is very short because all the common rules to Wordpress are in the included file we prepared earlier wordpress.conf.

Restart NGINX and PHP
$ service nginx restart
$ service php5-fpm restart

Finishing Installation

Now you can load the website on a browser to finish the installation. Here are the screenshot of the process.
za01
za02
za03
za04
za05
za06
za07
za08
za09

TLDR

Here is the shorter version using a script.
Download the script:
$ wget https://raw2.github.com/vpsnotes/setup/master/setup.sh

Install Wordpress given domain name and database name
$ bash setup.sh add_wp_website vpsnotes.com vpsnotesdb

Restart NGINX and PHP
$ service nginx restart
$ service php5-fpm restart

Tags: mysql, nginx, php, web server, wordpress