CentOS7.0下安装LNMP(CentOS7+Nginx1.10.1+MySQL5.6.31+PHP5.6.22)

准备工作 

  安装wget:yum install wget -y

  安装gcc及g++:yum install gcc gcc-c++ -y

  后续所有源代码都下载到/usr/local/src目录

安装nginx

  Nginx依赖pcre(重写rewrite)、zlib(网页gzip压缩)及openssl(加密传输)。

1、安装pcre

  wget http://pilotfiber.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz

  cd pcre-8.38

   ./configure --prefix=/usr/local/pcre

  make && make install

2、安装zlib

  wget http://zlib.net/zlib-1.2.11.tar.gz

  tar -xvzf zlib-1.2.11.tar.gz

   ./configure --prefix=/usr/local/zlib

  make && make install

3、安装openssl

  wget http://www.openssl.org/source/openssl-1.0.2h.tar.gz

  tar -xvzf openssl-1.0.2h.tar.gz

  cd openssl-1.0.2h

   ./config --prefix=/usr/local/openssl

  执行到上一步时候会提示“x86_64-whatever-linux2 you need perl 5”

  

wget http://www.cpan.org/src/5.0/perl-5.24.0.tar.gz
tar -xzf perl-5.24.0.tar.gz 
cd perl-5.24.0 
./Configure -des -Dprefix=$HOME/localperl 
make 
make test
make install

  

  make && make install

4、安装Nginx

 为了安全起见,创建一个nginx账号专门用于运行nginx,当然为了简便直接用root账号运行的话(不推荐),就不需要创建nginx账号及将nginx相关文件开放权限给nginx账号。

  groupadd nginx

  useradd -g nginx nginx -s /bin/false#该账号只用于运行nginx及相关软件,不能登录

  wget http://nginx.org/download/nginx-1.10.1.tar.gz​ #链接可能失效

  tar -xvzf nginx-1.10.1.tar.gz​

  cd nginx-1.10.1

  ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre=/usr/local/package/pcre-8.38 --with-zlib=/usr/local/package/zlib-1.2.11 --with-openssl=/usr/local/package/openssl-1.0.2h

  上一步可能报错 

the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.

  yum install php-gd 

  make && make install

5、配置nginx开机自启动

  方法一:在/etc/rc.d/rc.local文件最后增加一行脚本

/usr/local/nginx/sbin/nginx

  

  方法二:将Nginx加入服务,新增/etc/init.d/nginx脚本,内容请见nginx脚本,然后设置开机自启动:

  chmod +x /etc/init.d/nginx

  chkconfig nginx on #设置开启自启动后会自动将其加入服务

 

  启动nginx

  若Nginx已加入服务,则用service命令启动服务

service nginx start

  否则运行Nginx程序

/usr/local/nginx/sbin/nginx

  

  

  

posted @ 2018-04-03 16:45  hypnot  阅读(349)  评论(0编辑  收藏  举报