CentOS 7下部署php7.1和开启MySQL扩展的方法教程

2019-01-16 23:34:39于丽

配置安装

编译配置

[root@opstrip.com opt]# cd php-7.1.5 [root@opstrip.com php-7.1.5]# ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache

具体可以参考PHP官方安装说明文档:http://php.net/manual/zh/install.unix.nginx.php

编译安装

[root@opstrip.com php-7.1.5]# make && make install

配置环境变量:

在/etc/profile末尾追加export PATH=$PATH:/usr/local/php/bin,然后执行source /etc/profile生效后查看php版本:

[root@opstrip.com php-7.1.5]# php -v PHP 7.1.5 (cli) (built: May 31 2017 16:12:38) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

安装后的配置

配置php-fpm

安装完成后可以通过sapi/fpm/php-fpm.server来启动php-fpm了。不过为了以后管理方便,通常需要将配置文件统一放到/etc目录下,并将php-fpm.server添加至systemctl服务。如下:

[root@opstrip.com php-7.1.5]# mkdir -p /etc/php-fpm.d [root@opstrip.com php-7.1.5]# cp php.ini-production /etc/php.ini [root@opstrip.com php-7.1.5]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/ [root@opstrip.com php-7.1.5]# cp sapi/fpm/www.conf /etc/php-fpm.d/

然后更改/usr/lib/systemd/system/php-fpm.service文件使其执行正确的路径,如下:

[root@opstrip.com php-7.1.5]# vi /usr/lib/systemd/system/php-fpm.service # It's not recommended to modify this file in-place, because it # will be overwritten during upgrades. If you want to customize, # the best way is to use the "systemctl edit" command. [Unit] Description=The PHP FastCGI Process Manager After=network.target [Service] Type=simple PIDFile=/var/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target