Installing Nginx (LEMP) on Ubuntu 11.10
I’ve been using Apache for a number of years, and recently had to get Nginx working on Ubuntu for a client. There is a good number of tutorials out there, but none I could find apply to any of the more recent versions of Ubuntu.
We will assume you have a fresh, clean install of Ubuntu 11.10. Each of the commands below goes on it’s own line and press enter afterwards.
Firstly we need to logon to our server using SSH.
Not lets install the MySQL server.
apt-get install mysql-server mysql-client
Now lets install all that wonderful PHP.
apt-get install php5-cgi php5-cli php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-pspell php5-recode php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-gd
Now as the server we’ll install Nginx.
apt-get install nginx
We need to edit some of the options, we’ll create the following file first to help with our configuration.
nano /etc/init.d/php-fastcgi
Now populate it with the following:
#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS=”- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND”
RETVAL=0start() {
echo -n “Starting PHP FastCGI: ”
start-stop-daemon –quiet –start –background –chuid “$USER” –exec /usr/bin/env — $PHP_CGI_ARGS
RETVAL=$?
echo “$PHP_CGI_NAME.”
}
stop() {
echo -n “Stopping PHP FastCGI: ”
killall -q -w -u $USER $PHP_CGI
RETVAL=$?
echo “$PHP_CGI_NAME.”
}case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo “Usage: php-fastcgi {start|stop|restart}”
exit 1
;;
esac
exit $RETVAL
Now lets make sure that Nginx is ready to run that nice PHP.
Open up the default Nginx site.
nano /etc/nginx/sites-enabled/default
Find the line that reads:
index index.html index.htm;
And make it look like:
index index.php index.html index.htm;
Make sure the following lines ARE NOT commented out:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
Now somewhere at the top within the server{ } section, put the following, but feel free to change the maximum upload size to something of your choosing.
client_max_body_size 20M;
Now lets make sure PHP is ok with files that big.
nano /etc/php5/cli/php.ini
And update the following line to:
upload_max_filesize = 20M
Now the same for the other ini file.
nano /etc/php5/cgi/php.ini
upload_max_filesize = 20M
Now lets make our FastCGI executable:
chmod +x /etc/init.d/php-fastcgi
Give FastCGI a gentle kick:
/etc/init.d/php-fastcgi start
Now lets make sure it starts when/if the server reboots:
update-rc.d php-fastcgi defaults
And finally lets start up Nginx:
/etc/init.d/nginx start
All done, you can now upload your site to /usr/share/nginx/www which is the default path for Nginx on Ubuntu.
3 Comments
[…] happy too. We’ll assume you’re using Ubuntu 11.10 for this How To and running a LEMP server, although tailoring for Apache should be easy enough too using this […]
[…] will assume you already have a working LEMP server […]
[…] after my last tutorial about getting a LEMP server on Ubuntu 11.10 I’m very happy to announce that the process is now a heck of a lot easier on 14.04! As a matter […]