A complete WordPress-Nginx setup will involve PHP, MySQL, Nginx stack and on the top of it WordPress itself. This is the bare minimum requirement for WordPress. Postfix is highly recommended but technically you can use other packages for SMTP or even use remote SMTP servers like gmail.com to send mails using WordPress.
If you already have PHP, MySQL & Nginx up & running then you may jump to next part i.e Nginx configuration for different WordPress
I am assuming few things before you start.
- You have a Ubuntu server up and running. This guide may work on other Debian based distros but this is tested on Ubuntu 12.04 LTS only.
- You have shell access to your Ubuntu server with sudo privilege or you have direct root-user access.
Installing PHP 5.4
We are going to use PHP 5.4 as it is much faster & better than PHP 5.3.
As official repo for Ubuntu 12.04 LTS contains PHP version 5.3 only, we will use a launchpad repo maintained by Ondřej Surý
Run following codes to add launchpad repo to apt-sources:
sudo apt-get install python-software-properties sudo add-apt-repository ppa:ondrej/php5
Press “enter” key whenever asked!
This is must otherwise next command may end up installing PHP 5.3!
sudo apt-get update
Now, run following to install PHP itself
sudo apt-get install php5-common php5-mysql php5-xmlrpc php5-cgi php5-curl php5-gd php5-cli php5-fpm php-apc php-pear php5-dev php5-imap php5-mcrypt
Alternatively, you can compile PHP yourself. [TODO: I will post separate article for that]
Check PHP Version
Run following command…
You will see following output…
PHP 5.4.6-2~precise+1 (cli) (built: Aug 30 2012 14:37:22) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
With MySQL, we will also install an extra package
mysqltuner here. It is one of the best way to optimize your mysql configuration.
sudo apt-get install mysql-server mysqltuner
Above wizard should ask you to enter a mysql password for user
root. If it doesn’t, then run the following command to change MySQL password.
sudo mysqladmin -u root password NEWPASSWORD
Please note that above command will not help you in case you forget your mysql root password in future. [TODO: Post help]
If you want to send mails from your WordPress, you will need a SMTP server. You can use a remote SMTP server like gmail.com for this. But I prefer using postfix package to run a SMTP server locally.
In simple words, if you skip this step and do not configure remote SMTP server with WordPress either, your WordPress will not be send email notifications for comments, etc.
sudo apt-get install postfix
It will take you through few steps. The important one are:
- Select option – Internet Site
- Hostname – generally your main domain i.e example.com. Recommended – a FQDN like mail.example.com
You no need to touch other options. Just restart mail service to be safe.
Testing your mail config:
Run following PHP code with firstname.lastname@example.org replaced by your mail id:
php -a mail ('email@example.com', "Hello from nginx!", "My email setup works!"); exit ();
Alternatively you can use check-mail WordPress Plugin after your WordPress setup completes to be sure that your WordPress can send emails.
Ubuntu official repos come with a Nginx package but I prefer using launchpad repo maintained by Nginx team.
sudo add-apt-repository ppa:nginx/stable sudo apt-get update sudo apt-get install nginx
If you prefer to use Nginx package in Ubuntu repo, you can simply run following command:
sudo apt-get install nginx-full
At this point, we are done with installing prerequisite for WordPress.
In the next article, we will jump to basic WordPress installation & configuration.
After that, I will share some commonly used optimization tips and configuration tweaks and then we will touch complex WordPress configuration. You can also find the complete list of WordPress-Nginx tutorials here.