LNMP开发环境搭建

210 阅读2分钟

安装前准备

lnmp环境搭建说明:

软件均安装在 /app/ 下,mysql数据文件 /data/mysql_db ,web目录 /data/web/。安装软件前预先执行以下命令,防止在软件安装过程中出现不必要的繁琐。

预安装命令

[root@localhost ~]# yum -y install gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel lua-devel gd-devel curl-devel pcre-devel zlib-devel libxml2-devel bzip2-devel libxpm-devel libXpm mbstring exif libicu-devel libmcrypt-devel php-mcrypt bzip2* libjpeg* libpng* freetype* ncurses ncurses-devel cmake*

编译安装Nginx

1.安装编译Nginx时需要的依赖包

[root@localhost ~]# yum -y install zlib* pcre* lua-devel

2.下载Nginx安装包

[root@localhost ~]# wget wx.58haha.cn/lnmp/nginx-…

3.创建Nginx组和用户,设置不允许登陆系统

[root@localhost ~]# groupadd www && useradd -g www www -s /sbin/nologin

4.解压Nginx包

[root@localhost ~]# tar zxvf nginx-1.6.2.tar.gz && cd nginx-1.6.2

5.执行./coonfigure对nginx进行配置以及检测当前环境是否满足安装需求

[root@localhost ~]# ./configure --prefix=/app/nginx
--sbin-path=/app/nginx/sbin/nginx
--conf-path=/app/nginx/conf/nginx.conf
--user=www
--group=www
--with-pcre
--with-file-aio
--with-poll_module
--with-http_ssl_module
--with-http_realip_module
--with-http_stub_status_module
--with-http_sub_module
--with-http_gzip_static_module
--with-http_dav_module
--with-http_flv_module
--with-http_mp4_module
--with-http_spdy_module
--with-http_sub_module
--with-http_dav_module
--without-http_uwsgi_module
--without-http_scgi_module
--http-log-path=/data/logs/nginx/access.log
--error-log-path=/data/logs/nginx/error.log
--http-client-body-temp-path=/tmp/nginx/client-body-temp
--http-proxy-temp-path=/tmp/nginx/proxy-temp
--http-fastcgi-temp-path=/tmp/nginx/fastcgi-temp

6.编译安装Nginx

[root@localhost ~]# make && make install

7.创建缓存目录

[root@localhost ~]# mkdir -p /tmp/nginx/client-body-temp

8.启动nginx

[root@localhost ~]# /app/nginx/sbin/nginx

9.浏览器访问web服务器ip 看是否启动成功。

10.为nginx提供开机启动脚本

[root@localhost ~]# vim /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: /app/nginx/logs/nginx.pid

#config: /app/nginx/conf/nginx.conf

nginxd=/app/nginx/sbin/nginx

nginx_config=/app/nginx/conf/nginx.conf

nginx_pid=/app/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 /app/nginx/logs/nginx.pid

}

reload() {

echo -n $"Reloading $prog: "

#kill -HUP `cat ${nginx_pid}`

killproc $nginxd -HUP

RETVAL=$?

echo

}

test() {

$nginxd -t

}

#See how we were called.

case "$1" in

test)

test

;;

start)

start

;;

stop)

stop

;;

reload)

reload

;;

restart)

stop

start

;;

status)

status $prog

RETVAL=$?

;;

*)

echo "Usage:prog {start|stop|restart|reload|status|help|test}"

exit 1

esac

exit $RETVAL

11.赋予Nginx执行权限,并设置为开机启动

[root@localhost ~]# chmod 755 /etc/rc.d/init.d/nginx

[root@localhost ~]# chkconfig nginx on

至此,Nginx配置结束!!