其中 /usr/local/mysql/mysql.sock 就是上面安装 MySQL 时提到的。这个值必须填,否则会出现如下错误:
Warning: mysqli_connect(): (HY000/2002): No such file or directory
修改时区,查找 date.timezone,改成(主要将前面的 ; 去掉,这个是注释用的):
root@localhost php-7.1.4]# grep date.timezone /usr/local/php/lib/php.ini ; ;date.timezone = [root@localhost php-7.1.4]# sed -i 's#;date.timezone =#date.timezone = Asia/Shanghai#' /usr/local/php/lib/php.ini [root@localhost php-7.1.4]# grep date.timezone /usr/local/php/lib/php.ini ; date.timezone = Asia/Shanghai好了,PHP 7 已经安装好,下面验证一下
[root@localhost php-7.1.4]# /usr/local/php/bin/php -v PHP 7.1.4 (cli) (built: Apr 17 2017 14:58:11) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies再查看下已经安装的模块
[root@localhost php-7.1.4]# /usr/local/php/bin/php -m [PHP Modules] Core ctype curl date dom fileinfo filter ftp gd hash iconv json libxml mbstring mysqli mysqlnd openssl pcre PDO pdo_sqlite Phar posix Reflection session SimpleXML SPL sqlite3 standard tokenizer xml xmlreader xmlwriter zip zlib [Zend Modules]接下来配置 php-fpm,复制 php-fpm 的配置文档
[root@localhost php-7.1.4]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [root@localhost php-7.1.4]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf修改 /usr/local/php/etc/php-fpm.d/www.conf,把启动用户改为和nginx服务同一个启动用户(前面Nginx使用的是www账户,这里改成和Nginx使用一样的账户;一般都是使用www用户)
[root@localhost php-7.1.4]# grep -E 'user =|group =' /usr/local/php/etc/php-fpm.d/www.conf user = nginx group = nginx [root@localhost php-7.1.4]# sed -i 's#user = nginx#user = www#' /usr/local/php/etc/php-fpm.d/www.conf [root@localhost php-7.1.4]# sed -i 's#group = nginx#group = www#' /usr/local/php/etc/php-fpm.d/www.conf [root@localhost php-7.1.4]# grep -E 'user =|group =' /usr/local/php/etc/php-fpm.d/www.conf user = www group = www ;listen.group = www其中 中要留意这个值 listen = 127.0.0.1:9000
[root@localhost php-7.1.4]# grep 'listen = 127.0.0.1' /usr/local/php/etc/php-fpm.d/www.conf这里使用 9000 端口,这个选项在配置 Nginx 网站时要用到的。
配置 php-fpm 启动服务脚本
查看启动脚本中指定的程序目录和pid文件(默认已经修改过了,如果没有修改过执行下面操作)
[root@localhost php-7.1.4]# grep -E 'PIDFile|ExecStart' /usr/lib/systemd/system/php-fpm.service PIDFile=/usr/local/php/var/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf修改启动脚本,把里边 prefix 相关的内容用实际路径代替
[root@localhost php-7.1.4]# vim /usr/lib/systemd/system/php-fpm.service 将 PIDFile=${prefix}/var/run/php-fpm.pid ExecStart=${exec_prefix}/sbin/php-fpm --nodaemonize --fpm-config ${prefix}/etc/php-fpm.conf 修改成 PIDFile=/usr/local/php/var/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf重新载入 systemd
[root@localhost php-7.1.4]# systemctl daemon-reload让 php-fpm 随机启动
[root@localhost php-7.1.4]# systemctl enable php-fpm Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.立即启动 php-fpm
[root@localhost php-7.1.4]# systemctl start php-fpm查看状态
[root@localhost php-7.1.4]# systemctl status php-fpm ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled) Active: active (running) since 一 2017-04-17 15:37:06 CST; 1min 9s ago Main PID: 55770 (php-fpm) CGroup: /system.slice/php-fpm.service ├─55770 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) ├─55771 php-fpm: pool www └─55772 php-fpm: pool www 4月 17 15:37:06 localhost.localdomain systemd[1]: Started The PHP FastCGI Process Manager. 4月 17 15:37:06 localhost.localdomain systemd[1]: Starting The PHP FastCGI Process Manager...好,php-fpm 已经成功启动,那就立即建个网站看看
配置 Nginx 站点
先建立一个 lnmp 站点,路径是 /var/www/html
并准备好 phpinfo 测试文件
cat >> /var/www/html/test.php << EOF <?php phpinfo(); EOF