Nginx1.3.1+Mysql5.5.25+Php5.3.13

Nginx Php Mysql

Nginx安装
nginx官网:http://www.nginx.org
依赖包: pcre-devel openssl-devel
# useradd -M -s /sbin/nologin nginx
编译安装:
# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --conf-path=/usr/local/nginx/conf/nginx.conf &&make &&make install
注:--conf-path=/etc/nginx.conf  配置文件/etc/nginx.conf
# ln -s /usr/local/nginx/sbin/nginx  /usr/local/sbin
注:软链接放便启动
nginx脚本
# vim /etc/init.d/nginx
增加
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
 
lockfile=/var/lock/subsys/nginx
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest || return $?
    stop
    start
}
 
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
 
force_reload() {
    restart
}
 
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
保存
# chmod +x /etc/init.d/nginx
# chkconfig nginx on
# service nginx start
 
Php安装
php官网: http://cn.php.net/
依赖包: libcurl-devel gd-devel libjpeg-devel libpng-devel zlib-devel libXpm-devel freetype-devel libxslt-devel gettext-devel bzip2-devel 
        注:请安装第三方源epel remi 安装  mysql-devel mcrypt libmcrypt-devel mhash
# yum --enablerepo=remi install mysql-devel mcrypt libmcrypt-devel mhash
32位epel源:http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm
64位epel源:http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
32位remi源:http://rpms.famillecollet.com/enterprise/6/remi/i386/remi-release-6-1.el6.remi.noarch.rpm
64位remi源:http://rpms.famillecollet.com/enterprise/6/remi/x86_64/remi-release-6-1.el6.remi.noarch.rpm
编译安装:
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-curl --with-pear --with-gd --with-jpeg-dir --with-png-dir --with-zlib --with-xpm-dir --with-freetype-dir --with-mysql --with-mysqli --with-pdo-mysql --with-openssl --with-xmlrpc --with-xsl --with-bz2 --with-gettext --enable-fpm --enable-exif --enable-wddx --enable-zip --enable-bcmath --enable-calendar --enable-ftp --enable-mbstring --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-shmop --enable-dba --enable-sysvsem --enable-sysvshm --enable-sysvmsg --with-mcrypt --with-mhash &&make &&make install
注:php安装目录
# cp php.ini-production /usr/local/php/etc/php.ini
# ln -s /usr/local/php/etc/php.ini /etc/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
# ln -s /usr/local/php/sbin/php-fpm  /usr/local/sbin
# ln -s /usr/local/php/bin/php /usr/local/bin
php-fpm脚本
# vim /etc/init.d/php-fpm
增加
#!/bin/sh
#chkconfig: - 85 15
#description: php-fpm is PHP FastCGI Process Manage.
#processname:php-fpm
 
### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO
 
prefix=/usr/local/php
exec_prefix=${prefix}
 
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
 
php_opts="--fpm-config $php_fpm_CONF"
 
wait_for_pid () {
 
    try=0
 
    while test $try -lt 35 ; do
 
        case "$1" in
            'created')
            if [ -f "$2" ] ; then
                try=''
                break
            fi
            ;;
 
            'removed')
            if [ ! -f "$2" ] ; then
                try=''
                break
            fi
            ;;
        esac
 
        echo -n .
        try=`expr $try + 1`
        sleep 1
 
  done
 
}
 
case "$1" in
    start)
        echo -n "Starting php-fpm "
 
        $php_fpm_BIN $php_opts
 
        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        fi
 
        wait_for_pid created $php_fpm_PID
 
        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;
 
    stop)
        echo -n "Gracefully shutting down php-fpm "
 
        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi
 
        kill -QUIT `cat $php_fpm_PID`
 
        wait_for_pid removed $php_fpm_PID
 
        if [ -n "$try" ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
    ;;
 
    force-quit)
        echo -n "Terminating php-fpm "
 
        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi
 
        kill -TERM `cat $php_fpm_PID`
 
        wait_for_pid removed $php_fpm_PID
 
        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;
 
    restart)
        $0 stop
        $0 start
    ;;
 
    reload)
 
        echo -n "Reload service php-fpm "
 
        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi
 
        kill -USR2 `cat $php_fpm_PID`
 
        echo " done"
    ;;
 
    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload}"
        exit 1
    ;;
 
esac
保存
# chmod +x /etc/init.d/php-fpm
# chkconfig php-fpm on
 
修改配置文件:/usr/local/php/etc/php-fpm.conf
# vim /usr/local/php/etc/php-fpm.conf
pid = run/php-fpm.pid
error_log = log/php-fpm.log
listen = 127.0.0.1:9000
listen.backlog = -1
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500
request_slowlog_timeout = 0
request_terminate_timeout = 0
rlimit_files = 1024
rlimit_core = 0
catch_workers_output = yes
 
Mysql安装
官网: http://dev.mysql.com/
依赖包: cmake ncurses-devel
增加用户: # useradd -M -s /sbin/nolgoin mysql
编译安装:
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DINSTALL_DATADIR=/var/lib/mysql  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_SSL=system  -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1  -DMYSQL_USER=mysql &&make &&make install
增加权限:
# chown -R mysql.mysql /usr/local/mysql
# mkdir /var/lib/mysql
# chown -R mysql.mysql /var/lib/mysql
复制配置文件(解压目录mysql-5.5.25)
# cp /mysql-5.5.25/support-files/my-medium.cnf /etc/my.cnf
生成启动脚本(解压目录mysql-5.5.25)
# cp /mysql-5.5.25/support-files/mysql.server /etc/init.d/mysqld
# vim /etc/init.d/mysqld
修改:
basedir= /usr/local/mysql
datadir= /var/lib/mysql
安装默认数据库(安装目录)
# cd /usr/local/mysql/
# ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/var/lib/mysql --user=mysql 
启动数据库
# chkconfig mysqld on
# service mysqld start
软链接
# ln -s /usr/local/mysql/bin/mysql /usr/local/bin
# ln -s /usr/local/mysql/bin/mysqladmin /usr/local/bin
数据库加密:
# mysqladmin -u root -p password 123.com
 
#########编译ZendGuardLoader扩展#####
地址: http://www.zend.com
#t ar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
# cp ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
# vi /usr/local/php/etc/php.ini
增加
[Zend Guard Loader]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ZendGuardLoader.so"

 
#########编译memcache-3.0.5扩展#####
地址: http://pecl.php.net/package-stats.php
# tar xvfz memcache-3.0.6.tgz
# cd memcache-3.0.6/
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make &&make install
########编译PHP加速扩展###############
地址: http://pecl.php.net/package-stats.php
# unzip eaccelerator-0.9.6.1.zip
# cd eaccelerator-0.9.6.1
# /usr/local/php/bin/phpize
# ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
# make &&make install
 
########设置PHP配置文件############
# sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\n#' /usr/local/php/etc/php.ini
# sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/php/etc/php.ini
# sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/php/etc/php.ini
# sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
# sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/etc/php.ini
# sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/php/etc/php.ini
# sed -i 's/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
# sed -i 's/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
# sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /usr/local/php/etc/php.ini
 
# cat >>/usr/local/php/etc/php.ini<<EOF
[eaccelerator]
extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
EOF
 
# mkdir /tmp/eaccelerator
# chmod 777 /tmp/eaccelerator
测试是否成功
查看php配置信息前十行
# /usr/local/php/bin/php -i |head -10
查看
# cd /tmp/eaccelerator
 
 
nginx+php整合
}
server {
        listen       80;
        server_name   www.webftp.hk; //*在windows里面做本地解析*//
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   /srv/WebFtp;     //*指定目录*//
            index  index.html index.htm index.php;   //*增加index.php*//
        }
 
        #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;
        }
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /srv/WebFtp;     //*指定目录*//
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;   //*修改成$document_root*//
            include        fastcgi_params;
        }
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny  all;
        }
    }
 

 

本文出自 “hacker1394” 博客,谢绝转载!

你可能感兴趣的:(Nginx+Msyql+Php)