Linux下部署Nginx和PHP

系统:Centos 6.8 2.6.32-642.el6.x86_64
SELinux:关闭
iptables:打开tcp 80端口
安装依赖包(ps:yum源可以使用本地镜像,也可联网状态下直接yum安装)

# yum -y install libtool* zlib* openssl* wget gcc gcc-c++ cmake pcre* libxml2* curl* libcurl* libjpeg* libpng libpng-devel freetype freetype-devel libxslt*

编译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

Nginx版本1.11.3 && 编译安装

# wget http://nginx.org/download/nginx-1.11.3.tar.gz
# tar zxvf nginx-1.11.3.tar.gz && cd nginx-1.11.3
# ./configure --prefix=/usr/local/nginx
# make && make install
# ll /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
# /usr/local/nginx/sbin/nginx -s stop   //停止nginx
# /usr/locat/nginx/sbin/nginx -s reload //重新加载配置文件

PHP版本7.0.4

# wget  http://cn2.php.net/distributions/php-7.0.4.tar.gz
# tar zxvf php-7.0.4.tar.gz -C /usr/local/src/ && cd /usr/local/src/php-7.0.4
# ./configure \
--prefix=/usr/local/php7 \
--exec-prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--with-zlib-dir \
--with-mhash \
--with-mcrypt \
--with-openssl-dir \
--with-jpeg-dir \
--enable-gd-jis-conv \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-maintainer-zts \
--enable-zip \
--enable-opcache=no
# make
# make test
# make install

这里写图片描述
编译PHP中如make后报错

在包含自 /usr/local/src/php-7.0.4/ext/zip/lib/zip_add.c36 的文件中:
/usr/local/src/php-7.0.4/ext/zip/lib/zipint.h:126:2: 错误:#error unsupported size of off_t
make: *** [ext/zip/lib/zip_add.lo] 错误 1

解决方法

# echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf && ldconfig -v
# make clean //解决错误后clean,重新configure

编译完成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
# /etc/init.d/php-fpm start
Starting php-fpm  done

测试

# cat /usr/local/nginx/html/phpinfo.php
<?php
phpinfo();
?>

然后在浏览器中输入 localhost/phpinfo.php 出现如下界面算成功
这里写图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值