所需下载的软件包:
nginx-0.7.67.tar.gz
mysql-5.1.45-linux-i686-glibc23.tar.gz
php-5.3.3.tar.bz2
libevent-1.4.14b-stable.tar.gz
libiconv-1.13.1.tar.gz
安装nginx
#yum install gcc openssl-devel pcre-devel zlib-devel ( yum安装开发环境)
# useradd -g -r nginx -s /bin/false -M nginx
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
#!/bin/sh
#/etc/init.d/nginx
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/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/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
sleep 1
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
#chkcong --add nginx
验证 nginx:
我更改了 nginx的位置,因为我觉得那个默认的地方很难找,^_^
#vim /etc/nginx/nginx.conf
location / {
root /web; #就这改了
index index.html index.htm;
}
#mkdir /web
#echo "A TEST PAGE" > /web/index.html
#service nginx start
#chkcong nginx on
访问http://192.168.100.10
#cp mysql-5.1.45-linux-i686-glibc23.tar.gz /usr/local/
#cd /usr/local
#tar zxvf mysql-5.1.45-linux-i686-glibc23.tar.gz
#ln -sv mysql mysql-5.1.45-linux-i686-glibc23
#groupadd -r mysql
#useradd -r -g mysql -s /bin/false -M mysql
#chown -R mysql.mysql . #权限更改
#scripts/mysql_install_db --user=mysql #初始化 mysql
#chown -R root . #权限更改
#chown -R mysql data #权限更改
添加mysql命令到系统环境变量中
vim /etc/profile
在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC 之前
添加一行:
PATH=$PATH:/usr/local/mysql/bin
保存退出
再重新执行一下该文件,不需要重新启动
# . /etc/profile
此时 mysql还能不能找到其库文件的位置,我们来添加库文件的指向
创建 /etc/ld.so.conf.d/mysql.conf文件
#touch /etc/ld.so.conf.d/mysql.conf
#echo “ /usr/local/mysql/lib” > /etc/ld.so.conf.d/mysql.conf
重新加载库文件
#ldconfig
此时 mysql还不能找到其头文件,我们来给它一个链接
#ln -sv /usr/local/mysql/include /usr/include/mysql
# cp support-files/my-large.cnf /etc/my.cnf
启动脚本加到 chkcong中管理:
#cp support-files/mysql.server /etc/init.d/mysqld
#chkcong --add mysqld
#service mysqld start
#chkcong mysqld on
# mysqladmin -uroot password ‘ 123’ (这个要不要即可,主要是mysql的管理员密码)
登录测试:
#mysql -uroot -p
如果能进入数据库则表示已经成功!
# cd jxvf php-5.3.3
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --with-libevent-dir=/usr/local --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-iconv-dir=/usr/local
# make ZEND_EXTRA_LIBS='-liconv' #使其识别 liconv
# make install
# cp php.ini-dist /usr/local/php/etc/php.ini #拷贝配置文件
拷贝配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
编辑配置文件
vim /php-fpm.conf
保证有如下行
error_log
pm.start_server
pm.max_requests
pm.max_spare_servers
pm.min_spare_servers
pm.max_children
#/usr/local/php/sbin/php-fpm &
#
加入开机启动:
echo “ /usr/local/php/sbin/php-fpm &” >> /etc/rc.local
编辑 nginx的fastcgi配置文件
#vim /etc/nginx/fastcgi.conf #保证为以下行
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
# cat fastcgi.conf > fastcgi_params
编辑 nginx配置文件
vim /etc/nginx/nginx.conf,启用如下选项:
location ~ \.php$ {
root /web;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
并在所支持的主页面格式中添加php格式的主页,类似如下:
location / {
root /web;
index index.php index.html index.htm;
}
而后重启nginx。
# service nginx restart
#rm -f /web/index.html
#cat >> /web/index.php <
?>
EOF
访问 http://192.168.100.10
#rm -f /web/index.php
#cat >> /web/index.php <
if($link)
echo "success";
else
echo "fail";
?>
EOF
访问 http://192.168.100.10