美文网首页
LNMP环境搭建(centos6.9+mysql5.7+php7

LNMP环境搭建(centos6.9+mysql5.7+php7

作者: 如果明日来临 | 来源:发表于2018-06-07 10:45 被阅读23次

    本文转载自:http://woymk.blog.51cto.com/10000269/1917133
    原文作者:woymk

    一、安装MySql
    mysql的安装请参考

    LAMP环境搭建(centos6.9+apache2.4+mysql5.7+php7.1)

    和里面的安装方法一样。

    二、php安装

    cd /usr/local/src
    wget http://mirrors.sohu.com/php/php-7.1.3.tar.gz
    tar zxvf php-7.1.3.tar.gz
    cd php-7.1.3

    ./configure
    --prefix=/usr/local/php
    --with-apxs2=/usr/local/apache2/bin/apxs
    --with-config-file-path=/usr/local/php/etc
    --enable-fpm
    --with-fpm-user=nobody
    --with-fpm-group=nobody
    --with-mysql-sock=/tmp/mysql.sock
    --enable-mysqlnd
    --with-mysqli=mysqlnd
    --with-pdo-mysql=mysqlnd
    --with-libxml-dir
    --with-gd
    --with-jpeg-dir
    --with-png-dir
    --with-freetype-dir
    --with-iconv-dir
    --with-zlib-dir
    --with-bz2
    --with-openssl
    --with-mcrypt
    --enable-soap
    --enable-gd-native-ttf
    --enable-mbstring
    --enable-sockets
    --enable-exif
    --disable-ipv6

    如果出现“configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no”之类的错误
    解决办法:
    sudo ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/
    sudo ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

    make && make install

    cp php.ini-production /usr/local/php/etc/php.ini

    cp /usr/local/src/php-7.1.3/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    cp -v /usr/local/php/etc/{php-fpm.conf.default,php-fpm.conf}

    cp -v /usr/local/php/etc/php-fpm.d/{www.conf.default,www.conf}
    vi /usr/local/php/etc/php-fpm.d/www.conf

    修改 (如果user和group在编译参数里设置了,这里就不用修改了)
    user = nobody
    group = nobody

    修改php.ini
    vi /usr/local/php/etc/php.ini
    date.timezone = Asia/Chongqing

    chmod 755 /etc/init.d/php-fpm
    chkconfig --add php-fpm
    chkconfig php-fpm on
    service php-fpm start

    三、安装nginx
    cd /usr/local/src
    yum install -y pcre-devel
    wget http://mirrors.sohu.com/nginx/nginx-1.10.3.tar.gz
    tar zxvf nginx-1.10.3.tar.gz
    cd nginx-1.10.3
    ./configure --prefix=/usr/local/nginx --with-pcre
    make && make install

    vi /etc/init.d/nginx

    把nginx脚本(从这里复制nginx启动脚本)保存为 /etc/init.d/nginx,找到下面三行

    nginx="/usr/sbin/nginx"
    pidfile="/var/run/${prog}.pid"

    NGINX_CONF_FILE="/etc/nginx/nginx.conf"

    修改为:

    nginx="/usr/local/nginx/sbin/nginx"
    pidfile="/usr/local/nginx/logs/${prog}.pid"

    NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

    保存后,执行
    chmod +x /etc/init.d/nginx
    chkconfig --add nginx
    chkconfig nginx on
    /etc/init.d/nginx start

    五、配置解析php

    vi /usr/local/nginx/conf/nginx.conf
    找到

    location / {
                root   html;
                index  index.html index.htm;
    }
    

    改成

    location / {
                root   html;
                index  index.html index.htm index.php;
     }
    

    找到

            #location ~ \.php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    

    改成

    location ~ \.php$ {
          root           html;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
          include        fastcgi_params;
     }
    

    测试nginx配置文件是否正确
    /usr/local/nginx/sbin/nginx -t
    重新加载配置文件
    /etc/init.d/nginx reload
    测试解析php
    vi /usr/local/nginx/html/1.php
    写入:

    <?php
        echo "php解析正常";
        echo phpinfo();
    ?>
    

    保存后,继续测试:
    curl localhost/1.php
    查看结果已经可以成功解析。


    2018-06-02_225755.jpg

    相关文章

      网友评论

          本文标题:LNMP环境搭建(centos6.9+mysql5.7+php7

          本文链接:https://www.haomeiwen.com/subject/svwwsftx.html