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 : 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.
---
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 :
- 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.
- Nginx is not exactly for the newbies. It is better to have an idea of using typical LAMP servers.
- 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.
- 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 :
1 2 | apt update –y && apt upgrade apt dist–upgrade |
First, we will add Percona’s repo :
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.listecho “deb-src http://repo.percona.com/apt lsb_release -cs main” >> /etc/apt/sources.list.d/percona.listapt–get update |
Then install Percona MySQL server :
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 :
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) :
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 :
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 :
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 :
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 :
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 :
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
:
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.cnf
created after running the sudo mysql_install_db
command. 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 :
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 :
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 :
1 | cp /etc/mysql/my.cnf ~/my.txt |
then empty the file :
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 :
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 :
1 | service mysql restart |
If fails to restart, then quit with control
+ c
(for Mac) and check the error file :
1 | cat /var/log/mysql/error.log |
Nginx WordPress Installation Guide : Install Nginx
First add nginx
to www-data
group :
1 | sudo usermod –aG www–data nginx |
We use nginx-extras
, nginx-extras
is almost like Nginx Plus. One command :
1 | apt–get install nginx–extras |
Open the default virtual host file :
1 | nano /etc/nginx/sites–available/default |
Minimum, modify few lines on that file :
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 :
1 | nano /etc/nginx/nginx.conf |
Minimum, modify this line on that file :
1 | error_log /var/log/nginx/error.log warn; |
Run nginx -t
to check whether everything is fine. Then restart Nginx :
1 | service nginx restart |
Recursively chown
the public directory :
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 :
1 | https://codex.wordpress.org/Nginx |
Nginx WordPress Installation Guide : PHP5-FPM
Big one line command :
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 :
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 :
1 | nano /etc/memcached.conf |
Modify the memory to -m 1024
. By default, its to less.
Next, open this file :
1 | nano /etc/php5/mods–available/memcache.ini |
Add these two lines at bottom :
1 2 | session.save_handler = memcache session.save_path = “tcp://localhost:11211” |
Restart the services :
1 2 | service memcached restart service php5–fpm restart |
Now, Zend OpCache. This is needed for making slow PHP faster. Open this file :
1 | nano /etc/php5/fpm/conf.d/05–opcache.ini |
Open to add/edit these lines :
1 2 3 4 | opcache.memory_consumption=512 opcache.max_accelerated_files=50000 opcache.revalidate_freq=0 opcache.consistency_checks=1 |
Restart the service :
1 | service php5–fpm restart |
Remaining is XCache. If we run :
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 :
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 :
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) :
1 | sudo apt–get purge —auto–remove php5–xcache |
Reload the services :
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 :
1 | service php5–fpm restart |
after correction, it will reload fine. Basically this is safer while changing/tweaking any PHP related settings file :
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 :
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 :
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 :
1 2 | cd /usr/share/nginx/html/mystat mv * ~/mystat |
When you’ll want to see, do the reverse :
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.
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 :
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 :
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 :
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 :
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 :
1 | include /etc/nginx/w3tc.conf; |
Config test & reload :
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
:
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.
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