LEMP is short for Linux+Nginx  (pronounced “engine x”) +MySQL+PHP. This is a widely used wordpress webserver stack. This tutorial shows how you can install and run a WordPress blog on a Ubuntu 12.04 system that has LEMP deployed. In this example, I uses linux command to do anything I need.

If you haven’t installed LEMP on your VPS, please refer to tutorial: How To Install LEMP Server On Ubuntu

NOTE: Before you start this work, make sure you have pointed your domain to the VPS.

Create a document root for WordPress website

For example,  I create the “/wwwroot/example” folder for www.wordpresshostinggeek.com.

mkdir -p /wwwroot/example

Make the root writable and get WordPress package

Meke the root writable otherwise some plugins can not work properly. I use the following command to allow the root folder writable by user www-data and group www-data.

chown -R www-data:www-data /wwwroot/example

Then get the WP package:

cd /wwwroot/example
wget http://wordpress.org/latest.tar.gz
tar xvfz latest.tar.gz cd wordpress/
cp -R /wwwroot/example/wordpress/* /wwwroot/example
rm -rf /wwwroot/example/wordpress/

Create a database for wordpress

mysqladmin -u root -p create wordpress

In this example, the database is named “wordpress”. I use database user name “admin” and password is “DBpassword”.

mysql -u root -p
GRANT ALL PRIVILEGES ON wordpress.* TO 'admin'@'localhost' IDENTIFIED BY 'DBpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'admin'@'localhost.localdomain' IDENTIFIED BY 'DBpassword';
FLUSH PRIVILEGES;

quit;

Create an Nginx vhost configuration

vi /etc/nginx/sites-available/wordpresshotinggeek.com

Copy the following content to the configuration file. In this example, I use www.wordpresshostinggeek.com as my main domain. If you want to use www.your-domain.com as main domain, please edit the red line to “www.your-domain.com”.

server {
 listen 80;
 server_name www.wordpresshostinggeek.com wordpresshostinggeek.com;
 root /wwwroot/example;
 if ($http_host != "www.wordpresshostinggeek.com") {
 rewrite ^ http://www.wordpresshostinggeek.com$request_uri permanent;
 }
 index index.php index.html;
 location = /favicon.ico {
 log_not_found off;
 access_log off;
 }
 location = /robots.txt {
 allow all;
 log_not_found off;
 access_log off;
 }
 # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
 location ~ /\. {
 deny all;
 access_log off;
 log_not_found off;
 }
 location / {
 try_files $uri $uri/ /index.php?$args;
 }
 # Add trailing slash to */wp-admin requests.
 rewrite /wp-admin$ $scheme://$host$uri/ permanent;
 location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
 expires max;
 log_not_found off;
 }
 location ~ \.php$ {
 try_files $uri =404;
 include /etc/nginx/fastcgi_params;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 }
 }

To enable this vhost, we create a symlink to it from the /etc/nginx/sites-enabled/ directory:

cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/wordpresshotinggeek.com wordpresshotinggeek.com

In order to let these configuration take effect, restart Nginx and PHP with bellow command:

/etc/init.d/nginx restart
/etc/init.d/php-fastcgi restart

Launch the web-based WordPress installer.

First, launch your domain DNS manager and point it to your LEMP VPS public IP. Then open http://www.your-domain.com/wp-admin/install.php. Fill in the required details and submit the page.

wordpress config

Make security changes

After installed wordpress on LEMP VPS, it’s recommended to make some security policy change for your wordpress.

NOTE: Some plugins may need to modify wp-config.php. This step makes these plugins can not work properly.

chmod 755 /wwwroot/example/
chown root:root /wwwroot/example/wp-config.php

These command makes the wordpress root  folder un-writable for other users. The wp-config.php file will be only editable for root user in root group.

If you don’t want to make all this yourselves or you are not familiar with Linux command, another choice is to try out the MediaTemple. They provide 1-click software installer. You can easily deploy optimized WordPress, Drupal & ZenCart environment. It will save you much time to create your fantasy website.

Leave a Reply

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

/