🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
#### 架构 Nginx+PHP Nginx安装请查看Nginx部署文档 #### 安装依赖 ~~~ yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel ~~~ #### 下载并编译 下载 ```shell wget http://cn.php.net/distributions/php-7.1.6.tar.gz -P /opt cd /opt tar xzf php-7.1.6.tar.gz cd php-7.1.6 ``` ##### 编译参数 ```shell ./configure \ --prefix=/usr/local/php7.1 \ --exec-prefix=/usr/local/php7.1 \ --bindir=/usr/local/php7.1/bin \ --sbindir=/usr/local/php7.1/sbin \ --includedir=/usr/local/php7.1/include \ --libdir=/usr/local/php7.1/lib/php \ --mandir=/usr/local/php7.1/php/man \ --with-config-file-path=/usr/local/php7.1/etc \ --with-mcrypt=/usr/include \ --with-mhash \ --with-openssl \ --with-mysqli=shared,mysqlnd \ --with-pdo-mysql=shared,mysqlnd \ --with-gd \ --with-iconv \ --with-zlib \ --enable-zip \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-xml \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-mbregex \ --enable-mbstring \ --enable-ftp \ --enable-gd-native-ttf \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-soap \ --without-pear \ --with-gettext \ --enable-session \ --with-curl \ --with-jpeg-dir \ --with-freetype-dir \ --enable-opcache \ --enable-fpm \ --with-fpm-user=nginx \ --with-fpm-group=nginx \ --without-gdbm \ --disable-fileinfo ``` ## 待解决:--with-iconv=/usr/local/iconv ##### 拷贝配置文件 ```shell cd /opt/php-7.1.6 cp php.ini-production /usr/local/php7.1/etc/php.ini cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm cp /usr/local/php7.1/etc/php-fpm.conf.default /usr/local/php7.1/etc/php-fpm.conf ``` ##### 加载环境变量 ```shell echo -e 'export PATH=$PATH:/usr/local/php7.1/bin:/usr/local/php7.1/sbin\n' >> /etc/profile && source /etc/profile ``` ##### 创建基础目录 PHP日志目录 php-fpm的sock目录 session的目录 ```shell mkdir -p /var/log/php-fpm/ /var/run/php-fpm /var/lib/php/session chown -R nginx:nginx /var/run/php-fpm /var/lib/php/session ``` ### 修改配置文件 #### php.ini ```shell ######避免PHP信息暴露在http头中 expose_php = Off ######避免暴露php调用mysql的错误信息 display_errors = Off ######在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置) log_errors = On ######设置PHP的扩展库路径 extension_dir = "/usr/local/php7.1/lib/php/extensions/no-debug-non-zts-20141001/" ######设置PHP的opcache和mysql动态库 zend_extension=opcache.so extension=mysqli.so extension=pdo_mysql.so ######设置PHP的时区 date.timezone = Asia/Shanghai ######开启opcache [opcache] ; Determines if Zend OPCache is enabled opcache.enable=1 ######设置PHP脚本允许访问的目录(需要根据实际情况配置) ;open_basedir = /data/ding/dynamic; ``` #### php-fpm.conf 最后追加 ```shell ######设置错误日志的路径 error_log = /var/log/php-fpm/error.log ``` #### www.conf ```shell cd /usr/local/php7.1/etc/php-fpm.d cp www.conf.default www.conf ``` www.conf追加 ```shell ######根据nginx.conf中的配置fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;设置PHP监听 ;listen = 127.0.0.1:9000 ;listen = /var/run/php-fpm/php-fpm.sock ######开启慢日志 slowlog = /var/log/php-fpm/$pool-slow.log request_slowlog_timeout = 10s ######设置php的session目录(所属用户和用户组都是nginx) php_value[session.save_handler] = files php_value[session.save_path] = /var/lib/php/session ``` ### 追加模块 ##### 设置开机 ```shell chmod +x /etc/init.d/php-fpm chkconfig --add php-fpm chkconfig php-fpm on ``` #### 疑问:编译后有一个输出 PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. 解释:安装后,模块存在