Moving Joomla, WordPress and other PHP/FastCGI apps to Nginx

Have you moved your site from Apache to Nginx and now your FastCGI (php-cgi/spawn-fcgi) processes die/hang/crash periodically and your users see “HTTP 502 Bad gateway” or “HTTP 504 Gateway timeout” instead of a website?

I have faced this problem and found a relatively simple and robust solution. Here’s how I did it on Ubuntu 9.10 (Karmic Koala) and 10.04 (Lucid Lynx) server edition.

Solution was to replace default FastCGI implementation with PHP-FPM (FastCGI Process Manager). PHP-FPM is not supported in PHP out of the box – so if you use PHP 5.2.*, you’ll need to apply a patch and recompile PHP, and if you’re using PHP 5.3.* (at least in 5.3.2 PHP-FPM is not yet in the core) – you’ll need to check out PHP-FPM from PHP SVN.

Let’s start with uninstalling default Ubuntu php packages:

sudo apt-get remove php5*

Now we need to install dependencies. Note, that Ubuntu comes with a new autoconf tool version, which is not compatible with PHP, that’s why for successful compilation you need to temporarily install autoconf2.13 package.

sudo apt-get install libcurl4-openssl-dev libmcrypt-dev libxml2-dev libpng-dev 
autoconf2.13 libevent-dev libltdl-dev

Download latest stable PHP 5.2.13, Suhosin patch, PHP-FPM patch

cd ~/tmp
wget http://pl2.php.net/get/php-5.2.13.tar.gz/from/pl.php.net/mirror
wget http://download.suhosin.org/suhosin-patch-5.2.13-0.9.7.patch.gz
wget http://php-fpm.org/downloads/php-5.2.13-fpm-0.5.13.diff.gz
tar xvzf php-5.2.13.tar.gz
gunzip suhosin-patch-5.2.13-0.9.7.patch.gz
gunzip php-5.2.13-fpm-0.5.13.diff.gz
cd php-5.2.13
patch -p 1 -i ../php-5.2.13-fpm-0.5.13.diff
patch -p 1 -i ../suhosin-patch-5.2.13-0.9.7.patch
./buildconf --force
./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --with-openssl 
--with-mysql --with-mysql-sock --with-gd --without-sqlite --disable-pdo
make
make test
sudo make install

Alternatively you can download latest stable PHP 5.3.2, Suhosin patch, apply PHP-FPM patch. Note, that not all PHP based projects and plugins work correctly with new PHP 5.3 – it is not backwards compatible with PHP 5.2. I had troubles at least with some Joomla plugins and ZenCart.

cd ~/tmp
http://fi.php.net/get/php-5.3.2.tar.gz/from/this/mirror
wget http://download.suhosin.org/suhosin-patch-5.3.2-0.9.9.1.patch.gz
tar xvzf php-5.3.2.tar.gz
gunzip suhosin-patch-5.3.2-0.9.9.1.patch.gz
cd php-5.3.2
patch -p 1 -i ../suhosin-patch-5.3.2-0.9.9.1.patch
svn co http://svn.php.net/repository/php/php-src/trunk/sapi/fpm sapi/fpm
./buildconf --force
./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --with-openssl 
--with-mysql --with-mysql-sock --with-gd --without-sqlite --disable-pdo --disable-reflection
make
make test
sudo make install

Uninstall autoconf2.13 after compilation.

sudo apt-get remove autoconf2.13

Change user and group of php-fpm processes to user and group of your choice (e.g. www-data and www-data) – lines 63 and 66

sudo vim /usr/local/etc/php-fpm.conf

Edit PHP settings

sudo vim /etc/php5/cgi/php.ini (in Ubuntu 9.xx)
sudo vim /etc/php5/apache2/php.ini (in Ubuntu 10.04)

Set:

max_execution_time = 30
memory_limit = 128M
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php.log
register_globals = Off

Now if you haven’t done so yet, install Nginx. Ubuntu 10.04 comes with the latest stable Nginx 0.7.65, so just do:

sudo apt-get install nginx

Now you can congifure your sites, e.g. for WordPress Nginx configuration can look like this:

server {
        listen   80;
        server_name  blog.mysite.com;

        access_log  /home/user/logs/blog.mysite.com/access.log;

        location / {
          root   /home/user/blog.mysite.com;
          index  index.php index.html index.htm;

          # this serves static files that exist without running other rewrite tests
          if (-f $request_filename) {
              expires 30d;
              break;
          }

          # this sends all non-existing file or directory requests to index.php
          if (!-e $request_filename) {
              rewrite ^(.+)$ /index.php?q=$1 last;
          }

        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
          include /etc/nginx/fastcgi_params;
          fastcgi_pass  127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param  SCRIPT_FILENAME  /home/user/blog.mysite.com/$fastcgi_script_name;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
          deny  all;
        }
}

Comments

25 responses to “Moving Joomla, WordPress and other PHP/FastCGI apps to Nginx”

  1. […] there’s Ubuntu nginx package available (which works perfectly when you’re running PHP apps using FCGI), if you want to take into use Phusion Passenger, you’ll need to recompile Nginx from […]

  2. mantap thanks atas sharingnya

  3. Is it possible to have multiple(virtual hosts) domains(joomla) on a vps with nginx(php5.2.13)+msql5?

    Joomla is a must. 🙂

    thanks

  4. Ivan do you have msn?

    my is dadAo023@nAet.hr

    ditch letter A from the msn above 😉

  5. […] though there’s Ubuntu nginx package available (which works perfectly when you’re running PHP apps using FCGI), if you want to take into use Phusion Passenger, you’ll need to recompile Nginx from […]

  6. […] still have to deal with PHP occasionally). I had PHP compiled from source on Ubuntu 10.04 as per earlier instructions. Quick check of phpinfo() indicated that while gd module was compiled in, it didn’t have JPEG […]

  7. nginx gzip, deflate, gzip_static, gzip_static always, gunzip – explained and proved to be working!…

    i you are interested in nginx, you might have reasons to do so. e.g. you are serving a lot of concurrent connections with static content and your apache webservers are drowning? you want to split static content from dynamic content such as php or asp g…

  8. cheap toms shoes,cheap toms,cheap toms shoe,discount toms shoes,discount toms,toms shoes,buy toms,toms shoes for sale,cheap toms shoes for sale,toms shoes outlet,toms shoes for sale,toms shoes,toms shoes outlet,toms shoes for sale,toms shoes cheap,to…

    Dormcat hasn’t either, and he’s gone through much more than me. The younger Hogan was racing his vehicle before losing control of it and hitting a tree. Car wheels. MARQUETTE Ishpeming resident Amber Rude was craving a cupcake and made a run from her…

  9. Hello,

    Exclusive promo quality music for DJs https://0daymusic.org
    MP3/FLAC, label, music videos. Fans giving you full access to exclusive electronic, rap, rock, trance, dance… music.

    0day team.

  10. Выигрывай реальные деньги в лучших казино! Топ слотов, акции, советы для победы! Присоединяйся
    Казино онлайн: фишки, стратегии, промокоды! Поднимись с нами! Реальные обзоры.
    https://t.me/s/official_1go_1go/620

  11. Выигрывай бабло в онлайн казино! Обзоры слотов, акции, советы для победы! Присоединяйся
    Казино онлайн: фишки, стратегии, промокоды! Заработай с нами! Реальные обзоры.
    https://t.me/Official_1win_1win/563

  12. Откройте для себя мир азарта в 7k casino! Ожидают увлекательные игры, выгодные бонусы а также возможность сорвать куш! Испытайте удачу уже сегодня!
    https://7k-off.online

  13. kceuaatqg

    Spribe Aviator is legal as long as it complies with the applicable regulations. The National Lottery Regulatory Commission (NLRC) and local officials manage gambling. Online betting is legal if the platform has a license. Players should only use licensed sites, such as the Aviator official website, to stay safe. You must be 18 or older to gamble legally. Players need to prove their age before adding money. Always there to help you, no matter the time zone. Royal x Casino has more than 50 online money-making casino games and extremely high jackpot prize pools, constantly rewarding users. Although Plinko is a game of chance, applying an effective betting strategy and skillful bankroll management can help improve your chances of winning. It is important to remember that there is always a risk of losing in gambling and should not be considered as a way to make money. Play Plinko Gambling responsibly and enjoy every moment of the game.
    https://dados.ifro.edu.br/user/mingnariref1979
    Update: resolved, but still disappointed about support after the initial experience(After absolutely draining my money. Now, when I requested to close my account their support refused to do it. This website is insanely shady, they only offered me self exclusion which I DO NOT want. I want to CLOSE my account and not be able to open it again. When I asked support that they gave me only information about self exclusion and not account closure. They said you can not close your account only self-exclude. I have screenshots too. This is absolutely insane, just stealing money and legal documents without the possibility to close your account and erase your data. Very shady business.) The hospital I support in rural Burundi sits atop a steep hill. The land – donated to our organisation Village Health Works – is a dignified setting for medical care. Still, I worry about the paths people have to travel to reach it. The road is rocky, full of turns. Since there are limited vehicles in the region, many patients climb, requiring heroic effort from the sick. The bravest trekkers are the mothers, moving their own weight up the dirt road with babies on their backs. Their determination inspires our staff to work night and day, often to the point of exhaustion.

  14. Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

  15. qbjmherag

    We tested the Top Cat Most Wanted slot machine in details and deemed it safe to spin. Make sure to sign up to a secure online casino which has a catalog of Blueprint Gaming slots. Here are some ways that you can effectively utilize these CAT mock test series and take your CAT preparation to the next level, as follows: Top Cat: Most Wanted doesn’t use the same symbols as its predecessor, as it’s decided to use the cats in Top Cat’s gang for another purpose. Therefore, the icons that act as the medium paying ones consist of a fishbone, a trash can, bags of cash and the game logo. The lower value symbols are the same as in the original being playing cards 10, J, Q, K and A. Based on a stake of £1 Hogs & Heifers Saloon is an All-American, Classic Outlaw Country and Southern Rock Dive Bar where the Bartenders interact with the crowd, sometimes via bullhorns, as they sling drinks, share laughs and generally throw the best damn party in Vegas!
    https://antreprenoriatstudenti-ne.ro/aviator-game-review-maximizing-roi-for-pakistani-players/
    Cognizant came to our campus and conducted the hiring process in 2-3 stages, Cognizant is known as one of the prominent and well known service based companies. Type “Slot Machine 2.0 Hackerrank solution Java” into the search box and press Enter. This is called “lexical scoping” and no, if else blocks are not methods, but like methods, an if else, switch, for loop, etc. all are treated with their own local variable resolution. As far as the other errors, it’s the same issue. So, for those, just set them to a dummy value, like ints to 0 and strings to “”. It’s okay to set them like that for now because they’ll be changed when the game starts. Programmers eager to study real-world solutions and go deeper into the complexities of the Slot Machine 2.0 Hackerrank challenge will also find a plethora of information in the GitHub repositories. You can improve your ability to solve problems and develop as a programmer by using the offered Java code and researching GitHub sources.

  16. kkdchklka

    You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page. There is an online version of Dragon Simulator 3D, which you can play for free at CrazyGames Anytime Black Jack online Another part of our priority is adding protection for children while using the internet. We encourage parents and guardians to observe, participate in, and or monitor and guide their online activity. DELTIN GOLD, GOA: Book online & pay an additional ₹500 and get Non-negotiable Playing Coupons worth 1000 1500 with each package. Start your quest by choosing your dragon’s name, color, and element affinity. Your dragon can utilize the powers of either nature, fire, ice, or air. Each affinity provides awesome moves and abilities. Once you have customized your epic beast, jump into this dragon game.
    https://newsteadqa.co.uk/2025/05/28/estimated-online-play-durations-for-aviator-in-canada-an-in-depth-analysis/
    TeenPatti Gold’s visual style is reminiscent of other mobile card games like Teen Patti Ishq – Online Poker, World Series of Poker – WSOP, and Pokerist: Texas Holdem Poker. Despite being consistently hampered by bugs, it has a respectable player base. com-sweetgame-teenpatti-64-61527211-780c38cf9f9a8dc716b895936d1879d5.apk Teen Patti is a popular card game in India. The aim of the game is to get the best three-card hand or be the last player left. You’ll find Teen Patti at a variety of online casinos. Dragon Tiger Slots – Up Down provides a refreshing twist on traditional card games with the addition of slot machine elements. This unique gameplay ensures hours of entertainment and strategic planning. Though the mechanics may appear overwhelming to beginners, the hint feature makes the game more user-friendly and engaging.

  17. vaszzefeo

    La aplicación de juego de lucky jet facilita el acceso al juego Lucky Jet desde cualquier lugar. Además, la versión móvil incluye las mismas funciones que la plataforma web, como el uso de bot y predictor 1win.os jugadores pueden acceder al juego Lucky Jet a través del navegador web de su ordenador sin necesidad de instalar la app. Juego de Lucky Jet 1win – Juega JetX Predictor Descargar Para descargar e instalar el APK de Lucky Jet Predictor para PC, primero tendrá que utilizar un emulador de Android. Siga los pasos a continuación para obtener el apk: Se trata de un juego de crash único que combina elementos de los juegos fliperama con la posibilidad de ganar a lo grande en poco tiempo. Este es uno de los muchos juegos de casino rápidos y populares que ofrece 1win games Lucky Jet, incluidos Aviator y JetX, y demuestra el compromiso de la empresa por crear una experiencia de juego única y emocionante.
    https://gerimar.net/2025/06/03/review-del-juego-balloon-de-smartsoft-para-jugadores-en-colombia/
    Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back Go back

  18. qduacqcdz

    For players on the go, Jetx Jeux Dargent also offers a secure mobile app for Android and iOS users. The app includes all the features of its desktop version, including real-time betting from anywhere in the world! Now you can place your bets on Jetx Jeux Dargent while you’re on the go without having to worry about security or convenience. SmartSoft Gaming, a business that specializes in cutting-edge online casino games, is the creator of JetX. Expanding upon the crash game genre, JetX was created with an arcade-style UI and futuristic atmosphere in mind, making it playable by a wider range of players. When JetX was first released in 2019, its fast-paced action, social elements, and the possibility of huge prizes drew in gamers. JetX is a crash game that revolves around betting on the flight of a virtual plane. Players place bets and watch as the plane ascends, with the multiplier increasing as it flies higher. The goal is to cash out before the plane crashes to secure the highest possible multiplier for your bet. The simplicity of a game and the human factor in decision-making make it a unique and engaging gambling experience.
    https://naciag.pl/review-of-football-x-by-smartsoft-real-time-win-optimization-in-online-casinos-for-indian-players/
    3 Patti Circle is an app that offers a combination of different card games, including Indian hit teen patti. You can also enjoy other well-known classics like poker and blackjack. Teen Patti Gold is an online mobile card game app that lets you play the popular Indian card game, Teen Patti. You can enjoy this traditional game with friends and players from all over the world. Play the popular card game for free Min. Withdrawal ₹500 – If you’re looking for a teen patti game that lets you play with others online, then Teen Patti Diamond: 3 Patti is a good option to consider. It’s straightforward and you can start playing right away after installing it. Just make sure you have a decent internet connection for a smooth gameplay experience. Max : ₹50L INR Max : ₹50L INR Yes, Teen Patti Gold is free to download and play. However, you can buy extra chips and in-game items through in-app purchases.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.