centos redhat 配置 nginx 、php、php-fpm、mysql实践

By | 2011 年 8 月 22 日

centos

1、修改系统时区

#cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#reboot

/etc/localtime 是当前时区文件
/usr/share/zoneinfo/ 是全部时区文件位置。

2、修改时间

#date -s 2010-08-20

#date -s 19:40:52

#hwclock -w

当前时间写入bios,避免重启失效。

3、时间同步

#/usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1
#
#
#
#
4、下载nginx
#./configure --prefix=/usr/local/nginx --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-

http_stub_status_module

#
配置启动脚本
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: 234 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

保存为nginx;然后执行

chmod +x /etc/init.d/nginx

/sbin/chkconfig nginx on

/sbin/chkconfig –list nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off

完成之后,就可以使用以下命令了
service nginx start
service nginx stop
service nginx restart
service nginx reload
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload

5、安装mysql
#
#下载二进制包
#tar -zxvf 进行解压缩
#mv mysql-5.6.2-m5-linux2.6-x86_64 /usr/local/mysql
# cd /usr/local/mysql
#groupadd mysql
#useradd -g mysql mysql
#chown -R root /usr/local/mysql
# chgrp -R mysql /usr/local/mysql
# chown -R mysql /usr/local/mysql/data
生成mysql系统数据库
# /usr/local/mysql/scripts/mysql_install_db --user=mysql&
生成my.cnf文件
# cp support-files/my-medium.cnf /etc/my.cnf
设置mysql服务
#cp support-files/mysql.server /etc/init.d/mysql
#chmod +x /etc/init.d/mysql
#chkconfig mysql on
#chkconfig --list mysql
#service mysql start

6、安装php

# wget http://mirrors.sohu.com/php/php-5.2.17.tar.gz
#wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
#wget http://mirror.yongbok.net/nongnu/freetype/freetype-2.4.6.tar.gz
# tar -zxvf freetype-2.4.6.tar.gz
# cd freetype-2.4.6
#./configure
#make
#make install
#wget http://downloads.sourceforge.net/project/libpng/libpng15/1.5.4/libpng-1.5.4.tar.gz
#tar -zxvf libpng-1.5.4.tar.gz
#cd libpng-1.5.4
#./configure
#make
#make install
#wget http://www.ijg.org/files/jpegsrc.v8c.tar.gz
#tar -zxvf jpegsrc.v8c.tar.gz
#cd jpeg-8c/
#./configure
#make
#make install
#wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmcrypt%2Ffiles%2FLibmcrypt%2F2.5.8%

2F&ts=1314104860&use_mirror=cdnetworks-kr-1
#tar -zxvf libmcrypt-2.5.8.tar.gz
#cd libmcrypt-2.5.8
#./configure
#make
#make install

#wget http://downloads.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmcrypt%2Ffiles%

2F&ts=1314104707&use_mirror=cdnetworks-kr-1
#tar -zxvf mcrypt-2.6.8.tar.gz
#cd mcrypt-2.6.8
#./configure
#make
#make install

#wget http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmhash%2Ffiles%2Fmhash%2F0.9.9.9%

2F&ts=1314190360&use_mirror=nchc
#tar -zxvf mhash-0.9.9.9.tar.gz
#cd mhash-0.9.9.9
#./configure
#make
#make install

#tar -zxvf php-5.2.17.tar.gz
#gunzip php-5.2.17-fpm-0.5.14.diff.gz
#patch -d php-5.2.17 -p1 < php-5.2.17-fpm-0.5.14.diff #cd php-5.2.17 #./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline- optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd -- enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable -suhosin #make #make install #修改 /usr/local/php/etc/php-fpm.conf文件,去掉Nobody 附近的注释 #vi /usr/local/php/etc/php-fpm.conf Unix user of processes nobody

Unix group of processes
nobody

#新建启动脚本文件
#vi /etc/init.d/php

#! /bin/sh
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for
# higher quality random number generation.

php_fpm_BIN=/usr/local/php/bin/php-cgi
php_fpm_CONF=/usr/local/php/etc/php-fpm.conf
php_fpm_PID=/usr/local/php/logs/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 --fpm $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 "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 -TERM `cat $php_fpm_PID`

wait_for_pid removed $php_fpm_PID

if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;

quit)
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"
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"
;;

logrotate)

echo -n "Re-opening php-fpm log file "

if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi

kill -USR1 `cat $php_fpm_PID`

echo " done"
;;

*)
echo "Usage: $0 {start|stop|quit|restart|reload|logrotate}"
exit 1
;;

esac

#chmod +x php
#chkconfig /etc/init.d/php on
#service php start
#
#
#-----------------------------------------------------------------------------------------------------------------------------------------
#安装过程完成。
#测试html以及php
#编辑nginx配置文件
#vi /usr/local/ngin/conf/nginx.conf
gzip on;

server {
listen 80;
server_name 192.168.1.251 ;

#charset koi8-r;

#access_log logs/host.access.log main;

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

.......
location ~ .php$ {
root /web;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /web$fastcgi_script_name;
include fastcgi_params;
}
退出保存

#service nginx restart

发表回复

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据