Well, for a long time I have been looking for the perfect WordPress hosting setup. I end up using the combination of nginx, php-fpm and memcached. The other option is using apache and php while the difference is the way these two web server handle request and use php. As far as I understand, nginx has a more simple way of dealing with php using php-fpm and the way it handle modules and caching boosts the performance.
So even though the nginx configuration is like a nightmare I start giving it a try and after so many challenges I end up making it working! Obviously, the apache configuration is much simpler but if you need to satisfy millions of users then nginx can be a better option.
In my experience I used an EC2 t2.medium instance (just for 5 hosts) and Amazon Linux AMI as OS. So now we are going to install the services and modules before starting the configurations.
First we install the followings and create a cache directory for nginx fast-cgi:
yum install nginx yum install php56-fpm mkdir -p /var/cache/nginx/ yum install php56-mysqlnd #if needed yum install memcached #if needed
(I assumed your MySQL is hosted in another server.)
And then we create the root directory for websites with a simple default html file. The nginx process is the owner along appropriate permissions cause no one supposed to change it except us!
mkdir -p /var/nginx/sites/default echo 'You should not be here!' > /var/nginx/sites/default/index.html chown -R nginx:nginx /var/nginx/sites/default chmod -R 701 /var/nginx/sites/default
and then making the website root directory with right owner and permissions (the ftp-user group contains all users for that group and all of them only are able to access to this directory).
mkdir -p /var/nginx/sites/abcd.com chown -R nginx:abc-ftp /var/nginx/sites/abcd.com chmod -R 711 /var/nginx/sites/abcd.com
Appendix 1 and 3 should be available in proper directory and appendix 2 template should be used for adding additional websites to host.
And finally test the configurations: service nginx configtest
Now it’s time to start the engine! service nginx start; service php-fpm start;
now copy your wordpress source in /var/nginx/sites/abcd.com/ folder and you should be able to browse your website(s) and just use the wizard to setup database connection.
Once you entered the wordpress admin panel you can install W2 Total Cache plugins which can be configured to use memcached for a boost in performance. After all the performance is mostly about caching so maybe in another post I explain more about wordpress caching options.
Please remember to change the user and group in /etc/php-fpm.d/www.conf file:
user = nginx
group = nginx