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 <
//配置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

//最后在浏览器中输入 localhost/phpinfo.php 出现一个关于php相关信息的页面即成功

你可能感兴趣的:(CentOS_6,CentOS_7)