A book I’m reading: Nginx HTTP Server

So I’m all up in Nginx at the moment. It’s smooth as silk on pages and a low overhead. I wish it came in a  package friendly version like MAMP on a mac but heyyyy, the setup isn’t that difficult anyway.

However I have not delved into scalability and one of my customers will need it shortly so luckily I have the chance to review this little gem Nginx HTTP Server. Oddly enough the author is in China as well… as far as I’ve worked out.

It’s a good read so far, I’m trying to fit it in between website launches, designs british council, red travel and finding a new apartment. Needless to say I’m burning the candle at both ends….

Stay tuned…

–Ryan out.

W3C Core Styles

The W3C Core Styles offer authors an easy way to start using style sheets without becoming designers. By adding a link in the head of your documents, a CSS browser will fetch the style sheet of your choice from W3C’s server when it encounters your document. A non-CSS browser will display the HTML document like it always did.

Cool so post here. …and the styles here.

Actually… this is very cool…. “exploring ways to become a better thinker”

This wiki is a collaborative environment for exploring ways to become a better thinker. Topics that can be explored here include MemoryTechniques, MentalMath, CriticalThinking, BrainStorming, ShorthandSystems, NotebookSystems, and SmartDrugs. Other relevant topics are also welcome.

Visit: http://www.ludism.org/mentat …  Can’t wait for the book…

Ubuntu Server 10.04 LTS + Nginx + PHP + MySQL

Let’s install Nginx

Add the stable repo here for nginx – https://launchpad.net/~nginx/+archive/stable. Then “aptitude update”, then:

 sudo apt-get install nginx<br />

Start your server and test:

/etc/init.d/nginx start

Update your nginx configuration (see later section!) /etc/nginx/sites-available/default (make a backup of the old one):

<br />
server {<br />
    listen   80 default;<br />
    server_name  localhost;</p>
<p>    access_log  /var/log/nginx/localhost.access.log;</p>
<p>	## Default location<br />
    location / {<br />
        root   /var/www;<br />
        index  index.php index.htm index.html;<br />
    }<br />
	## Images and static content is treated different<br />
	    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {<br />
	      access_log        off;<br />
	      expires           30d;<br />
	      root /var/www;<br />
	    }</p>
<p>	## Parse all .php file in the /var/www directory<br />
	    location ~ .php$ {<br />
	        fastcgi_split_path_info ^(.+\.php)(.*)$;<br />
	        fastcgi_pass   backend;<br />
	        fastcgi_index  index.php;<br />
	        fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;<br />
	        include fastcgi_params;<br />
	        fastcgi_param  QUERY_STRING     $query_string;<br />
	        fastcgi_param  REQUEST_METHOD   $request_method;<br />
	        fastcgi_param  CONTENT_TYPE     $content_type;<br />
	        fastcgi_param  CONTENT_LENGTH   $content_length;<br />
	        fastcgi_intercept_errors        on;<br />
	        fastcgi_ignore_client_abort     off;<br />
	        fastcgi_connect_timeout 60;<br />
	        fastcgi_send_timeout 180;<br />
	        fastcgi_read_timeout 180;<br />
	        fastcgi_buffer_size 128k;<br />
	        fastcgi_buffers 4 256k;<br />
	        fastcgi_busy_buffers_size 256k;<br />
	        fastcgi_temp_file_write_size 256k;<br />
	    }</p>
<p>	## Disable viewing .htaccess &amp;amp;amp;amp;amp;amp; .htpassword<br />
	    location ~ /\.ht {<br />
	        deny  all;<br />
	    }<br />
	}<br />
	upstream backend {<br />
	        server 127.0.0.1:9000;<br />
}<br />

Visit the IP number in your web browser to make sure it’s installed ok “Welcome to nginx!“. Next, add to /etc/apt/sources.list:

 deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main<br />
deb-src http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main<br />

then run

<br />
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8D0DC64F<br />
sudo apt-get update<br />

Now let’s instal PHP, and the things you need. Here’s my stack:

<br />
sudo apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json php5-suhosin php5-common php-apc php5-dev<br />

A few of these are replaced by php5-common – this is ok and I should update the stack at some point but it’s automatic!

Now we grab the PHP FPM + CGI Module:

sudo apt-get install php5-fpm php5-cgi

Restart Nginx + Fast CGI

sudo /etc/init.d/nginx restart

and you should get something like this:

<br />
ryan@localhost:~# sudo /etc/init.d/nginx restart<br />
Restarting nginx: the configuration file /etc/nginx/nginx.conf syntax is ok<br />
configuration file /etc/nginx/nginx.conf test is successful<br />
nginx.<br />

Get CGI up:

/etc/init.d/php5-fpm start

Create an index.php in /var/www with and test your configuration. This was all working for me on Ubuntu Server amd64. Now it’s time to try and deploy an application to see how it can work :)

My nginx.conf file:

<br />
user www-data www-data;<br />
worker_processes  4;</p>
<p>error_log  /var/log/nginx/error.log;<br />
pid        /var/run/nginx.pid;</p>
<p>events {<br />
    worker_connections  1024;<br />
    # multi_accept on;<br />
}</p>
<p>http {<br />
    include       /etc/nginx/mime.types;<br />
    default_type  application/octet-stream;</p>
<p>    access_log  /var/log/nginx/access.log;</p>
<p>    sendfile        on;<br />
    #tcp_nopush     on;</p>
<p>    #keepalive_timeout  0;<br />
    keepalive_timeout  65;<br />
    tcp_nodelay        on;</p>
<p>    gzip  on;<br />
    gzip_disable &quot;MSIE [1-6]\.(?!.*SV1)&quot;;<br />
    gzip_comp_level 2;<br />
    gzip_proxied any;<br />
    gzip_types      text/plain text/html text/css application/x-javascript text/xml<br />
                    application/xml application/xml+rss text/javascript;</p>
<p>    include /etc/nginx/conf.d/*.conf;<br />
    include /etc/nginx/sites-enabled/*;<br />
}<br />
 

I installed memcache and APC (beta works with 10.04 lucid but you need libpcre installed ). Select the [no] defaults:

<br />
sudo pecl install memcache<br />
sudo apt-get install libpcre3-dev<br />
sudo pecl install apc-beta<br />

Didn’t need to modify any php.ini so far, but it is in 3 locations so I’ll see how this goes :-)

Useless command line options

Why not make it -rm and -i by default? The letters ‘e’and ‘r’are right next to each other, are they that thick…

root@obk-live:/var/www/vhosts/bc.crystal-dev.com/cake/console# crontab -r
root@obk-live:/var/www/vhosts/bc.crystal-dev.com/cake/console# crontab -e
no crontab for root - using an empty one
No modification made
root@obk-live:/var/www/vhosts/bc.crystal-dev.com/cake/console# crontab
^Croot@obk-live:/var/www/vhosts/bc.crystal-dev.com/cake/console# crontab --help
crontab: invalid option -- '-'
crontab: usage error: unrecognized option
usage: crontab [-u user] file
crontab [-u user] { -e | -l | -r }
(default operation is replace, per 1003.2)
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)
-i (prompt before deleting user's crontab)
root@obk-live:/var/www/vhosts/bc.crystal-dev.com/cake/console# useless fucking tool