Howsto: Step-by-step Installing Nginx work with DLE 9.3

Status
Not open for further replies.

thanhlangso

Active Member
139
2009
9
5
Installing Nginx With PHP5 (Use spawn-fcgi program as FastCGI Daemon) And MySQL Support On Debian Squeeze

In this tutorial, I will do step-by-step guide you can manually install a web server using nginx with php5 and mysql server and to configure nginx to run a website using DLE. This article is suitable for what you are using linux vps with debian 6.0 system (Squeeze) and want to run your website using DLE script.

Nginx (pronounced "engine x") is a free, open-source, high-performance HTTP server. Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption. This tutorial shows how you can install Nginx on a Debian Squeeze server with PHP5 support (through FastCGI) and MySQL support.

Step 1:
Installing MySQL 5

To install MySQL, we run:

Code:
[FONT=Times New Roman][SIZE=4] #apt-get install mysql-server mysql-client[/SIZE][/FONT]

You will be asked to provide a password for the MySQL root user and enter your password.

Step 2:
Installing PHP5

We can make PHP5 work in nginx through FastCGI. Fortunately, Debian Squeeze provides a FastCGI-enabled PHP5 package which we install like this (together with some PHP5 modules like php5-mysql which you need if you want to use MySQL from your PHP scripts):

Code:
[FONT=Times New Roman][SIZE=4] #apt-get install php5-cgi php5-mysql[/SIZE][/FONT]

And you can install add more packet support for php5

Code:
#apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Installing APC

APC is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It's similar to other PHP opcode cachers, such as eAccelerator and XCache. It is strongly recommended to have one of these installed to speed up your PHP page.
APC can be installed as follows:

Code:
#apt-get install php-apc
Then open /etc/php5/cgi/php.ini and uncomment the line cgi.fix_pathinfo=1:

Code:
#vi /etc/php5/cgi/php.ini

Code:
[FONT=Times New Roman][SIZE=4]
  ; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
  ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
  ; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
  ; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
  ; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
  ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
  ; http://php.net/cgi.fix-pathinfo
  cgi.fix_pathinfo=1
  [...]
[/SIZE][/FONT]

Step 3: [FONT=&quot]Installing Nginx (Web Server)

[/FONT][FONT=&quot]Nginx is available as a package for Debian Squeeze which we can install as follows:
Code:
#apt-get install nginx
[/FONT][FONT=&quot]
Start nginx afterwards:

Code:
#/etc/init.d/nginx start
[/FONT][FONT=&quot]
The default nginx document root is /var/www which does not exist yet; therefore we must create it as follows:

Code:
#mkdir /var/www
#chown www-data:www-data /var/www
[/FONT][FONT=&quot]
Type in your web server's IP address or hostname into a browser (e.g. http://192.168.1.10), and you should see the following page:

a5082d9bf8.jpg

Step 4:
[/FONT] Install spawn-fcgi and make Spawning a FastCGI Process

Code:
#apt-get install spawn-fcgi
Unlike Apache or Lighttpd, Nginx does not automatically spawn FCGI processes. You must start them separately. In fact, FCGI is a lot like proxying. There's a few ways to start FCGI programs, but luckily PHP5 will auto-spawn as many as you set in the PHP_FCGI_CHILDREN environment variable. First, install the php5-cgi library. Then, we can simply run php-cgi -b 127.0.0.1:9000 manually, or create an init script like this:
Code:
#vi /etc/init.d/php-fastcgi
Code:
#!/bin/bashBIND=127.0.0.1:9000USER=www-dataPHP_FCGI_CHILDREN=15PHP_FCGI_MAX_REQUESTS=1000 PHP_CGI=/usr/bin/php-cgiPHP_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=0 start() {      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  ;;esacexit $RETVAL
Or You can view this code here:
Code:
http://pastebin.com/mDK9J2en

Save this to /etc/init.d/ (or wherever your init scripts are) as php-fcgi. Install the usual way (e.g. for Debian/Ubuntu: update-rc.d php-fcgi defaults) and start it.
Code:
#chmod +x /etc/init.d/php-fastcgi
#update-rc.d php-fastcgi defaults
# /etc/init.d/php-fastcgi start
Step 5:
Configuring nginx working with DLE (Important Step)

The nginx configuration is in /etc/nginx/nginx.conf which we open now:
Code:
[FONT=Times New Roman] #vi /etc/nginx/nginx.conf[/FONT]

The configuration is easy to understand (you can learn more about it here: http://wiki.codemongers.com/NginxFullExample and here: http://wiki.codemongers.com/NginxFullExample2)
First (this is optional) increase the number of worker processes and set the keepalive_timeout to a reasonable value:
Code:
[...]worker_processes  5;[...]    
keepalive_timeout   2;[...]
The virtual hosts are defined in server {} containers. The default vhost is defined in the file /etc/nginx/sites-available/default - let's modify it as follows:
Code:
[FONT=Times New Roman] #vi /etc/nginx/sites-available/default[/FONT]

To view this code click this link:
Code:
http://pastebin.com/8zY5P3C1

Now save the file and restart nginx:
Code:
#/etc/init.d/nginx restart

I am currently selling cheap vps installed operating system debian to install webserver Nginx
.
if you need can contact me through yahoo. My Y!M id: thanhtoday
 
5 comments
Status
Not open for further replies.
Back
Top