Archive | February, 2010

Sharks Ahoy!

News from Dubai. A huge aquarium in Dubai Mall got cracked and started leaking. Best part: it was a shark filled aquarium! People were evacuated from the section of the mall with the aquarium, I guess the sharks were hungry and humans were not exactly on the menu. Here’s a video of the leak:

This isn’t the first problem Dubai has had with their attractions. Recently the elevator at Burj Khalifa (aka Burj Dubai) had a problem.



Both Dubai Mall and Burj Khalifa were developed by the same developer Emaar Properties. I wouldn’t be surprised that more of these occurrences come about in the future. Some speculate that low wages and abuse by contractors towards employees have resulted in poor quality (aka revenge) of some developments.

Dubai is a great city, I still remember the first time I went there when things started booming. I’d hate to see its image ruined. I guess only time will tell…

0 Comments

How to Install nginx, MySQL and PHP on Fedora

As promised in my first post, here is a hopefully simple guide to get your site up and running with nginx. This will involve using FastCGI for the PHP part and a configuration to get a single site running (no virtual hosts). You will need some knowledge of working on Linux through a command line. Shell commands and configuration will be bolded for easier reading.

Ok, lets start…

1. Login as root on your server.

2. Install MySQL and related stuff:

[root@server]$ yum install mysql mysql-server

3. Install the nginx server:

[root@server]$ yum install nginx

4. Install PHP and related packages:

[root@server]$ yum install php php-mysql

5. We are going to be using Lighttpd’s spawn-fcgi to get bridge nginx with PHP. You can download spawn-fcgi separately and we do not need to install Lighttpd in the process. You may download it from here. Follow the steps below to download and install (remember to replace the link after wget with the correct link you get from the spawn-fcgi site since it might be a different version!):

[root@server]$ wget http://spawnfcgifile.tar.gz

[root@server]$ tar –xvzf spawnfcgifile.tar.gz

[root@server]$ cd spawnfcgifolder

[root@server]$ ./configure

[root@server]$ make

[root@server]$ cp src/spawn-fcgi /usr/bin/spawn-fcgi

Note: we did not follow the instruction as shown in the spawn-fcgi readme, we skipped the last step which is usually “make install”. Instead we copied the only file we really need for this tutorial.

6. Alright we are now done installing stuff we need to continue. The next part of this tutorial is configuring everything to work together.

7. Let’s start by starting and securing MySQL:

[root@server]$ service mysqld start

[root@server]$ mysqladmin –u root password ‘newpassword’ (include the single quotes)

[root@server]$ mysql –u root –p (enter your just modified root password to login to MySQL)

The prompt now changes to “>mysql”, enter these commands to remove the test database and anonymous users:

mysql> DROP DATABASE test;

mysql> DELETE FROM mysql.user WHERE user=’’;

mysql> FLUSH PRIVILEGES;

mysql> exit; (now we are back to the regular shell)

8. Edit php.ini and look for “cgi.fix_pathinfo =1”. This line will probably be commented, so remove the “#” to uncomment it or insert the line if it wasn’t there. Save the file and exit the editor.

9. Now its time to configure nginx. Edit the file /etc/nginx/nginx.conf. The important parts are below:

location / {

root   /usr/share/nginx/html;

index  index.php index.html index.htm; #We added index.php to this line.

The next part we need to edit is a bit further down, this part is commented, so uncomment by removing the “#”s:

location ~ \.php$ {

root           /usr/share/nginx/html; #Edit this to the same path we set above.

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;#Also path above

include        fastcgi_params;

}

10. Save nginx.conf, remember to make sure files are owned by user “nginx” in the document root. You may change this user inside nginx.conf at the top where it says “user”. Otherwise you will get a forbidden message due to permissions.

11. We did not install spawn-fcgi through yum or rpm, so we do not have a convenient start/stop/restart script. Create a file in /etc/init.d called phpfcgi. This init.d script is completely based on this one:

#!/bin/sh
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
spawnfcgi=”/usr/bin/spawn-fcgi” #Path to the spawn-fcgi binary.
php_cgi=”/usr/bin/php-cgi” #Patch to php-cgi.
prog=$(basename $php_cgi)
server_ip=127.0.0.1
server_port=9000
server_user=nginx #User to run as.
server_group=nginx #Group to run as.
server_childs=1 #Number of processes to start.
pidfile=”/var/run/php_cgi.pid”
# do not edit, put changes in /etc/sysconfig/phpfastcgi
[ -f /etc/sysconfig/phpfastcgi ] && . /etc/sysconfig/phpfastcgi
start() {

[ -x $php_cgi ] || exit 1
[ -x $spawnfcgi ] || exit 2
echo -n $”Starting $prog: “
daemon $spawnfcgi -a ${server_ip} -p ${server_port} -u ${server_user} -g ${server_group} -P ${pidfile} –C

${server_childs} -f ${php_cgi}

retval=$?
echo
return $retval

}

stop() {

echo -n $”Stopping $prog: “
killproc -p ${pidfile} $prog –QUIT
retval=$?
echo
[ -f ${pidfile} ] && /bin/rm -f ${pidfile}
return $retval

}

restart(){

stop
sleep 2
start

}

rh_status(){

status -p ${pidfile} $prog

}

case “$1″ in

start)
start;;

stop)
stop;;

restart)
restart;;

status)
rh_status;;

*)

echo $”Usage: $0 {start|stop|restart|status}”
exit 3
esac

12. Exit the editor, then issue the following to make it executable: chmod +x phpfcgi

13. Now lets startup everything we have installed and configured.

[root@server]$ service mysqld start (note: you may have already started this in the MySQL config part)

[root@server]$ service nginx start

[root@server]$ service phpfcgi start

14. Assuming everything went ok above (you get [OK] for each as you issue start), you would like all of this to start automatically on reboot:

[root@server]$ chkconfig mysqld

[root@server]$ chkconfig nginx

[root@server]$ chkconfig phpfcgi

15. Place some test php files in your document root and check if it is working. The phpinfo is a good test. It is simply:

<?phpphpinfo();?>

16. Create a file in /etc/sysconfig/ called phpfastcgi. We will enter an important fcgi directive, every certain number of requests the phpfcgi processes will restart and server another batch of requests and so on. Without this I noticed that nginx stopped serving PHP files and there were no php-cgi processes running. So enter the following and save the file (our init.d script calls this file if you haven’t noticed):

export PHP_FCGI_MAX_REQUESTS=1000

17. That’s it! If something seems broken try to backtrack what you did. I think I have covered everything that got my setup running. If you run into trouble and need some help post a comment below.

1 Comment

First Post… Powered by nginx!

After several days of having this blog run on several different web servers (from Apache, Lighttpd aka Lighty and now nginx) except Microsoft’s IIS (I personally prefer free, open source alternatives, especially for running services) I finally have got nginx setup perfectly!

To those that are not familiar with nginx: it is pronounced “engine x” but I tend to pronounce it as “en-jinx”. It is a high performance web server that also comes with some proxying services (not only web, mail too!). It was developed by Igor Sysoev (a Russian programmer) to handle the heavy traffic of some Russian sites. It now powers other sites, notable ones being WordPress (I’m guessing the .com blogs hosting platform) and Hulu amongst others.

It took me days to setup simply because every single time I was repeating the same silly mistake which I didn’t bother to search (install times were right before bed time!). So this blog kept going down and up (down when I tried nginx and up when I restored to a state with Apache running). I finally got it running a while ago, but this time with a mostly yum based installation *cowers*… Well the problem I was having was mostly an OS problem… You see, I… I had my files as username abc but the nginx was running as user cba… Technically I had a successful install every single time, but messed up in basic configuration!

Performance wise the difference is clear between a basic tweaked Apache setup and nginx. I had Apache with around 100Mb of total system RAM on startup, quickly growing to between 150-180Mb when I started moving around WordPress’ admin section. Now with nginx I am running with total memory usage at 108Mb max (so far), with the CGI’s process eating the most RAM! Quite a difference.

I’m hoping to get nginx running successfully once again but with another CGI module instead (got my eyes on php-fpm). I’ll probably get a tutorial posted here with both the easy *cough*yum*cough* and install from source method.

Unfortunately my mind isn’t powered by nginx yet, better sleep before my mind is replaced with a BSOD!

0 Comments
Performance Optimization WordPress Plugins by W3 EDGE