Linux下搭建nginx+php7

//系统
# cat /etc/redhat-release 
CentOS release 6.9 (Final)
# uname -r
2.6.32-696.el6.x86_64
//关闭SELinux,机器需要重启
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
//验证
# grep SELINUX=disabled /etc/selinux/config
SELINUX=disabled
//关闭SELinux,不需要重启
# setenforce 0
//iptables关闭(视情况而定)
# /etc/init.d/iptables stop
//应用版本
//nginx-1.14.0
//php-7.1.7
//安装依赖
# yum -y install wget gcc gcc-c++ cmake pcre* curl*
# yum -y install libtool* zlib* openssl* libxml2* libcurl* libjpeg* libpng libpng-devel freetype freetype-devel libxslt*
//安装Nginx
# tar zxvf nginx-1.14.0.tar.gz
# cd nginx-1.14.0
# ./configure --prefix=/usr/local/nginx-1.14
# make && make install
# ln -s /usr/local/nginx-1.14 /usr/local/nginx
# cat /usr/local/nginx/conf/nginx.conf //在最后一行添加(最后一个 } 之前)
include vhost/*.conf;
# mkdir /usr/local/nginx/conf/vhost && cd /usr/local/nginx/conf/vhost
# cat /usr/local/nginx/conf/vhost/nginx.conf //创建nginx.conf文件,内容如下
server {
    listen 80;	//使用的端口视情况而定
    server_name localhost;

    root   html;
    index index.html index.php;

    error_log logs/tianhuabms_error.log;

    location / {
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO /usr/local/nginx/conf/$fastcgi_path_info;
            fastcgi_pass   127.0.0.1:9000;
            include fastcgi_params;
        }

    }
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

}
# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# /usr/local/nginx/sbin/nginx //启动nginx
# ps aux|grep nginx
root       5148  0.0  0.0  19988   692 ?        Ss   19:41   0:00 nginx: master process /usr/local/nginx/
sbin/nginxnobody     5149  0.0  0.1  20460  1292 ?        S    19:41   0:00 nginx: worker process      
root       5151  0.0  0.0 103336   900 pts/1    S+   19:41   0:00 grep nginx
//Nginx的其它命令(可能使用到)
# /usr/local/nginx/sbin/nginx -s stop   //停止nginx
# /usr/locat/nginx/sbin/nginx -s reload //重新加载配置文件
//编译php
# useradd www -s /sbin/nologin -M
# tar zxvf php-7.1.7.tar.gz
# cd php-7.1.7
//在编译前增加 /usr/local/lib 以避免一些错误
# echo "/usr/local/lib" >> /etc/ld.so.conf && ldconfig -v
//如果./configure时遇到错误,解决错误后clean
# make clean //解决错误后clean,重新./configure

# ./configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli \
--with-pdo-mysql \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--disable-fileinfo \
--enable-maintainer-zts
# make
# make test
# make install
//编译php ./configure时遇到错误
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
//解决
# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz 
# tar zxvf libmcrypt-2.5.7.tar.gz && cd libmcrypt-2.5.7
# ./configure && make && make install

//编译php ./configure时遇到错误
configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
//解决./configure时添加以下项
--enable-opcache=no

//编译php ./configure时遇到错误
configure: error: off_t undefined; check your library configuration
//解决
# cat >> /etc/ld.so.conf <<eof
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
eof
# ldconfig -v

//启动php-fpm时出现错误
Starting php-fpm [02-Aug-2018 14:53:24] ERROR: [pool www] cannot get uid for user 'www'
[02-Aug-2018 14:53:24] ERROR: FPM initialization failed
 failed
//解决,造成的原因是编译php时指定的用户和属组
# useradd www -s /sbin/nologin -M

//make时遇到错误 make: *** [sapi/cli/php] Error 1
//解决方法
//使用以下命令替换make
# make ZEND_EXTRA_LIBS='-liconv' 
//或者
# vim Makefile
//找到97行的位置在末尾-lcrypt后添加: -liconv
//配置php
# cp php.ini-production /usr/local/php7/etc/php.ini
# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
//启动php命令
# /etc/init.d/php-fpm start
//测试
# cat /usr/local/nginx/html/phpinfo.php
<?php
phpinfo();
?>
//最后在浏览器中输入 localhost/phpinfo.php 出现一个关于php相关信息的页面即成功
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值