Installing nginx on Ubuntu 11.10 and earlier

To replace Apache with nginx (or you want to run them at the same time), follow these steps.

Please note that this is only for Ubuntu installations of versions 11.10 and below. If you have 12.04 or later, we recommend you install nginx with the package manager.

Log in as root in your VPS:

  1. Install nginx: apt-get install nginx
  2. Install all the basic dependencies for compiling applications in your server:

  3. Download the latest version of PHP source: wget http://us.php.net/distributions/php-5.4.10.tar.gz — this command will download that version of PHP into the current directory.

  4. Uncompress (or untar) the file: tar -xzvf php-5.4.10.tar.gz

  5. Enter the directory (cd php-5.4.10), then prepare the build:

    If you see an error like error cc: Internal error: Killed (program cc1), your VPS ran out of memory, you have to disable some existing services or upgrade your VPS.

  6. Compile PHP:

    make

    make install

  7. Your installation is complete but it helps to configure a few things before getting started so nginx plays nice with PHP:

  8. Since the PHP and nginx files aren’t in an standard location, update your PATH variable:

  9. Initialize PHP-FPM: /etc/init.d/php-fpm start

That’s it. Go to your website using nginx’s default port. To verify that everything is working, create a file with phpinfo() in it.

Related articles