WCPay 1.0 Launch

So you want to run WordPress on Nginx

Written by Patrick Garman on July 19, 2013 Blog.

There are some great managed hosting options available for WordPress, and it’s a hosting niche that seems to be growing quickly. WPEngine, Pagely, and Zippy Kid are usually the three big names you hear when Managed WordPress hosting is brought up in a conversation but sometimes you want a little more control over your website. While it is going to take a bit more than some guides on the internet to make your website scale to the extent those three providers could guarantee this is a great first start step for most sites out there.

This guide will take you step by step through every piece of your hosting environment and should leave you with a speedy stable website that is fairly secure as well. This process is very close to the same process I have used to help a handful of WooNinjas setup their own server.

Choosing your provider

Before I get into any of the configuration or setup of the server and website, I need to choose where the website will be hosted. There are more factors that go into this than just price and specs. Just like anything else you should also consider value, reliability, and support.

One of the providers I typically recommend for hosting is Rackspace and their Cloud Server platform. Their support is one of the key reasons I recommend them, on more than one occasion I’ve been able to get in touch with support late at night and get answers right away. We will be using their most affordable Cloud Server available which offers us 512MB of RAM, 20GB of disk space, and 1 vCPU. This is more than enough to power a handful of websites, and, after bandwidth, will cost about $18 per month.

I am also a big supporter of offloading everything you can off of your main web server. One of the benefits of Rackspace is the extra opportunities it allows us to take advantage of.

Rackspace Cloud Databases – Offers us a managed MySQL instance using lightning fast SSD’s and adds a security benefit of requiring all connections to the database to be within the same datacenter. A single 512MB instance with 1GB of disk space will be about $44 per month.

SendGrid – SendGrid offers Rackspace customers a special free plan for up to 40,000 emails to be sent per month.

Cloud Passage – Cloud Passage also offers Rackspace customers a free plan which will give you an easy to configure firewall and allows you to setup two factor authentication for SSH & SFTP.

New Relic – Last but certainly not least New Relic offers Rackspace customers free Standard monitoring of their servers. The feeling of your fast websites will be backed up by the data you will have through New Relic.

With Rackspace the total cost of running a handful of speedy websites is a little over $60. The number of websites you can run off of this setup is limited only by the amount of traffic each website receives.

Build your platform

When you first login to Rackspace you will be greeted by a page with a big red arrow pointing to a Create Server button, click that button!

You will then enter a server name (“wordpress” will work for our purposes) and choose a region (you want “Next Generation Cloud Servers”).

I would suggest using Ubuntu 12.04 LTS as your OS but Ubuntu 13.04 will work just fine as well. The only requirement is you use Ubuntu. The reason you may want to use an older version of Ubuntu is because every two years a “LTS” version is released and LTS stands for “Long Term Support.” You can visit the Ubuntu wiki to learn more about LTS.

Now just choose the size of your cloud server (512MB) and click the Create Server button one more time and the server will begin building!

Write down the root password that appears, you will not get this password after you dismiss it.

While your server is building you will want to move on over to the “Database” section of the control panel and click “Create MySQL Instance.”

Simply enter an instance name (anything will do), leave RAM at 512MB, 1GB of disk space and be sure to choose the same region as your original server. Below the region you can add a database with a name (wordpress), user (wordpress), and password (your choice – make it secure!).

This database will only be accessible through the private network within the same datacenter, which means would be hackers have one less way to access your data but also that you must plan accordingly. Click “Create Instance” to continue and the database server will begin building.

You will see a really long URL on the next screen, this is what you will enter as your database host when you install WordPress so keep this saved somewhere handy.

By now the server has built itself and you can SSH into it. If you go back to the “Servers” portion of your control panel you should have an IP address for the server and a solid green bar on the left showing that the server is “active” and not “building.”

If you have any issues during this process you can click the live chat button at the top of your screen and get quick help from a Racker right away.

Install the software

This section of this guide is going to get a bit techy-er than the rest. It involves sending commands to a server using your terminal and configuring your software. You do not need to be an expert to copy and paste the commands/files but you should have a basic working knowledge of SSH and how to connect to remote servers.

You will want to use the command below to SSH into your server, but be sure to replace the temporary IP address (123.123.123.123) with your Public IP address. You will be asked for your password that you should have saved earlier so type that in as well, and if you are asked if you want to add the server to the list of known hosts you will want to answer yes.

This first set of commands is going to update and upgrade all the existing software that is installed by default – updated software on your server is always good just like you would always updater your themes and plugins in WordPress. After you’ve upgraded everything the next commands will install the new software (Nginx, PHP, and some basic utilities). The last step is to start Nginx and PHP and make sure they work.

Welcome to nginx!

If you open your server’s IP address in a browser now you should see a blank white page that says “Welcome to nginx!” in it. This means you have succeeded, congratulations!

So far you have run all the commands as “root” on your server, and you do not want your website running under root. I also prefer not to use the “www-data” user on the server either.

To save headaches and just solve all the permissions issues right out of the gate I create a brand new user that will only have access to their home directory. We are going to make PHP run as that user and all of the files will be in that users home directory. When you SFTP into your server that is the username you will use. Since we are installing WordPress the username is going to be… WordPress! I’m sure you did not see that coming.

These next commands are going to create the WordPress user, create a few directories, and then download and unzip the latest version of WordPress from WordPress.org. After that, it ensures the WordPress user is the owner of all the files and resets the WordPress user’s password as well. Don’t worry, you will be prompted to enter a new password so the choice is yours.

We’re not done yet!

You may have noticed your server still is welcoming you to Nginx and not showing you WordPress yet. There are three scripts below for you.

The first is actual commands you need to run, this will delete the default configurations, create new ones, and then restart the services. When you use Nano (or your favorite editor) to edit the Nginx or PHP configurations you will want to copy and paste the entire sample configurations in and save the file. The Nginx configuration is a simple standard WordPress setup, and PHP will use the static process management to always have 3 processes ready at all times but respawn after 500 requests.

Nginx

PHP

Five minutes to install WordPress

After restarting Nginx and PHP if you browse to your servers IP you should see a familiar WordPress installation screen. Simply enter your database information you kept handy from before, pick a nice username (anything but admin!) and password and start pressing your words.

Bonus Points!

All those tools Rackspace gives you the opportunity to use for free are great, but they need to be installed first. After you’ve signed up for your accounts just run the commands in the script below (be sure to replace the key placeholders with your own) and the server should automatically appear in your control panels for you to configure however you would like.

If you have ever wanted in-depth analytics about how your site is performing or two factor SMS authentication to be able to SSH into your server… these are just some of the features you will get for free!

cta-banner-10-product-page-v2_2x

33 Responses

  1. Gemma W.
    July 20, 2013 at 11:01 am #

    While I appreciate this article is probably aimed at those who like to tinker, this approach would make no sense whatsoever for me. For me personally, I’d rather pay WP Engine to do all of that and more for me, leaving me free to do what I do best instead of having to deal with WP/server headaches. Time is far more precious than money, in my book.

    Nice tutorial though. 🙂

    • Michael Cabral Poubel Bastos
      July 20, 2013 at 7:45 pm #

      Gemma, there are plenty of people that think like you do and that is fine, but keep in mind that before there was WP Engine there was pagely and before then there was WordPress.com, I’ve been around the WP community long enough to hear all these arguments before, why would I host a .org site when I can host it on .com or pagely is so much easier than doing it myself why would I bother. Regardless of how you feel about their affiliate Link to Rack Space these kind of “tinkering” tutorials are what help others build the next generation of tools that allow you to do what you do even easier and help the community as a whole so I for one hope to see more if these kind of tutorials.

      • Patrick Garman
        July 22, 2013 at 6:11 pm #

        Exactly 🙂 This post may not be for everyone but to some eyes this may be the spark that gets them innovating.

  2. anonymous
    July 20, 2013 at 12:05 pm #

    This comment was brought to you by Rackspace.

    • David
      July 20, 2013 at 12:47 pm #

      Pretty poor of woothemes not even mentioning that any rackspace links connect straight to an affiliate account…

      • matt
        July 21, 2013 at 11:18 pm #

        Why? WooThemes is a business. You can’t expect them to do an exhaustive how-to like this just for the fun of it.

  3. stooni
    July 20, 2013 at 12:48 pm #

    Thanks for these Tutorial!

    Realy fine, and though!!!

  4. Lee Peterson
    July 20, 2013 at 10:08 pm #

    For those unable to afford $60/month…

    For just $10/month, you can run this same configuration on SSD disks at DigitalOcean. One server for WordPress application; one server for MySQL database.

    • Andrew
      July 22, 2013 at 8:36 am #

      I’m thinking about moving to DO and doing the same thing, not sure having a box for Nginx & PHP and another for MySQL is worth the hassle.

      • Kevin
        July 22, 2013 at 4:01 pm #

        Why would you need two boxes? Moving you DB to a separate server is a really bad idea if you’re on Rackspace. Been there done that and performance is worse than running everything on a single box. With RS, I suggest you expand vertically if you need more resources.

        Yes, move to Digital Ocean. I promise you will love it!

        • Patrick Garman
          July 22, 2013 at 6:14 pm #

          On two “cloud servers” I had similar experience with performance but the “cloud databases” platform was a different experience entirely. I wish there was more data available on the MySQL server because currently you have no way of tracking performance other than within your application and the disk space, even talking with support its not possible to find out CPU/RAM utilization.

        • Alex
          July 22, 2013 at 8:35 pm #

          Running your DB on another vm is a nightmare why? Unless you set up a VPS with them both on the same box you’d be hard pressed to find a host who would provide you with mysql on the exact same box anyways. I have used Rackspace for all sorts of hosting in the past and their Database Hosting is maybe their strongest product, if you had performance issues I would ask for some help, after all one of the main reasons to pay for Rackspace is the fully managed customer support. I’m not being paid to solicit them in any way, just for the record. Also @above, you can likely find a similar configuration at a lot of hosts for much less money. The reason you shell out more for Rackspace is reliability, great integration between all their different products and the best support I’ve ever dealt with at any company ever (seriously those guys are incredible, none of that reading from a notebook pre-canned answers junk, they are actually educated about their offerings and very industry aware. If you’ve ever dealt with hosting support you know what I’m talking about, all too often other companies are quick to blame faultless third party stuff simply because they don’t understand it or your situation and needs. I’ve never found that to be the case with Rackspace). The other reason that I personally think they are great is because they are Texas based and I’m a Texan. That means nothing to most of you but they employ their staff including support here locally in the USA, to me that is very important.

          Sorry for the little rant but as an honest to god customer of Rackspace for several years and after going through the ringer with other supposedly quality companies I will never again host elsewhere by choice and cannot recommend them enough to anyone serious about their websites ( Even if your site is very small and non income generating you can manage with the lowest possible server which is less than $20, and if you have a serious website the ability to scale and have a real team behind you to back you up with real technical expertise is well worth the cost.) I will grant that Rackspace is not a great fit for those not at all interested in putting in the time to self deploy a VPS for small sites, but if you have a real need they do offer fully managed and maintained services too, but they are costly ( costly compared to a non managed solution, not really costly in comparison to other managed solutions in my experience).

          TLDR; Rackspace is the stuff, They are worth every cent and more.

        • Alex Boorman
          July 22, 2013 at 9:34 pm #

          I have used Rackspace for all sorts of hosting in the past and their Database Hosting is maybe their strongest product, if you had performance issues I would ask for some help, after all one of the main reasons to pay for Rackspace is the fully managed customer support. I’m not being paid to solicit them in any way, just for the record. @The Many Above, you can likely find a similar configuration at a lot of hosts for much less money. The reason you shell out more for Rackspace is reliability, great integration between all their different products (Email, CDN, DB Hosting – DB Hosting is critical for high usage sites, having true scalability comes from the ability to add and balance loads for databases especially) and the best support I’ve ever dealt with at any company ever (seriously those guys are incredible, none of that reading from a notebook pre-canned answers junk, they are actually educated about their offerings and very industry aware. If you’ve ever dealt with hosting support you know what I’m talking about, all too often other companies are quick to blame faultless third party stuff simply because they don’t understand it or your situation and needs. I’ve never found that to be the case with Rackspace). The other reason that I personally think they are great is because they are Texas based and I’m a Texan. That means nothing to most of you but they employ their staff including support here locally in the USA, to me that is very important.

          Sorry for the wall of text but as an honest to god customer of Rackspace for several years and after going through the ringer with other supposedly quality companies I will never again host elsewhere by choice and cannot recommend them enough to anyone serious about their websites ( Even if your site is very small and non income generating you can manage with the lowest possible server which is less than $20, and if you have a serious website the ability to scale and have a real team behind you to back you up with real technical expertise is well worth the cost.) I will grant that Rackspace is not a great fit for those not at all interested in putting in the time to self deploy a VPS for small sites, but if you have a real need they do offer fully managed and maintained services too, but they are costly ( costly compared to a non managed solution, not really costly in comparison to other managed solutions in my experience).

    • mike
      July 22, 2013 at 10:21 pm #

      I can’t agree more about DigitalOcean. I was turned onto them by a friend about a year ago and couldn’t be happier. Until then I actually ran my own servers in a local colo facility and thought I would never stop doing that. DigitalOcean has been a godsend for me. Their support is second to none, heck just check the forums and you will see what I mean. The speed is absolutely amazing as EVERYTHING is run on SSD’s. As to size, they are the fastest growing cloud company on the planet at the moment (google for stats).

      How anyone can justify spending $60/month when you get the same (well faster due to SSD) service for only $5/month is beyond me. Pure unadulterated advertising for rack on the part of Woo (affiliate links), but I expect that these days.

      I do appreciate the ‘basic’ nginx article though. To bad that it ended here as there are hundreds of advanced techniques and settings you can use to further optimize the server setup.

  5. Kevin
    July 22, 2013 at 3:56 pm #

    I’m both a Rackspace and Digital Ocean customer, and the only reason I still have a $1000/month Rackspace account is because my customer is paying for their support. That’s it. And I even charge them extra to deal with Racksapce because of the delays in getting servers up and all the default security settings I have to change. Digital Ocean is faster, cheaper, all natural, and has less bloatware. You can also spin up a server with your ssh keys in less than 60 seconds.

    But I thought this tutorial was to get WordPress running on Nginx, but instead we get an ad “brought to you by Rackspace.” You seriously need to add an Nginx conf file; PHP5-fpm, APC and memcached setting; and caching plugin Nginx server configs. All that is not for even the coolest of tinker bells but a task for someone who knows Nginx.

    Woothemes, do you know Nginx? If not, just suggest Litespeed Web Server. It’s a drop-in replacement for Apache and will auto-tune to your server resources.

    • Patrick Garman
      July 22, 2013 at 6:26 pm #

      I’ve tested out a number of VPS providers myself (Digital Ocean included) and still stick with Rackspace as my suggestion for someone who is just getting started. The reason for that is primarily the support, apps you can access through them, and all around stability. It’s definitely not the best performance I’ve had with a VPS but for someone who is just getting started with Nginx & WordPress (or any VPS) it’s a good “all around” host.

      I’m sure it’s just bad luck but my own experience with Digital Ocean hasn’t been spectacular. The price and SSD’s is great, but in the month I’ve had a test VPS up there it’s had two separate instances of unplanned downtime. 🙁

    • Alex
      July 22, 2013 at 9:42 pm #

      This is valid, they really haven’t explained anything all that useful here. Sure they tell you how to spin up an nginx server but they give you nothing in regards to configuration or set up. The real value of Nginx comes from configuring it for your environment (that and it’s a gem for reverse proxy). Out of the box not all that useful for anyone. People who don’t already have some knowledge on the matter would do better just rolling Apache or Litespeed, you’ll probably have better results if you don’t know what you’re doing.

    • Nux
      August 20, 2013 at 8:23 pm #

      Right. A few problems that I have with this article:

      1 – Why can’t you show me some content without requiring me to run your javascript?!
      2 – Masked advertising for Rackspace & Co.

  6. Jesin
    July 22, 2013 at 5:53 pm #

    I am very disappointed by this article, this seems more of a Rackspace guide/affiliate article than an article on nginx.

    There is not a single line of code for nginx.conf and nothing on performance optimization.

    There are lots of other websites like howtoforge and nixcraft which explain LAMP and LEMP performance optimization techniques.

    • Nick M.
      July 29, 2013 at 4:45 pm #

      @Jesin,

      Config Nginx is a whole article in itself considering rtcamp has around 40 huge articles devoted just to that topic. When I setup nginx first time over 3 years ago, most tutorials were posted by people who never tried them , and I spend days trying to figure things out. I would have been happier than a dumbass posting a stupid comment had I found this nicely illustrated easy to follow tutorial for someone using Ubuntu command line for the first time in their life.

      @Patrick,

      Don’t listen to these bozos. You did a fine job for a target audience. It’s funny reading the comments that the same jackasses who denounce using an affiliate link as immoral, have no qualms about piggybacking on your article with their own promotional message , peeking out from behind a cloud of phoney self righteousness and hipster poseurism.

  7. moxiedeveloper
    July 22, 2013 at 6:07 pm #

    You can run the same setup on Linode with a bit of modification to this article. In working with both Linode and Rackspace for WP on LEMP stacks I can say Linode is the best in the biz. There pricing, technology and support are unparalleled. In addition they now offer managed support so you can offload all of your support requests regarding your server. I also find using the LTS versions of Ubuntu a much better choice.

    Also – This article is a bit outdated but with a bit of research you can get your self up and running on any cloud hosting service with bonus for Varnish Caching: http://www.ewanleith.com/blog/900/10-million-hits-a-day-with-wordpress-using-a-15-server

  8. erlend_sh
    July 22, 2013 at 6:14 pm #

    I don’t mind affiliate linking, but I do appreciate a heads up. Everyone has their biases and preferences. If an affiliate connection directed your bias in this case, that’s absolutely fine, just be frank about it. This isn’t so much “so you want to run WordPress on Nginx” as it is “Running WordPress on Rackspace with Nginx”.

  9. Sean
    July 22, 2013 at 7:00 pm #

    How is this different to having your own server at say hostgator and installing WP on that?

    • Patrick Garman
      July 22, 2013 at 7:21 pm #

      Theoretically if you have the same specs and software stack it is the exact same just with a different provider. In actuality different hosts will offer the same specs but due to a number of other factors the performance can vary. I don’t have any experience with HostGator VPS specifically though.

  10. Wil
    July 23, 2013 at 5:23 am #

    Great tutorial Patrick.

    Isn’t the NGINX script in the “We’re not done yet!” section missing though?

    Wil.

  11. samuelthan
    July 23, 2013 at 6:22 am #

    I view this post as a spark for those who like to get their hands dirty rather then “show me the quickest way to make my site fast”.

    Thanks for the write up.

    I’ve been doing such configuration for sometime running on VPS and SSDs. If you know what you are tweaking/configuring in NGINX, one should able to squeeze some performance out of a budget box.

    But again, who’s the best hosting provider is subject to your budget and expectations on various services that comes with it. I’ve not use rackspace myself but have been using some other hosting company and i’m happy with them – RAMNODE 🙂

    Anyway, long-live NGINX….

  12. Vid Luther
    July 23, 2013 at 9:32 am #

    Patrick,
    A couple of suggestions to make this article better.

    1. You seem to be missing the sample configurations that people would want to paste for their nginx virtual host.

    2. You didn’t point out some of the ways to secure your site, for example, you’re not showing how to deny the execution of php, how to force everything by index.php.

    3. For the new relic, you forgot to show how to install the new relic PHP agent and how to configure it with php-fpm so people can actually profile their WordPress site.

    • mike
      July 24, 2013 at 1:07 am #

      Please, do share!
      I”m really interested in #2 and #3 specifically as the solution to #1 was quite easy to find online.

      Maybe there is an article you can link to for us?

  13. Jim Walker
    July 23, 2013 at 6:54 pm #

    Quite an excellent setup article for Rackspace cloud. Makes me want to try it myself.

    Title of article seems a bit misrepresented. I got no qualms with a guy trying to make a buck in promoting his favorite web host, though arguably the article has little to do with WordPress.

    Thank you for the juicy comments guys- which are well worth the price of admission!

  14. Houston
    August 8, 2013 at 5:07 pm #

    Thank you, Patrick!

    My take is that you are speaking to that audience that is willing to tinker and looking for inspiration, and this definitely has me asking the questions I need answers to to be able to move forward.

    Question: Where would be a good place to look for someone with the knowledge and expertise to take on this task, AND the generosity to share HOW it’s done? Fiverr.com or craigslist — any suggestions?

  15. Max
    August 16, 2013 at 11:03 am #

    Many thanks indeed!

    The state of wp+nginx tuts has come leaps and bounds in the last several months!

    Seriously, less than a year ago I realized that Nginx was the way forward… and proceeded to use my just-enough-to-be-dangerous sysadmin skillz to spend three months almosting getting this amazing nginx+php-fpm+maria+varnish an a sweet ssd kvm with a solid 1000mb/s port… it was gonna be sooo sweet!

    … and then I realized that though it had cost me very little dollars (big thanks to Nick @ ramnode*com) it had cost me THREE MONTHS of lost time on my overall development plan, because I am not actually a super slick sysadmin… nor do I really want to focus upon becoming one at this time…

    In fact, I want be part of creating an awesome online marketing activism business from a netbook while traveling the world and planting plants and such (but thats just me, I’m sure you have your own dreams 🙂

    In the end, I concluded that even if I got it all working later that night, it was still time to call it done. I was doing this all so that my WordPress installations would be precociously quick and robust enough to be, well, really robust!

    So I started looking for a happy medium between what I had been doing and the (at that time) relative handful of super premium hosts who were effectively advertising their nginx+varnish wordpress hosting capabilities… I’m pretty good at the internet, and I spent many nights pouring through pricing pages, service terms, reviews, forums, and so on.

    Conclusion: Its really hard to figure this out too. It seems half the super premium value is in delivering unimpeachable performance, the other in putting the whole thing to rest.

    Anyways, after ANOTHER three months looking for the right value and values from a host, I found euroVPS.com through webhostingtalk and let me tell you, they are, in a word, superb.

    The real steal is that while they sure know what they are doing with nginx, they really shine with varnish cache… 🙂

    I had planned to use several dedicated varnish servers in my attempt. I’d still be working on it I’m sure.

  16. dev
    September 10, 2013 at 7:55 am #

    Woothemes running out of fuel & $$$.

    Broken bullshit CJ affiliate links?

    • dev
      September 10, 2013 at 7:56 am #

      Woothemes running out of fuel & $$$.

      Broken bullshit CJ affiliate links?

WooCommerce - the most customizable eCommerce platform for building your online business.

  • 30 day money back guarantee
  • Support teams across the world
  • Safe & Secure online payment
%d bloggers like this: