CentOS 7 下编译安装lnmp之PHP篇详解

一、安装环境

宿主机=> win7,虚拟机 centos => 系统版本:centos-release-7-5.1804.el7.centos.x86_64

CentOS 7 下编译安装lnmp之PHP篇详解

二、PHP下载

官网 http://www.php.net/downloads.php 下载 php-7.3.0.tar.bz2 至 /usr/local/src 目录下

解压并移动至 /usr/local/下,重命名为php7

[root@bogon src]# tar -jxf php-7.3..tar.bz2
[root@bogon src]# mv php-7.3. /usr/local/php7
[root@bogon src]# ls /usr/local/php7
acinclude.m4 genfiles php.ini-development run-tests.php
aclocal.m4 header php.ini-production sapi
appveyor INSTALL README.EXT_SKEL scripts
build install-sh README.GIT-RULES server-tests-config.php
buildconf LICENSE README.input_filter server-tests.php
buildconf.bat ltmain.sh README.MAILINGLIST_RULES snapshot
CODING_STANDARDS main README.md stamp-h.in
config.guess makedist README.NEW-OUTPUT-API tests
config.sub Makefile.frag README.PARAMETER_PARSING_API travis
configure Makefile.gcov README.REDIST.BINS TSRM
configure.ac Makefile.global README.RELEASE_PROCESS UPGRADING
CONTRIBUTING.md missing README.SELF-CONTAINED-EXTENSIONS UPGRADING.INTERNALS
CREDITS mkinstalldirs README.STREAMS vcsclean
ext NEWS README.SUBMITTING_PATCH win32
EXTENSIONS pear README.TESTING Zend
footer php7.spec.in README.UNIX-BUILD-SYSTEM
generated_lists php.gif README.WIN32-BUILD-SYSTEM

三、PHP7编译安装

1、安装依赖

[root@bogon src]# yum install gd zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel

2、配置参数

[root@bogon php7]# ./configure --prefix=/usr/local/php7 --with-gd --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --enable-mbstring --enable-fpm

运行结果

Thank you for using PHP.

config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.
config.status: creating sapi/cli/php.
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.
config.status: creating sapi/cgi/php-cgi.
config.status: creating ext/phar/phar.
config.status: creating ext/phar/phar.phar.
config.status: creating main/php_config.h
config.status: main/php_config.h is unchanged
config.status: executing default commands

3、编译安装

[root@bogon php7]# make && make install

四、启动PHP7

1、测试启动PHP进程

[root@bogon php7]# ./sbin/php-fpm
[-Dec- ::] ERROR: failed to open configuration file '/usr/local/php7/etc/php-fpm.conf': No such file or directory ()
[-Dec- ::] ERROR: failed to load configuration file '/usr/local/php7/etc/php-fpm.conf'
[-Dec- ::] ERROR: FPM initialization failed

大意是在 /usr/local/php7/etc/ 目录下找不到 php-fpm.conf,进入该目录查看

[root@bogon php7]# ls etc
pear.conf php-fpm.conf.default php-fpm.d

只有 php-fpm.conf.default文件,复制一份更名为 php-fpm.conf

[root@bogon php7]# cp etc/php-fpm.conf.default etc/php-fpm.conf
[root@bogon php7]# ls etc
pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d

再次启动

[root@bogon php7]# ./sbin/php-fpm
[-Dec- ::] WARNING: Nothing matches the include pattern '/usr/local/php7/etc/php-fpm.d/*.conf' from /usr/local/php7/etc/php-fpm.conf at line .
[-Dec- ::] ERROR: No pool defined. at least one pool section must be specified in config file
[-Dec- ::] ERROR: failed to post process the configuration
[-Dec- ::] ERROR: FPM initialization failed
去 /usr/local/php7/etc/php-fpm.conf 的143行查看
[root@bogon php7]# vi etc/php-fpm.conf

 include=/usr/local/php7/etc/php-fpm.d/*.conf

查看 /usr/local/php7/etc/php-fpm.d 目录

[root@bogon php7]# ls etc/php-fpm.d
www.conf.default

只有www.conf.default,复制一份重命名为 www.conf

[root@bogon php7]# cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf
[root@bogon php7]# ls etc/php-fpm.d
www.conf www.conf.default

再次启动 php-fpm

[root@bogon php7]# ./sbin/php-fpm
[root@bogon php7]# ps aux | grep php
root 0.0 0.5 ? Ss : : php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 0.0 0.5 ? S : : php-fpm: pool www
nobody 0.0 0.5 ? S : : php-fpm: pool www
root 0.0 0.0 pts/ R+ : : grep --color=auto php

进程启动成功,查看php详细版本信息

[root@bogon php7]# ./bin/php -v
PHP 7.3. (cli) (built: Dec ::) ( NTS )
Copyright (c) - The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) - Zend Technologies

2、设置开机启动

2.1、在系统服务目录里创建php7.,service文件

[root@bogon php7]# vi /lib/systemd/system/php7.service

2.2、添加如下内容

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target [Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID [Install]
WantedBy=multi-user.target

2.3、添加到开机启动

[root@bogon php7]# systemctl enable php7.service

2.4、启动php7服务

[root@bogon php7]# pkill - php-fpm
[root@bogon php7]# systemctl start php7
[root@bogon php7]# systemctl status php7
● php7.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php7.service; enabled; vendor preset: disabled)
Active: active (running) since Mon -- :: CST; 7s ago
Main PID: (php-fpm)
CGroup: /system.slice/php7.service
├─ php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
├─ php-fpm: pool www
└─ php-fpm: pool www Dec :: bogon systemd[]: Started The PHP FastCGI Process Manager.
Dec :: bogon systemd[]: Starting The PHP FastCGI Process Manager...

至此,php7编译安装完毕。

上一篇:源码编译安装lnmp环境


下一篇:CentOS 5.5编译安装lnmp