美文网首页Yii2我用 LinuxPHP经验分享
Centos 7 x86_64 Nginx + PHP 安装步

Centos 7 x86_64 Nginx + PHP 安装步

作者: 方圆百里找对手 | 来源:发表于2017-10-01 13:08 被阅读101次

    Centos 7 Nginx + PHP 安装步骤

    Centos 7 下的 PHP7/Nginx/Memcached 安装步骤。跟上一篇 Centos 7 Nginx + PHP 安装步骤 的区别是,这次是编译的64位的,所有的库均编译到 /usr/local/lib64 目录中,网上那些教程一般没有指定编译路径,实际上是错的,全部编译到默认路径是在
    /usr/local/lib 下然后在软连接到 lib64 里简直是有病。另外 Centos 7.4 已经升级了openssl 库,故本篇不在单独安装新版的 Openssl 。所以这篇文章完全是安装Linux的标准方式安装的,跟网上那些半吊子安装教程有本质区别。本篇文章没有去配置 php.ini,我觉得这个配置根据跟人需求自己配置即可。

    一、获取相关开源程序

    1、安装环境所需的程序库

    yum -y update
    yum -y remove mariadb*
    
    yum -y install patch make cmake gcc gcc-c++ bison flex file libtool libtool-libs autoconf re2c \
    libaio libcap glibc glib2 kernel-devel glibc-devel glib2-devel systemd ncurses ncurses-devel
    
    yum -y install curl wget nano unzip diffutils ntp
    
    yum -y install libjpeg libpng freetype libxml2 zlib bzip2 libidn gettext libxslt libedit libtidy gd libyaml
    
    yum -y install libxml2-devel openssl-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel \
    cyrus-sasl-devel gmp-devel libedit-devel libtidy-devel libxslt-devel readline-devel libidn-devel zlib-devel  \
    gettext-devel gd-devel libyaml-devel systemd-devel
    
    yum -y install whois bind-utils git mailx
    
    yum -y install supervisor memcached
    yum -y install  java-1.8.0-openjdk
    systemctl enable memcached.service
    systemctl enable supervisord.service
    systemctl enable rsyncd.service
    

    2、准备环境变量

    echo -e "/lib64\n/usr/lib64\n/usr/local/lib64\n/lib\n/usr/lib\n/usr/local/lib\n`cat /etc/ld.so.conf`" > /etc/ld.so.conf
    /sbin/ldconfig
    

    3、下载程序源码包

    cd /usr/local/src
    wget http://7xk96f.com1.z0.glb.clouddn.com/software/libiconv/libiconv-1.15.tar.gz
    wget -O php-7.1.10.tar.gz http://cn2.php.net/get/php-7.1.10.tar.gz/from/this/mirror
    wget http://7xk96f.com1.z0.glb.clouddn.com/software/mcrypt/libmcrypt-2.5.8.tar.gz
    wget http://7xk96f.com1.z0.glb.clouddn.com/software/mcrypt/mcrypt-2.6.8.tar.gz
    wget http://7xk96f.com1.z0.glb.clouddn.com/software/mhash/mhash-0.9.9.9.tar.gz
    wget http://7xk96f.com1.z0.glb.clouddn.com/software/icu/icu4c-58_2-src.tgz
    wget http://7xk96f.com1.z0.glb.clouddn.com/software/libmemcached/libmemcached-1.0.18.tar.gz
    wget http://7xk96f.com1.z0.glb.clouddn.com/software/openssl/openssl-1.1.0e.tar.gz
    wget http://7xk96f.com1.z0.glb.clouddn.com/software/nginx/nginx-1.13.5.tar.gz
    wget http://pecl.php.net/get/msgpack-2.0.2.tgz
    wget http://pecl.php.net/get/igbinary-2.0.4.tgz
    wget http://pecl.php.net/get/memcached-3.0.3.tgz
    wget http://pecl.php.net/get/redis-3.1.4.tgz
    wget http://pecl.php.net/get/yaml-2.0.2.tgz
    wget http://pecl.php.net/get/mongodb-1.3.0.tgz
    

    二、安装PHP 7(FastCGI模式)

    1、编译安装PHP 7 所需的支持库:

    tar zxf libiconv-1.15.tar.gz && cd libiconv-1.15/
    ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --enable-static
    make && make install
    cd ../
    
    tar zxf libmcrypt-2.5.8.tar.gz && cd libmcrypt-2.5.8/
    ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --enable-static
    make && make install
    ldconfig
    cd libltdl/
    ./configure --prefix=/usr/local  --libdir=/usr/local/lib64 --enable-ltdl-install
    make && make install
    cd ../../
    
    tar zxf mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9/
    ./configure --prefix=/usr/local --libdir=/usr/local/lib64
    make && make install
    cd ../
    
    tar zxf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8/
    /sbin/ldconfig
    ./configure --prefix=/usr/local --libdir=/usr/local/lib64
    make && make install
    cd ../
    
    tar zxf icu4c-58_2-src.tgz && cd icu/source/
    ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --enable-static 
    make && make install
    cd ../../
    
    tar -zxvf libmemcached-1.0.18.tar.gz && cd libmemcached-1.0.18
    ./configure --prefix=/usr/local --libdir=/usr/local/lib64
    make && make install
    cd ../
    

    2、编译安装PHP(FastCGI模式)

    tar zxf php-7.1.10.tar.gz
    cd php-7.1.10/
    /sbin/ldconfig
    ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --with-config-file-path=/usr/local/etc --with-config-file-scan-dir=/usr/local/etc/php \
    --with-libxml-dir --with-openssl --with-kerberos --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl \
    --enable-exif --enable-fpm --enable-ftp --with-png-dir --with-gd --with-jpeg-dir --enable-gd-native-ttf \
    --with-icu-dir=/usr/local --enable-mbstring --enable-mbregex --enable-shmop --enable-soap --enable-sockets \
    --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-xmlrpc --with-libedit --with-iconv-dir=/usr/local \
    --with-xsl --enable-zip --with-pcre-regex --with-pcre-jit --with-freetype-dir --enable-xml  --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --disable-rpath --enable-inline-optimization --with-mcrypt \
    --with-mhash --enable-pcntl --without-pear --with-gettext --enable-fileinfo --enable-intl --enable-opcache --enable-cli \
    --with-gmp --with-tidy --with-pcre-dir --with-readline --with-fpm-systemd --with-zlib-dir --with-libdir=lib64
    make ZEND_EXTRA_LIBS='-liconv'
    make install
    
    cp php.ini-production /usr/local/etc/php.ini
    cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
    cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
    systemctl enable php-fpm.service
    cd ../
    

    3、编译安装PHP扩展模块

    tar zxf msgpack-2.0.2.tgz
    cd msgpack-2.0.2
    phpize
    ./configure
    make && make install
    cd ../
    
    tar zxf igbinary-2.0.4.tgz
    cd igbinary-2.0.4
    phpize
    ./configure
    make && make install
    cd ../
    
    tar zxf memcached-3.0.3.tgz
    cd memcached-3.0.3
    phpize
    ./configure --with-libdir=lib64 --enable-memcached --enable-memcached-igbinary --enable-memcached-json --enable-memcached-msgpack 
    make && make install
    cd ../
    
    tar zxf redis-3.1.3.tgz
    cd  redis-3.1.3
    phpize
    ./configure
    make && make install
    cd ../
    
    tar zxf yaml-2.0.2.tgz
    cd yaml-2.0.2
    phpize
    ./configure
    make && make install
    cd ../
    
    tar zxf mongodb-1.2.9.tgz
    cd mongodb-1.2.9
    phpize
    ./configure
    make && make install
    cd ../
    
    mkdir -p /usr/local/etc/php
    echo -e "[PHP]\nextension=msgpack.so" >> /usr/local/etc/php/msgpack.ini
    echo -e "[PHP]\nextension=igbinary.so" >> /usr/local/etc/php/igbinary.ini
    echo -e "[PHP]\nextension=memcached.so" >> /usr/local/etc/php/memcached.ini
    echo -e "[PHP]\nextension=redis.so" >> /usr/local/etc/php/redis.ini
    echo -e "[PHP]\nextension=yaml.so" >> /usr/local/etc/php/yaml.ini
    echo -e "[PHP]\nextension=mongodb.so" >> /usr/local/etc/php/mongodb.ini
    

    三、安装Nginx

    tar zxf nginx-1.13.5.tar.gz
    cd nginx-1.13.5/
    ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --conf-path=/usr/local/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/run/lock/nginx.lock --pid-path=/run/nginx.pid \
    --with-http_ssl_module --with-http_v2_module --with-http_image_filter_module --with-http_xslt_module --with-http_realip_module --with-http_stub_status_module \
    --with-pcre-jit --with-http_flv_module --with-http_mp4_module --with-http_addition_module \
    --with-threads --with-http_ssl_module --with-http_gzip_static_module --without-mail_imap_module --without-mail_pop3_module --without-mail_smtp_module \
    --without-http_uwsgi_module --without-http_scgi_module --without-select_module \
    --with-cc-opt='-O2'
    
    make && make install
    cd ../
    mkdir /var/log/nginx
    mkdir /var/lib/nginx
    

    四、收尾

    1、添加www用户

    /usr/sbin/groupadd www
    /usr/sbin/useradd -M -g www www
    

    2、优化内核

    #for aliyun
    cat >>/etc/security/limits.conf<<eof
    * soft nproc 65535
    * hard nproc 65535
    eof
    
    #other
    cat >>/etc/security/limits.conf<<eof
    * soft nproc 65535
    * hard nproc 65535
    * soft nofile 65535
    * hard nofile 65535
    eof
    
    echo "fs.file-max=65535" >> /etc/sysctl.conf
    

    3、设置开机启动

    systemctl enable nginx.service
    systemctl enable php-fpm.service
    systemctl enable memcached.service
    systemctl enable supervisord.service
    

    相关文章

      网友评论

        本文标题:Centos 7 x86_64 Nginx + PHP 安装步

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