• PHP
  • Ruby on Rails
  • MySQL
  • Linux
    • SELINUX
    • Fedora
    • debian
  • Apache
  • nginx
  • AJAX
Albertech.net

Installing nginx with PHP, MySQL, and WordPress in Fedora

April 1, 2011 12:31 pm / Albertech.net

Interested in installing nginx on a Fedora system? The configuration with nginx is more complicated than Apache since  it requires the setup of the nginx server and a separate daemon for running PHP. I prefer creating the daemon from scratch rather than going with the fpm route in Fedora 14 since there isn’t official support for it. I’d certainly install the fpm package once its available in Fedora.

Why switch to nginx?

If you have a site with heavy CPU and memory load in Apache, then nginx is a great choice. I recently made the switch to nginx and have noticed a reduction in CPU and memory usage. Nginx loads static content very fast and efficiently.

Here’s a graph of my nginx server load test. Courtesy of LoadImpact‘s free load testing service.

The user load time on my server is minimally impacted with 50 clients viewing the site simultaneously.

nginx disadvantages

The biggest drawback to nginx is that it does not have per-directory configuration files and does not support Apache .htaccess files (which is heavily used in many web apps such as WordPress).

Here’s a list of resources for installing nginx on Fedora Release 14

1) Linode.com has an excellent tutorial on setting up nginx on Fedora.
http://library.linode.com/web-servers/nginx/php-fastcgi/fedora-14

This should be sufficient to get nginx running. I had to tweak the php-fastcgi-init-rpm.sh to work on my system, specifically with the configtest section inside the init script. You should check the service to make sure it works correctly via the “service php-fastcgi stop”, “service php-fastcgi start”, “service php-fastcgi restart”

https://library.linode.com/web-servers/nginx/php-fastcgi/reference/php-fastcgi-init-rpm.sh

2) Setting up WordPress on Fedora

Once nginx is running, you will need to tweak the /etc/nginx/nginx.conf to work with WordPress. This is required to emulate the Apache Rewrites in nginx. This is essential on a multi-site install with WordPress 3.1, blogs located in subdirectories . If not, you will get errors in WordPress for wp-admin missing, broken templates, broken plugins, etc.

This is a really good tutorial on setting up WordPress with nginx.
http://wordpress.org/support/topic/nginx-php-fpm-php-apc-wordpress-multisite-subdirectory-wp-super-cache

The following configuration file is the one I used to get a multi-site install of WordPress running on nginx/Fedora. It has the zero-day exploit defense built-in along with support for super cache and w3 total cache plugins. Special thanks to bigsite.

# WordPress multisite subdirectory rules.
# Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# Directives to send expires headers and turn off 404 error logging.
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 24h;
log_not_found off;
}

# Pass uploaded files to wp-includes/ms-files.php.
rewrite /files/$ /index.php last;

# For multisite: Use a caching plugin that creates symlinks to the correct subdirectory structure to get some performance gains.
set $cachetest "$document_root/wp-content/cache/ms-filemap/${host}${uri}";
if ($uri ~ /$) {
set $cachetest "";
}
if (-f $cachetest) {
# Rewrites the URI and stops rewrite processing so it doesn't start over and attempt to pass it to the next rule.
rewrite ^ /wp-content/cache/ms-filemap/${host}${uri} break;
}

if ($uri !~ wp-content/plugins) {
rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
}

# Uncomment one of the lines below for the appropriate caching plugin (if used).
# include global/wordpress-ms-subdir-wp-super-cache.conf;
# include global/wordpress-ms-subdir-w3-total-cache.conf;

# Rewrite multisite '.../wp-.*' and '.../*.php'.
if (!-e $request_filename) {
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
# Zero-day exploit defense.
# http://forum.nginx.org/read.php?2,88845,page=3
# Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
# Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine. And then cross your fingers that you won't get hacked.
try_files $uri =404;

fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_intercept_errors on;
fastcgi_pass php;
}

Share this:

  • Facebook
  • Google
  • Twitter
  • Print
  • Email
Posted in: Fedora, Linux, nginx, PHP, wordpress / Tagged: Fedora install, nginx, wordpress

Comments are closed.

Post Navigation

← Previous Post
Next Post →

Categories

  • AJAX
  • Android
  • Apache
  • Canon Cameras
  • Cloud
  • CMS
  • Computer Mods
  • Conferences
  • Deals
  • debian
  • Fedora
  • Flash
  • Frameworks
  • git
  • Hardware
  • HTML
  • IDE
  • iPhone
  • iPhone App Review
  • jQuery
  • Linux
  • Mac OS X
  • MySQL
  • nginx
  • PHP
  • portfolio
  • Puppet
  • Ruby on Rails
  • Script Reviews
  • SELINUX
  • Software
  • Software Review
  • SQL Server
  • statistics
  • Tech
  • Tomcat
  • Uncategorized
  • VMWARE
  • VPS
  • Windows
  • wordpress
  • Zend Framework

Blogroll

  • DragonAl Flickr
  • Dropbox – Free 2GB Account
  • James' Blog
  • Javascript Compressor
  • PHP Builder Community
  • PHP-Princess.net
  • Rubular – Regular Expression Validator
  • The Scale-Out Blog
  • Tiny MCE

Tags

activation AJAX android antec Apache AWS awstats canon coda codeigniter debian enclosure external free G1 install vmware tools Internet Explorer iphone 5 jquery Linux mx-1 MySQL office 2007 OSX photoshop PHP plugin plugins portfolio redesigned website review rewrite script security SELinux ssh tinymce tutorial upgrade VMWARE vmware server wordpress wordpress mu XSS zend framework
© Copyright 2013 Albertech.net
Infinity Theme by DesignCoral / WordPress
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.