Nginx – Need working guide to install latest Apache or Nginx, PHP & MySQL for production

apache-2.2lampMySQLnginxPHP

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?

Best Answer

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]