LEMP
Sources of below LEMP stack install steps are this, this and that. Most importantly is this forum thread and the geeks that jumped in to help me out.
Follow solely anyone of them didn’t get me to where I want so below is a blend of the three.
Note: -> indicates continuation into next line, if you are copying codes from below replace that with a space between text.
Install mysql first
apt-get install mysql-server mysql-client
-> libmysqlclient15-dev
Install PHP5
apt-get install php5-common php5-cgi php5-mysql php5-cli
Install Lighttpd just to get fastcgi
apt-get install lighttpd
Remove Lighttpd from startup script so it won’t start at boot up
update-rc.d -f lighttpd remove
Now we’ll create a script to launch the FastCGI process
and have it listen on 127.0.0.1 port 9000 (or other port at your choice)
nano /usr/bin/php5-fastcgi and paste below codes in 2 lines
#!/bin/sh
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g
-> www-data -C 2 -f /usr/bin/php5-cgi
Make it executable
chmod +x /usr/bin/php5-fastcgi
Symlink it to php-fastcgi
ln -s /usr/bin/php5-fastcgi /usr/bin/php-fastcgi
Now we create a startup script at /etc/init.d folder
nano /etc/init.d/fastcgi
paste below codes
#!/bin/bash
PHP_SCRIPT=/usr/bin/php-fastcgi
RETVAL=0
case "$1" in
start)
echo "Starting fastcgi"
$PHP_SCRIPT
RETVAL=$?
;;
stop)
echo "Stopping fastcgi"
killall -9 php5-cgi
RETVAL=$?
;;
restart)
echo "Restarting fastcgi"
killall -9 php5-cgi
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage:
-> php-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
Grant permission to the file
chmod 755 /etc/init.d/fastcgi
start fastcgi
/etc/init.d/fastcgi start
If you are lucky you’ll see child spawn successfully: PID: ????
make fastcgi to start on boot up
update-rc.d fastcgi defaults
Install nginx
apt-get install nginx
I got version 0.5.33-1 from Ubuntu 8.04.1 default repository
To enable php with nginx we need to edit the nginx configuration file to use fastcgi.
nano /etc/nginx/sites-available/default
This default file has many lines commented out by # the real meat is below lines to make it work.
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
location / {
root /var/www/nginx-default;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
-> /var/www/nginx-default$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
If you are lazy like me you could rename the default file and copy and paste above as your new default file. If you are editing the default file pay special attention to underlined parts above.
/var/www/nginx-default is where you put files to be served by nginx
To see if nginx is working you need to stop Lighttpd
/etc/init.d/lighttpd stop
On next boot Lighttpd shouldn’t start up, now restart nginx
/etc/init.d/nginx restart
Place a test.php file at the nginx default folder /var/www/nginx-default with echo phpinfo() to see if nginx is serving php5 for you. If you are unlucky you may have to stop and restarting nginx or even reboot your server. Generally you should see phpinfo listing and note the location of php.ini file in the table, in my case the file is located at /etc/php5/cgi/. This is important as you may have to tweak this file later on to suit your need.
Next would be installing blogware, e.g. Habari or WP, you’ll need subversion and phpmyadmin to manage mysql
apt-get install subversion
The above is proved alright in ubuntu 8.04
Now you can proceed to install your blogware


August 31, 2008 at 12:14 am
I’m glad to hear some of my instructions helped. Good luck with nginx.