Page 4 the LEMP stack - Nginx, PHP, MySQL
In the past, with Debian 5, it was very frustrating trying to stay up to date with the latest versions of PHP, MySQL and Nginx because the packages were always so outdated. Debian 6 shipped with up to date versions but if you want the latest performance packages your going to need the Dotdeb repositories.
Dotdeb is a repository containing packages to turn your Debian boxes into powerful, stable and up-to-date LAMP servers :
- PHP 5.3
- useful PHP extensions : APC, imagick, Pinba, xcache, Xdebug, XHprof…
- MySQL 5.1 and its performant InnoDB plugin,
- Maatkit…
Add the Dotdeb repos to /etc/apt/sources.list
deb http://packages.dotdeb.org stable all deb-src http://packages.dotdeb.org stable all
Now fetch the appropriate GnuPG keys
wget http://www.dotdeb.org/dotdeb.gpg cat dotdeb.gpg | apt-key add -
Run apt-get update and you should see your server connecting to the dot deb mirrors.
Note: Dotdob is a one man operation maintained by Guillaume Plessis, @W_a_s_t_e on Twitter. If you benefit or prosper from his packages consider donating
Install Nginx, PHP-FPM, MySQL, APC
apt-get install nginx-full php5-fpm php5 php5-mysql php5-apc php5-mysql php5-xsl php5-xmlrpc php5-sqlite php5-snmp php5-curl
You will be prompted to accept installs and apt-get will make sure all dependencies are met and install additional packages if needed. When you get to the MySQL install a semi-graphical interface will pop up. Make sure you choose a password for the root mysql user.
If you have made it this far go grab a beer or an espresso you deserve it, Systems Administrator.
Next Page: the .confs
just checking one thing: the w3 total cache rewrite rules are only needed if using disk cache, right?
Yes you really only need the W3 rules for disc cache. They just add a finer level of control for the browser cache rules. I just updated the server file to show a full example of the W3 Rules using disk enhanced page cache and disk minify.
Hi,
Great post, thanks a lot for the information. From the title I got the impression, you were going into the details of multiple wp installs with one ngnix or via multiple xen installs.
Do you have any best practices about this? Or even some up to date ressources?
Thanks again for the great post.
Hi Costa,
Thanks for the feedback. I updated the post to include configuration files for a WordPress multisite and also hosting multiple sites on the server.
Hi,
Thanks a lot for the additional configuration information. It’s really helpful.
Regards
I’ve got a noob question about SSH keys. If I’ve installed the SSH key on the server it means that I can only login to it from my computer right? What if I don’t have my computer with me and have an emergency and need to SSH into the server?
Using SSH keys you will only be able to login if your computer contains a private key that matches a public key installed on the server. I prefer the added added security they provide but if you often need to access your server away from your computer then maybe a really strong password would be better for you.
If your using password authentication you can change the ssh port to prevent a majority of the brute force attempts. Also some VPS and dedicated server hosts have a java console you can use to access your server without having to use your ssh keys.
Just a note that “you are” is shortened to “you’re”, not “your”.
Otherwise, thanks for the great write up!
Hey Guys:
Awesome tutorial — my first foray into nginx w/ wordpress.
A couple things I got snagged on in the tutorial & the fixes:
> When installing everything the first ‘php5-mysql’ should be ‘mysql-server’ instead since there is already a php5-mysql package a little later in the command
> There’s a missing closing ‘}’ at the end of the file in the sites conf
> Upon trying to install wordpress I got “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.” Fixed this by editing the php.ini inside the php-fpm dir.
>> I un-commented ‘extention=mysql.so’ as well as uncommenting ‘extention_dir = “./”‘ and changing ‘./’ to /usr/lib/php5/20090626+lfs and all was well.
Thanks again guys! Loving nginx so far!
Hi
Great guide thank you, I have one question about file ownerships/permissions.
Presumably everything in my site’s public folder needs to be owned by www-data and in the www-data group?
If so, how can I then upload and/or edit files when logged in as a non-root user? Do I just need to add my user to the www-data group?
Any advice much appreciated, I find this bit quite confusing!
Any recommendations for creating init scripts to ensure all the services start automatically after a reboot?
All the packages in this tutorial include the required init scripts.
-location ~ \.php {
+location ~ \.php$ {
-location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
+location ~* \.(ico|css|js|gif|jpe?g|png)$ {
-rewrite ^.*/files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
+rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
Hi,
Thanks for your tutorial, I finally get my wordpress working on LEMP stack.
However, if any of your reader need the easy way to install wordpress, you can use https://github.com/buchin/WordPress-On-Lemper
Which is based on this tutorial.
It assumes you’ve installed nginx, php-fpm, and mysql, and need multipe WordPress installed on multiple domains.