I have seen some online guides about this but really was after one specific to Ubuntu 12.04. So here goes:
Step 1 – Installing Nginx
First we need to add the Nginx source
sudo add-apt-repository ppa:nginx/stable
Next, as we always do after adding a source, we need to update
sudo apt-get update
And now we install it
sudo apt-get install nginx
Next, we must start the Nginx service.
sudo /etc/init.d/nginx start
To check if it is successful, try going to http://localhost/ in your browser. If you see a Welcome to Nginx page, it has been successful.
Step 2 – Installing PHP5:
Install PHP and any required extensions
sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt php5-mysql
Edit the default Nginx site config (if you are not familiar with vim, try entering ‘nano’ instead)
sudo vim /etc/nginx/sites-available/default
The changes you will need to make are as follows:
1)
index index.html index.htm;
to
index index.html index.htm index.php;
2)
root /srv/http/nginx;
^this path may be different in your install, it doesn’t matter as we are changing it!
to:
root /var/www;
3) uncomment the following lines
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
Now quit vim (‘:wq’) and restart the nginx service.
sudo /etc/init.d/nginx restart
If the folder /var/www/ doesn’t exist, create it
sudo mkdir /var/www/
Step 3 – Install MySQL
And finally,
sudo apt-get install mysql-server
Step 4 – Check it works!
Create a test file
vim /var/www/test.php
Add this line
<?php phpinfo();?>
Save and quit vim (:wq) and go to http://localhost/test.php in your browser.
If you see a page displaying all your PHP settings, then it works!



Home



















May 17th, 2012 at 08:00
Thanks !
You saved my life ^^
July 4th, 2012 at 13:45
Small amendment, but for…
sudo add-apt-repository ppa:nginx/stable
…you need to have first installed python-software-properties.
sudo apt-get install python-software-properties
July 4th, 2012 at 13:55
I thought they came with Ubuntu, but I might be mistaken. Thanks for the tip though.
July 6th, 2012 at 00:44
Olá amigo.
Preciso de ajuda.
ja tentei de tudo segui as instruções á risca mas o nginx não instala.
dá a mensagem abaix:
Lendo lista de pacotes … Pronto
Construindo arvore de dependencias
Lendi a informação de estado …pronto
nginx ja é a versão mais nova.
0 pacotes instalados, 0 pacotes novos instalados, 0 a serem removidos e 31 não atualizados,,,,, dai dá uma serie de erros e o erro abaixo
ERROR: Module usblp does not exist in /proc/modules
Pode me ajudade nisso/
Valeu!
July 9th, 2012 at 10:35
Hey man,
Maybe you should put a little PHP code to make sure that the MySQL server works and will work with PHP. I’ve followed tons of guides like these over and over and MySQL has been a bitch.
July 20th, 2012 at 23:31
Thanx for the guideance. I spend about 30 minutes to figure out why ngnix does not accept my changes in ../sites-available/default.
I fact i did something i always do. I made a backup of the configfile and put it under /sites-available/default_bak. Unfortunatly I forgot that ngnix includes all files in that directory, which leads to strange results. After removing my backup configfile everything worked fine.