• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Nginx WordPress Installation Guide (All Steps)

By Abhishek Ghosh December 17, 2015 10:38 am Updated on January 12, 2016

Nginx WordPress Installation Guide (All Steps)

Advertisement

We have lot of host specific guide published so far. This is a Full Nginx WordPress Installation Guide With All Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG’s Example Settings For Nginx. Commands are valid for Ubuntu, Debian and other deb GNU/Linux. It is Even Good For a Sysadmin or a New SSH User. Nginx-PHP5-FPM needs tweak, we supplied some tricks & a GitHub Repo, but one must look at WordPress DOT ORG’s codex.wordpress.org guides and settings as written in the text. This guide is not really WordPress 2-Minute Noddles like install. You’ll find such cheap quality guides on mid-range to low end web hosts’ official websites. They will need 2-Minute to hack and result to a slower WordPress. This guide includes all the basic steps with all possible optimization we perform, troubleshooting etc. compatible with WordPress DOT ORG’s codex.wordpress.org guides and settings. Another compatibility is with W3 Total Cache’s official guide. This guide excludes the security part, we believe, cloud server instances are better secured by a virtual router like used on HP Cloud. We used Ubuntu 14.04 LTS for This Nginx WordPress Installation Guide. Here is Table of Contents for Nginx WordPress Installation Guide. Basic concept is to – (1) Install MySQL (2) Install PHP (3) Install webserver software Nginx. They get complicated for cache and optimization. WordPress will run top of it. Obviously, a minimum security related to WordPress, sending emails are important. The concept can be diagrammatically represented :

Nginx-WordPress-Installation-Guide-Steps
Table of Contents

  1. Introduction
  2. Concepts Behind Installing WordPress
  3. Install Percona MySQL
    • 3.1 Basic MySQL Management
    • 3.2 Backup and Restore MySQL
    • 3.3 Prevent Error Establishing a Database Connection
  4. Install Nginx (nginx-extras)
  5. Install PHP5-FPM & Other PHP Stuffs
    • 5.1 Configuring Memcached
    • 5.2 Configuring Zend OpCache
    • 5.3 Configuring XCache
    • 5.4 Debug PHP
    • 5.4 Admin & Statistics Pages For Memcached, XCache, Zend OpCache
  6. Install WordPress
  7. Install WordPress Plugins – W3 Total Cache
  8. Conclusion & Further Optimization

 

Nginx WordPress Installation Guide : Foreword

 

We are using HP Enterprise Cloud’s nodes. Sometimes we use Rackspace’s Cloud Server or Bare Metal. XCache possible gives pathetic result on cheaper hardware. If you use $7 / month 6GB VPSDime or a cheaper dedicated server, method of caching will be different. If you do not find any part on our website, you should read guides by Rackspace or Major Hayden. Basically W3 Total Cache plugin serves Static HTML pages. W3 Total Cache is enough to handle all the caches. If you cache those Static HTML pages with Nginx Microcache, then you’ll need their WordPress Plugin. Do not copy-paste from here and there without understanding. If you follow our plus WordPress DOT ORG’s codex.wordpress.org guides and settings; you will not face any trouble. Nginx Microcache is not shown to enable in this guide.

Advertisement

---

We are starting after you have SSH-ed on the server and is using the server as root user. We are taking it granted that :

  1. You have a basic idea of how to SSH. If you are even newer user, read our older guides on Rackspace Cloud Server series to get used.
  2. Nginx is not exactly for the newbies. It is better to have an idea of using typical LAMP servers.
  3. We are installing Nginx Web server software, Percona MySQL database server, Memcache on same server. MySQL database server can be installed on different server. We recommand to use ONE server for all if you are a new user.
  4. We are assuming that the user is using an instance with 4 GB RAM or more.

We have some kind of configured settings files on Github. They are deliberately not 100% closer to our real settings, but very closer. Basically we have optimized settings files. We simply run the commands and copy-paste them. When you’ll reach your optimized settings by tuning, keep the files on some free cloud storage like Dropbox or at minimum on your computer. Often, we may need to change host or server.

 

Nginx WordPress Installation Guide : First Install Percona MySQL

 

We prefer to install database software first. Percona MySQL is preferred as Percona has free tuning service. Only settings files is my.cnf. You can optimize it later using Percona’s service and Major Hayden’s MySQL Tuner. We prefer InnoDB engine.

First update & upgrade the server :

Vim
1
2
apt update –y && apt upgrade
apt dist–upgrade

First, we will add Percona’s repo :

Vim
1
2
3
4
apt–key adv —keyserver keys.gnupg.net —recv–keys 1C4CBDCDCD2EFD2A
echo “deb http://repo.percona.com/apt lsb_release -cs main” >> /etc/apt/sources.list.d/percona.list
echo “deb-src http://repo.percona.com/apt lsb_release -cs main” >> /etc/apt/sources.list.d/percona.list
apt–get update

Then install Percona MySQL server :

Vim
1
sudo apt–get install percona–server–server–5.6 percona–server–client–5.6

Add a tough password . Then, we will run these two commands one by one :

Vim
1
2
sudo mysql_install_db
sudo mysql_secure_installation

Running sudo mysql_install_db consumes a time, it creates all the needed directories and settings files. sudo mysql_secure_installation needed to ensure security. Now login to MySQL server and run the commands specific for Percona (you’ll see they are instructed to run) :

Vim
1
2
3
4
5
6
7
8
9
mysql –u root –h localhost –p
# run after login
CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME ‘libfnv1a_udf.so’;
CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME ‘libfnv_udf.so’;
CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME ‘libmurmur_udf.so’;
# you should exit
exit
# then restart mysql
service mysql restart

Now, again login and create database, add password etc. yourserver2015, wordpress2015, BADPASSWORD__a&ET# are my own custom phrases, you should change to yours difficult to guess combinations :

Vim
1
2
3
mysql –u root –h localhost –p
CREATE USER ‘yourserver2015’@‘localhost’ IDENTIFIED BY ‘BADPASSWORD__a&ET#’;
CREATE DATABASE wordpress2015;

MySQl server’s root with password while installing MySQL ALWAYS can access the database. We add user with a password to separate the chance of attack, we sometimes never create a user if one MySQL has one database on different server. This step is for higher security, MySQl server’s root with password would work to install WordPress. The extra steps :

Vim
1
2
3
GRANT SELECT,DELETE,INSERT,UPDATE ON wordpress2015.* TO ‘yourserver2015’@‘localhost’;
GRANT ALL PRIVILEGES ON wordpress2015.* TO ‘yourserver2015’@‘localhost’;
FLUSH PRIVILEGES;

 

Basic MySQL Management (You Can Read Later)

 

View the database :

Vim
1
show databases;

In case you are migrating from a different installation, you have a MySQL database backup, suppose backup.sql. First cd to the location where backup.sql is located, login to MySQL server. This is how, you’ll restore from backup :

Vim
1
2
3
show databases;
use wordpress2015;
\. backup.sql

MySQL need no PHPMyAdmin to manage. PHPMyAdmin is good for 100% new users. PHPMyAdmin will eat RAM and increase security risks. This is how you’ll take backup :

Vim
1
mysqldump –h localhost –u root –p wordpress2015 > backup11072015.sql

After completion of this step, you can run a cat command on /etc/mysql/my.cnf :

Vim
1
cat /etc/mysql/my.cnf

We were talking about optimizing this file. You can optimize it later like using some basic tweaked and ready to my.cnf from our GitHub repo. That /etc/mysql/my.cnfcreated after running the sudo mysql_install_dbcommand. Percona has no my.cnf by default. Percona MySQL is for the advanced users.

Most important to read how to “enable” Auto Restart of MySQL. At minimum make /etc/mysql/my.cnf‘s [mysqld_safe] looking like this :

Vim
1
2
3
4
5
6
[mysqld_safe]
pid–file        = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
nice = 0
log_error=/var/log/mysqld.log
datadir=/var/lib/mysql

restart MySQL :

Vim
1
service mysql restart

Otherwise MySQL will not Auto-Restart on failure and throw infamous Error Establishing a Database Connection message. MySQL haults on error, it possibly fails to find var/run/mysqld/mysqld.pid, that is why does not start. Also, the number of maximum allowed connection is very less by default (35 or like that). Change it 10 times more! What for that default my.cnf packaged for 32 MB RAM in 2015-16, it is not clear. MySQL is great software except the my.cnf file. There is no free software which has so less optimized settings file. In case you are optimizing, always take a backup :

Vim
1
cp /etc/mysql/my.cnf ~/my.txt

then empty the file :

Vim
1
echo ” “ > /etc/mysql/my.cnf

wget a close to optimized file and echo or cat it to the original (which we emptied on previous step) file :

Vim
1
2
3
cd ~ && wget https://raw.githubusercontent.com/AbhishekGhosh/Nginx–PHP5–FPM/master/percona–mysql–server/fail–safe–my.cnf
ls
cat fail–safe–my.cnf > /etc/mysql/my.cnf

Now reload MySQL :

Vim
1
service mysql restart

If fails to restart, then quit with control + c (for Mac) and check the error file :

Vim
1
cat /var/log/mysql/error.log
We have finished installing MySQL database part. You can scroll to proceed to next section or go to the top to Table of Content.

 

 

Nginx WordPress Installation Guide : Install Nginx

 

First add nginx to www-data group :

Vim
1
sudo usermod –aG www–data nginx

We use nginx-extras, nginx-extras is almost like Nginx Plus. One command :

Vim
1
apt–get install nginx–extras

Open the default virtual host file :

Vim
1
nano /etc/nginx/sites–available/default

Minimum, modify few lines on that file :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
...
access_log  /var/log/nginx/log/access.log  main;
...
index index.php index.html index.htm;
...
        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }
...
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5–fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
...

Open the settings file :

Vim
1
nano /etc/nginx/nginx.conf

Minimum, modify this line on that file :

Vim
1
error_log  /var/log/nginx/error.log warn;

Run nginx -t to check whether everything is fine. Then restart Nginx :

Vim
1
service nginx restart

Recursively chown the public directory :

Vim
1
sudo chown www–data:nginx /usr/share/nginx/html –R

We have configuration flies kept here on GitHub, you can use them later. However, it uses TCP/IP, you should modify fastcgi_pass 127.0.0.1:9000; to fastcgi_pass unix:/var/run/php5-fpm.sock;, if you use that file. We like UNIX Socket over TCP/IP.

Nginx Plus is the paid, optimized version of Nginx community edition. It is very light and Nginx directly optimize by login in to the service. If you need Nginx Plus, you can contact us. Directly Russian team of Nginx contact you via email. Installation and configuration of Nginx Plus is different.

WordPress dot ORG has excellent configuration examples :

Vim
1
https://codex.wordpress.org/Nginx
We have finished installing MySQL database and Nginx web server. You can scroll to proceed to next section or go to the top to Table of Content.

 

 

Nginx WordPress Installation Guide : PHP5-FPM

 

Big one line command :

Vim
1
apt–get install php5–common php5–mysqlnd php5–xmlrpc php5–curl php5–gd php5–cli php5–fpm php–pear php5–dev php5–imap php5–mcrypt snmp php5–intl php5–imagick php5–ming php5–ps php5–pspell php5–recode php5–snmp php5–sqlite php5–tidy php5–xsl php5–xcache php5–gd libssh2–php libssh2–php memcached php5–memcache

We installed XCache, Memcached and the PHP5-Memcache which is compatible with WordPress W3 Total Cache plugin. WordPress W3 Total Cache plugin’s developer is a great person. Our older guide’s link is listed on official readme text of the Plugin. You are installing in the way, WordPress W3 Total Cache plugin will work without hitch.

Run :

Vim
1
sudo updatedb

Else, we can not use locate command to find the files.

 

Optimizing PHP5-FPM, Zend OpCache, MemCached, XCache

 

For Memcached, you need to tweak two files :

Vim
1
nano /etc/memcached.conf

Modify the memory to -m 1024. By default, its to less.

Next, open this file :

Vim
1
nano /etc/php5/mods–available/memcache.ini

Add these two lines at bottom :

Vim
1
2
session.save_handler = memcache
session.save_path = “tcp://localhost:11211”

Restart the services :

Vim
1
2
service memcached restart
service php5–fpm restart

Now, Zend OpCache. This is needed for making slow PHP faster. Open this file :

Vim
1
nano /etc/php5/fpm/conf.d/05–opcache.ini

Open to add/edit these lines :

Vim
1
2
3
4
opcache.memory_consumption=512
opcache.max_accelerated_files=50000
opcache.revalidate_freq=0
opcache.consistency_checks=1

Restart the service :

Vim
1
service php5–fpm restart

Remaining is XCache. If we run :

Vim
1
locate xcache.ini

Initially edit the first result before installing WordPress – file name is usually 20-xcache.ini. We have ready to use configuration file on GitHub. Username and Password not set.

XCache is discussed separately and must be read. XCache need another work – setup of XCache Admin page. XCache is very powerful caching system. Memcached is not alternative to XCache and vice-versa.

nbsp;

Test and Debug PHP5-FPM

 

PHP5-FPM is infamous for throwing errors. First check whether plain PHP page is loading on frontend or not :

Vim
1
2
3
cd /usr/share/nginx/html
rm index.html
nano index.php

Paste as content of index.php. Now, go to you IP address (or domain name) via browser. You should see an informative page about PHP. If you see white page with or without any text, you are getting error. Try to fix PHP5-FPM in this way first.

Test PHP by running :

Vim
1
php5–fpm –t

If it returns wrong with word related to xcache – problem is settings with XCache. If you feel XCache too complicated to work, uninstall it (you can always install it later) :

Vim
1
sudo apt–get purge —auto–remove php5–xcache

Reload the services :

Vim
1
service php5–fpm restart

If PHP5-FPM throws error like unknown service, problem is with ANY PHP related settings you changed. Revert back to default. Then, reboot the server by running reboot command. If you run :

Vim
1
service php5–fpm restart

after correction, it will reload fine. Basically this is safer while changing/tweaking any PHP related settings file :

Vim
1
2
3
nginx –t
service php5–fpm restart
service php5–fpm restart

Running service php5-fpm restart twice excludes the probability of loading a wrong PHP settings. Another thing you need to change – Expiry header from 19 Nov 1981. Run locate php.ini, you’ll see first two php.ini files. Change only those two.

 

Admin Pages, Statistics Pages For Memcached, XCache, Zend OpCache

 

Go to public directory :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
cd /usr/share/nginx/html
rm index.html index.php
mkdir mystat && cd mystat
mkdir opcache memcache
cd opcache
wget https://raw.github.com/rlerdorf/opcache–status/master/opcache.php
cd .. && cd memcache
wget http://phpmemcacheadmin.googlecode.com/files/phpMemcachedAdmin–1.2.2–r262.tar.gz
tar –xzvf p*
rm phpMemcachedAdmin–1.2.2–r262.tar.gz
chmod +r *
chmod 0777 Config/Memcache.php

If you visit :

Vim
1
2
http://yo.ur.IP.add.ress/mystat/opcache/opcache.php
http://yo.ur.IP.add.ress/mystat/memcache/index.php

You will see the stats plus proof that PHP is working fine. But, keeping the mystat directory is dangerous! Always move inside server :

Vim
1
2
cd /usr/share/nginx/html/mystat
mv * ~/mystat

When you’ll want to see, do the reverse :

Vim
1
2
cd ~/mystat
mv * /usr/share/nginx/html/mystat

They are so dangerous, that it is not even safe to add only password to protect. When we restart Nginx, a hacker can intrude & run an exploit. They are for dev purpose. It is safe to keep “outside of public sight”. Setup of XCache Admin page is discussed before. XCache Admin is robust about security. It is not unsafe to keep it on public directory.

We have finished installing MySQL database, Nginx web server and PHP. You can scroll to proceed to next section or go to the top to Table of Content.

 

 

Download and Install WordPress

 

Most easy step. We suggest to add the IP to your favorite DNS Service, like CloudFlare or DynDNS. If your domain name is abhishekghosh.net and IP yo.ur.IP.add.ress, you should wait for few minutes to make DNS Service to force using the domain name.

Download WordPress & complete all the steps to bring the stuffs at root of FTP :

Vim
1
2
3
4
5
6
cd /usr/share/nginx/html
wget http://wordpress.org/latest.tar.gz
tar –xvf l*
rm –r latest.tar.gz && cd w*
mv * .. && cd ..
rm –r wordpress

Now, go to you IP address (or domain name) via browser. Very easy, it will offer you web form to fill the database name, database user name, database host name etc. Fill and continue. You will end up on a webpage telling you that WordPress can not write wp-config.php file and offer you wp-config.php‘s content to copy. Copy it and do the steps :

Vim
1
2
3
cd /usr/share/nginx/html
rm wp–config–sample*
nano wp–config.php

Paste the content in the file. Now, go to you IP address (or domain name) via browser and complete WordPress installation.

 

Install WordPress Plugins – W3 Total Cache

 

Go to WordPress Administration page by login via http://yo.ur.IP.add.ress/wp-login.php and first change the permalink to a sane one to make it either /post-name or /2015/11/post-name, finally install these plugins :

Vim
1
2
3
4
5
6
7
8
W3 Total Cache
WP Fragment Cache
DNS Prefetch
Redirection
WP–Optimize
WordPress SEO
Contact Form by BestWebSoft
Header and Footer

W3 Total Cache and WordPress SEO will need some configuration. For W3 Total Cache plugin (there will be an option named Performance on the left hand sidebar of WordPress Admin), you will use these settings :

Page cache: Enabled (Ticked), Disk:Enhanced
Database Cache: Enabled (Ticked), Memcached
Object Cache: Enabled (Ticked), Opcode XCache
Browser Cache: Enabled (Ticked)

W3 Total Cache will suggest changes. Copy it. On your server :

Vim
1
2
cd /etc/nginx/
nano w3tc.conf

and paste it. Include the w3tc.conf file by calling it from either nginx.conf or default virtual hosts file in this way :

Vim
1
include /etc/nginx/w3tc.conf;

Config test & reload :

Vim
1
2
nginx –t
service nginx restart

It is too basic configuration for WordPress and server side caching. WordPress DOT ORG has good documentation at codex.wordpress.org for Nginx configuration for WordPress W3 Total Cache. WordPress SEO will need some configuration as well – it is only few lines. Directly use the snippet on either nginx.conf or default virtual hosts file.

 

Conclusion on Nginx WordPress Installation Guide

 

This is a professional grade WordPress installation with no basic security part. This WordPress can not send email to you. So, you’ll need Mandrill and our snippet or any other cloud transactional email to make WordPress installation near perfect.

WordPress typically throw some odd errors. You should change XML-RPC stuffs to prevent XML-RPC attack.

At the end, you may need to chmod the wp-content directory to 755 :

Vim
1
sudo chmod 755 /usr/share/nginx/html/wp–content/ –R

Still, you may not be able to write from WordPress post editor. If such happens, fix by adding a line on wp-config.php file. If you need, only then you’ll do these steps.

Make it habit to check free memory by running free command, check processes by running top command, analyzing the log files etc. Analyzing these all, actually tells us whether we are under attack or not. Networking attacks are eliminated by the good web hosts fully manually before it reaches us. As it needs manpower, the cost of server increases. If you use $7 / month 6GB VPSDime, it is likely to be under attacks. Minimum using Linode, Aruba Cloud etc. are safer. VPSDime is great for many other works – running smaller websites, taking backup of all the other servers etc. However, you must use free DropBox cloud integrated with server to push whole FTP and MyQL backup as tar ball at least every 3 days. Last but not the least – you need a CDN. You can use KeyCDN or CacheFly.

There are dynamic website caching services from various service providers including Akamai. If you use them, need no optimization on your server – even no W3 Total Cache. We suggest to use either the full service of Akamai or CacheFly or DynDNS plus CloudFlare for maximum acceleration from DNS to PHP stuffs. Using Akamai’s all services makes our website to load within 3 seconds on webpage test test with 6 Ad units. The art of hand typed commands for installation and optimization of website is closer to death and only needed for cost saving purpose.

We have finished Nginx WordPress Installation Guide. Nothing to scroll to proceed to read more on this guide! Go to the top to Table of Content.

 

Tagged With wordpress , nginx wordpress , nginx wordpress windows 10 , wordpress update failed install new plugin windows nginx , nginx wordpress seo , wordpressnginx , Nginx Installation , nginx install wordpress windows , install wpress on nginx windows10 , how to install wordpress on windows nginx
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Nginx WordPress Installation Guide (All Steps)

  • WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud

    Here is a Step by Step Guide on Setting Up WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud with All Commands and the Configuration.

  • Zend Opcache Optimization for Nginx Ubuntu (HP Cloud)

    Here is Full Guide to Zend Opcache Optimization for Nginx PHP5-FPM for Ubuntu Server Running on HP Cloud. We Suggest to Use Zend Opcache over APC.

  • XCache Admin Page on Nginx-PHP5-FPM (Ubuntu, HP Cloud)

    Here is How to Setup a XCache Admin Page on Nginx-PHP5-FPM on Ubuntu Instance Running on HP Cloud. It Gives a Clear Graphical Idea of Caching.

  • How to Install WordPress : Ubuntu 16.04, Nginx, PHP7-FPM

    Here is Step by Step Guide on How to Install WordPress on Ubuntu 16.04, Nginx, PHP7-FPM, memcached & Percona MySQL 5.7 on Cloud Server or VPS.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Market Segmentation in BriefSeptember 20, 2023
  • What is Booting?September 18, 2023
  • What is ncurses?September 16, 2023
  • What is JTAG in Electronics?September 15, 2023
  • iPhone 15 Pro Max Vs Samsung Galaxy S22/S23 UltraSeptember 14, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy