上一篇我们介绍了如何在 ubuntu 14.04 上面搭建 lnmp 环境,今天我们来介绍如何在 centos 7.0 上面搭建 lnmp 环境。
和 ubuntu 的更新策略不同,centos 更看重可靠性和稳定性,所以官方源更新的非常慢,里面自带的 php 版本很低,不符合生产部署的要求,所以我们选择源码编译的方式来安装 php。
如何在 centos 7.0 上面搭建 lnmp 环境
1. 创建 nginx 用户 和 nginx 用户组
$ sudo adduser -U nginx
$ sudo passwd nginx
2. 编译安装 nginx
下载 nginx 源码并解压
$ wget http://nginx.org/download/nginx-1.10.0.tar.gz
$ tar xzvf nginx-1.10.0.tar.gz
$ cd nginx-1.10.0
参考 nginx 官方打包使用的配置(所有参数应该全在一行)
$ ./configure
--prefix=/etc/nginx
--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.pid
--lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
--user=nginx
--group=nginx
--with-http_ssl_module
--with-http_realip_module
--with-http_addition_module
--with-http_sub_module
--with-http_dav_module
--with-http_flv_module
--with-http_mp4_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_random_index_module
--with-http_secure_link_module
--with-http_stub_status_module
--with-http_auth_request_module
--with-threads
--with-stream
--with-stream_ssl_module
--with-http_slice_module
--with-mail
--with-mail_ssl_module
--with-file-aio
--with-http_v2_module
--with-ipv6
make & make install
$ make
$ sudo make install
3. 编译安装 php
下载 php 源码并解压
$ wget http://cn2.php.net/distributions/php-7.0.6.tar.gz
$ tar xzvf php-7.0.6.tar.gz
$ cd php-7.0.6
配置参数
$ ./configure --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-openssl --with-curl --enable-mbstring --with-mcrypt --with-mysqli --with-pdo-mysql --enable-zip
make & make install
$ make
$ sudo make install
参考:
http://nginx.org/en/docs/configure.html
http://nginx.org/en/linux_packages.html
http://php.net/manual/zh/install.unix.nginx.php
767 total views