HowTo install nginx +PHP for Linux Slackware 13.X.X
Публикувана от admin на August 15 2012 13:13:50
cd /usr/src/
wget "http://sbopkg.googlecode.com/files/sbopkg-0.35.0-noarch-1_cng.tgz"
installpkg sbopkg-0.35.0-noarch-1_cng.tgz
sbopkg


Search nginx > network/nginx http/imap/pop3 proxy > Build Build a package for nginx

nano /etc/nginx/nginx.conf

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;
root /var/www/htdocs;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
# root html;
root /var/www/htdocs;
index index.php index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

location ~ \.php$ {
root /var/www/htdocs;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME script$fastcgi_script_name;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443;
# server_name localhost;

# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}



chmod +x /etc/rc.d/rc.nginx
/etc/rc.d/rc.nginx start

pico /etc/rc.d/rc.nginx


#!/bin/sh
#
# Nginx daemon control script.
# Written for Slackware Linux by Cherife Li .

BIN=/usr/sbin/nginx
CONF=/etc/nginx/nginx.conf
PID=/var/run/nginx.pid
nginx_start() {
# Sanity checks.
if [ ! -r $CONF ]; then # no config file, exit:
echo "$CONF does not appear to exist. Abort."
exit 1
fi

if [ -s $PID ]; then
echo "Nginx appears to already be running?"
exit 1
fi

echo "Starting Nginx server daemon..."
if [ -x $BIN ]; then
$BIN -c $CONF
fi
}

nginx_test_conf() {
echo "Checking configuration for correct syntax and"
echo "then trying to open files referenced in configuration..."
$BIN -t -c $CONF
}

nginx_term() {
echo "Shutdown Nginx quickly..."
kill -TERM $(cat $PID)
}

nginx_stop() {
echo "Shutdown Nginx gracefully..."
kill -QUIT $(cat $PID)
}

nginx_reload() {
echo "Reloading Nginx configuration..."
kill -HUP $(cat $PID)
}

nginx_upgrade() {
echo "Upgrading to the new Nginx binary."
echo "Make sure the Nginx binary has been replaced with new one"
echo "or Nginx server modules were added/removed."
kill -USR2 $(cat $PID)
sleep 3
kill -QUIT $(cat $PID.oldbin)
}

nginx_rotate() {
echo "Rotating Nginx logs..."
kill -USR1 $(cat $PID)
}

nginx_restart() {
nginx_stop
sleep 3
nginx_start
}

case "$1" in
check)
nginx_test_conf
;;
start)
nginx_start
;;
term)
nginx_term
;;
stop)
nginx_stop
;;
reload)
nginx_reload
;;
restart)
nginx_restart
;;
upgrade)
nginx_upgrade
;;
rotate)
nginx_rotate
;;
*)
echo "usage: `basename $0` {check|start|term|stop|reload|restart|upgrade|rotate}"
esac


cd /var/www/htdocs/
pico index.html




Welcome to Nginx





http://localhost/index.html


pico /etc/nginx/nginx.conf


location ~ \.php$ {
root /srv/httpd/htdocs;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME script$fastcgi_script_name;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}



bash-4.1# locate php | grep php-cgi
/usr/bin/php-cgi


cd /etc/rc.d/
pico rc.php-cgi


#!/bin/sh
#
# /etc/rc.d/rc.php-cgi
#
# Start/stop/restart
#
# To make php-cgi start automatically at boot, make this
# file executable: chmod +x /etc/rc.d/rc.php-cgi
#
#created by Imron Rosdiana
case "$1" in
'start')
echo "Starting php-cgi"
/usr/bin/php-cgi -b 127.0.0.1:9000 &
;;
'stop')
echo "Shutdown php-cgi"
killall php-cgi
;;
'restart')
echo "Shutdown php-cgi....."
killall php-cgi
sleep 3
echo "Starting php-cgi..."
/usr/bin/php-cgi -b 127.0.0.1:9000 &
;;
*)
echo "Usage: $0 {start|stop|restart}"
;;
esac


chmod +x /etc/rc.d/rc.php-cgi

/etc/rc.d/rc.php-cgi start

cd /var/www/htdocs/
pico info.php

Link

Example #1 phpinfo() Example

http://localhost/info.php


pico /etc/rc.d/rc.local

# Start Nginx Web server;
if [ -x /etc/rc.d/rc.nginx ]; then
. /etc/rc.d/rc.nginx start
fi

# Start php-cgi;
if [ -x /usr/bin/php-cgi ]; then
. /etc/rc.d/rc.php-cgi start
fi