Thursday, 8 November 2012
Installing Nginx in Linux Mint 12
1. Run “apt-get install mysql-server mysql-client” to install MySql server and client. And you will be asked to provide root password, at the end of this process.
2. run “apt-get install nginx” to install Nginx
3. run “/etc/init.d/nginx start” to start Nginx
4. Go to your browser and open http://localhost, then you will see “Welcome to nginx!” page. It means that nginx is running successfully.
5. Run “update-rc.d nginx defaults” to make nginx start at boot time.
6.
Run “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-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl” to install PHP. This command is an one line command.
7. Run “vi /etc/php5/cgi/php.ini” to edit php.ini file, then add the line “cgi.fix_pathinfo = 1”, right at the end of the file.
8. Since there is no standalone FastCGI daemon package for Linux Mint, therefore we can use the spawn-fcgi program from lighttpd. Then run “apt-get install lighttpd” to install lighttpd. And spawn-fcgi would be installed on “/usr/bin/spawn-fcgi”
9. At the end of step 8, you will see an error message saying that lighttpd couldn't start because port 80 is already in use. That's how it's supposed to be because nginx is already listening on port 80. Then run “update-rc.d -f lighttpd remove” to remove lighttpd from startup script.
10. Run “/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid” or place this command at the end of “/etc/rc.local” file to make the system execute the command automatically at boot time. Please note, this command is an one line command.
Note: Permanent the fastcgi by writing above command in /etc/rc.local file
find init.d script: ls -al /etc/init.d/*php*
look /usr/bin/php-fastcgi: ls -al /usr/bin/php-fastcgi
look /usr/bin/spawn-fcgi(if exist '/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -f /usr/bin/php5-cgi' to start, 'killall spawn-fcgi' to stop)
11. Run “vi /etc/nginx/nginx.conf” to configure nginx.
user www-data www-data;
worker_processes 5;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr $host $remote_user [$time_local] “$request” '
'$status $body_bytes_sent “$http_referer” “$http_user_agent” '
'“$request_time” “$gzip_ratio”';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
keepalive_timeout 65;
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_buffers 16 8k;
#gzip_proxied expired no-cache no-store private auth;
gzip_proxied any;
gzip_min_length 1000;
gzip_types text/plain text/html text/css application/json application/x-javascript
text/xml application/xml application/xml+rss text/javascript;
server {
listen 80;
client_max_body_size 50M;
server_name server.domain.com;
root /var/www;
index index.html index.php;
access_log /var/log/nginx/access.log main;
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/www;
}
location ~* ^.+.(jpg|jpeg|gif)$ {
root /var/www;
expires 30d;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}
}
}