Ok I'm told the best and easiest way to install Apache/Nginx, PHP, MySQL for production these days is to pull in the software using apt-get or similar package manager for your specific distro. The advantage of this is you're using reliably built packages and you can easily update them in production.

Now I'm currently using Ubuntu 12.04 and keen for the latest versions of this software:

  • Apache 2.4.x or Nginx 1.2.x
  • PHP 5.4.x
  • MySQL 5.5.x

However every guide I've come across seems to have me install all this stuff but after I've done all the configuration it doesn't end up working and I have no idea what went wrong or how to fix it.

So far I've come up with:

1) Install dotdeb repositories using these instructions:

2) Install Apache 2.2.22, PHP 5.4.3, MySQL 5.5.24 with:

aptitude install mysql-server apache2 libapache2-mod-php5 php5-mysql php5-apc php5-curl

3) Install mod-rewrite package with:

a2enmod rewrite

Now that works and I can get a phpinfo() running and displaying properly and connecting to the database. However this only gets me Apache 2.2.22 (I would prefer 2.4.x for the latest speed increases) and also I can't get mod-rewrite working, it just refuses to redirect everything to index.php so only the homepage works.

I have the htaccess code set up as:

RewriteEngine on
RewriteBase /

# Forward any url without the listed extentions to index.php
RewriteRule !\.(js|css|ico|txt|gif|jpg|jpeg|png|ttf)$ index.php

I dunno, this is the 5th install of Ubuntu I've had to do now to try and get this working but still at square one and not getting anywhere.

Does anyone have a working guide or solution to install all these technologies together and make them interact nicely?

  • dotdeb for production? trying to keep everything at the very latest version sounds like a nightmare for a production server. What are you going to do when there are security patches? pray that dotdeb patches in a timely manner? what if they don't and all the offer is some future upgrade to php 5.5? are you going to migrate all your php code in order to get a minor security patch?
    – stew
    May 18 '12 at 20:33

The likelyhood of you being able to find repository packages for the very latest builds of the software is highly unlikely. The packages are proven installs that will work without issue and install with little effort. To get a higher version installed you will have to install from source. This can sometimes be a little hairy because the packages deal with all of the configurations and dependencies for you. If you already have the phpinfo() function working, copy the ./configure setting that shows on that page to help you when you have to build it. All that being said, once you have fought through it and get it working, the prospect of building an app from source will no longer intimidate you.

As far as your rewrite rules, try something like this

RewriteEngine on 

RewriteCond $1 !^(index\.php)
RewriteRule !^(.*)\.(js|css|ico|txt|gif|jpg|jpeg|png|ttf)$ index.php [L]
  • 1
    I'm actually surprised: What searching I did couldn't turn up a "latest and greatest" Apache PPA. I would of thought someone, somewhere would of setup one so people don't have to install from source
    – TheLQ
    May 20 '12 at 18:43

If your goal is a secure, stable production system you should not go for the "latest" version sometimes. And you should keep down maintenance tasks. So choosing the "right" distribution for your task is IMHO the way to go.

It is too troublesome to keep updated manually - and some distributions patch faster than a stable release is being released.

I watched this a while on CentOS for apache-httpd. If your want the security-patches even faster you have to take RedHat Enterprise (or any other distribution that provides fast and stable patches).


You can use this guide to install Apache 2.4 from source then use dotdeb for the latest versions of PHP, Nginx, and MySQL.

It would be much easier to just use Nginx with php5-fpm.

I wrote this guide about a year ago on setting up and configuring Nginx with Php-fpm and MySQL from dotdeb.

And another but older article on Nginx - Apache reverse proxy set up.

  • Nope your guide is no go. :( I think I got lost at page 5 trying to configure nginx. I want just a basic install as I'm not using Wordpress. I added some of the lines, but all I get is the browser trying to save index.php as a file. It doesn't even attempt to render the PHP just pops up the save as dialogue then I can read the code of the file which is basically just <?php phpinfo(); ?>. That's happened on a few of the other guides as well. Here's my default file config in /etc/nginx/sites-available if that helps.
    – zuallauz
    May 11 '12 at 10:38
  • You have 2 entries for fastcgi_pass remove this one fastcgi_pass php-fpm. Go to /etc/php5/fpm/pool.d/www.conf and change the listen directive to listen = /var/run/php5-fpm.sock. Restart: /etc/init.d/php5-fpm restart and you should be good to go.
    – Chris_O
    May 16 '12 at 9:36
  • Ok thanks I will give this a go and report back. Will have to reinstall everything again as I blew away the last install and tried another approach.
    – zuallauz
    May 16 '12 at 10:01

Even Canonical recommend that you wait until the first point release (e.g. 12.04.1) before rolling out to production boxes. Having said that, I'm just doing clean installs of 12.04 LTS on a server cluster that's been running 8.04 LTS for the last couple of years, so not everyone follows good advice!

If you're prepared to settle for Apache 2.2 and PHP 5.3, this is the quickest way on Ubuntu:

sudo tasksel install lamp-server
sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart

That'll install Apache 2.2, PHP 5.3, MySQL 5.5 and mod_rewrite with all dependencies and stock configuration.

If you really need Apache 2.4 and PHP 5.4, my advice would be to wait until they appear in a version of Ubuntu Server.

Edit: One of the packages you're using is APC. According to this thread:


it might be a bit tricky if you go with PHP 5.4.

  • You have a link backing up that claim about Canonical? I'm slightly skeptical considering the tone of their other recent statements regarding release cycles. Thanks.
    – Magellan
    May 20 '12 at 19:07
  • wiki.ubuntu.com/PrecisePangolin/ReleaseNotes/… I've paraphrased a bit. The advice is in regard to upgrading from 10.04 LTS to 12.04 LTS. Apparently a similar statement is also in the 12.04 LTS release notes.
    – jetboy
    May 21 '12 at 13:35
  • APC 3.1.10 (in beta) seems to work pretty well with PHP 5.4.5-dev which I have been testing today. Installation was relatively painless from source using this guide. If I can't get PHP to work stably I may resort to just using the lamp-server install option that you mention. I came across a good guide here which installs everything by source but it works pretty well.
    – zuallauz
    May 23 '12 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.