服务器环境为:CentOS6.5 64位
目标:搭建LNMP(Linux + Nginx + MySQL + PHP +SVN),其中svn是用来代替ftp,方便开发中调试同步代码
相关目录:所有软件都安装到/www/目录下,在www目录下新建web文件夹作为网站的根路径,www目录下新建wwwsvn作为svn的仓库地址。/www/software用来放nginx,mysql,php的安装包和源码。nginx运行分组和账户www:www
一,安装前的准备
yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel cmake
直接将所有待安装的依赖安装完。
然后下载nginx ,mysql, php的源代码:
nginx:http://nginx.org/en/download.html 下载1.8.0的稳定版:nginx-1.8.0.tar.gz
MySQL:http://dev.mysql.com/downloads/mysql/ ,下载Community Server版本的后缀为tar.gz的源码mysql-5.6.27.tar.gz:
php:http://php.net/downloads.php 下载php-5.6.14.tar.gz
将这三份tar.gz文件通过scp命令弄到服务器上/www/software目录下。
二,安装nginx
解压缩文件,然后进到nginx-1.8.0里,输入命令:
./configure --user=www --group=www --prefix=/www/nginx
然后make,make install就安装完毕了。
安装完后第一件事,创建www的用户和分组,否则会遇到http://blog.itblood.com/nginx-emerg-getpwnam-www-failed.html 的错误。
执行:
/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www
nginx命令在/www/nginx/sbin/下,拷贝到/etc/init.d/一份,接下来设置开机启动。
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
然后
cd /etc/rc.d/init.d/ 目录下新建nginx,内容如下:
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/www/nginx/sbin/nginx
nginx_config=/www/nginx/conf/nginx.conf
nginx_pid=/www/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /www/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
注意:如果nginx的安装路径不是在/www/nginx下,则适当修改就好。
chmod 775 /etc/rc.d/init.d/nginx #赋予执行权限
chkconfig nginx on #设置开机启动
/etc/rc.d/init.d/nginx restart
service nginx restart
至此nginx安装就ok了,但遗留两个问题:
1,是更改默认web根目录在/www/web的问题
2,是与php的整合,默认nginx是不认php得
对于1,nginx默认web根目录在 nginx安装路径下的html文件夹,我们把他改到/www/web目录下。
转自:http://www.myhack58.com/Article/sort099/sort0102/2016/71375.htm