CentOS7下源码编译安装PHP7.4

2020-11-18  本文已影响0人  刘禹锡_c886

操作系统:CentOS7
安装版本:PHP7.4

【官网】https://www.php.net/downloads

1)到PHP官网下载PHP7.4,并且解压

cd /home/install/php
wget https://www.php.net/distributions/php-7.4.12.tar.gz
tar -zxvf php-7.4.12.tar.gz
1.png

2)切换到解压目录编译配置

#更多可以在  ./configure --help 去查看
./configure --prefix=/usr/local/php \
 --with-config-file-path=/etc --enable-fpm  --enable-inline-optimization \
 --disable-debug --enable-mysqlnd --enable-static --disable-rpath --enable-shared --enable-soap  --with-xmlrpc \
 --with-openssl --with-mhash  --with-external-pcre --with-pcre-jit --with-zlib \
 --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl \
 --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pear \
 --enable-opcache --enable-ftp --with-gdbm --with-openssl-dir --with-jpeg --with-zlib-dir \
 --with-freetype --enable-gd --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --with-sqlite3\
 --enable-mbstring --enable-mbregex --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
 --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg \
 --enable-sysvsem --enable-sysvshm --with-xsl --with-zip --enable-mysqlnd-compression-support --enable-intl

编译时可能会出现一些错误 configure error:(我编译安装时遇到的报错如下,有其他报错请另外自己解决)

1. configure: error: Please reinstall the BZip2 distribution
    解决:yum install bzip2 bzip2-devel -y

2. configure: error: Package requirements (libcurl >= 7.15.5) were not met:No package 'libcurl' found
    解决:yum install libcurl libcurl-devel -y

3.configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
    解决:yum install libxslt libxslt-devel -y

4.configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
    解决:yum install sqlite-devel -y

5.configure: error: GNU MP Library version 4.2 or greater required.
    解决:yum install gmp-devel -y   

6.configure: error: Package requirements (oniguruma) were not met: No package 'oniguruma' found
    解决:yum install oniguruma-devel -y

7.configure: error: Please reinstall readline - I cannot find readline.h
    解决:yum install readline-devel -y

8.configure: error: Package requirements (libpcre2-8 >= 10.30) were not met: No package 'libpcre2-8' found
    解决:https://www.jianshu.com/p/89646111a1ce

9.configure: error: DBA: Could not find necessary header file(s).
     解决:yum install gdbm-devel -y
10.configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:No package 'libzip' found
    解决:https://www.jianshu.com/p/6cbd25addc29
11.configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met: No package 'libxml-2.0' found
    解决:yum install libxml2-devel -y
12.configure: error: Package requirements (libpng) were not met: No package 'libpng' found
    解决:yum install libpng-devel -y
13.configure: error: Package requirements (libjpeg) were not met:No package 'libjpeg' found
    解决:yum install libjpeg-devel -y
14.configure: error: Package requirements (freetype2) were not met:No package 'freetype2' found
    解决:yum install freetype-devel -y
15.configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:
    No package 'icu-uc' found
    No package 'icu-io' found
    No package 'icu-i18n' found
    解决:yum install libicu-devel -y

到这里没有报错过一会会出现下图界面

2.png

然后再执行编译安装命令(编译安装过程时间有些长,须耐心等待)

make
make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/
Installing PHP CLI binary:        /usr/local/php/bin/
Installing PHP CLI man page:      /usr/local/php/php/man/man1/
Installing PHP FPM binary:        /usr/local/php/sbin/
Installing PHP FPM defconfig:     /usr/local/php/etc/
Installing PHP FPM man page:      /usr/local/php/php/man/man8/
Installing PHP FPM status page:   /usr/local/php/php/php/fpm/
Installing phpdbg binary:         /usr/local/php/bin/
Installing phpdbg man page:       /usr/local/php/php/man/man1/
Installing PHP CGI binary:        /usr/local/php/bin/
Installing PHP CGI man page:      /usr/local/php/php/man/man1/
Installing build environment:     /usr/local/php/lib/php/build/
Installing header files:          /usr/local/php/include/php/
Installing helper programs:       /usr/local/php/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.9
[PEAR] Console_Getopt - installed: 1.4.3
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.5
warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.9 is not the recommended version 1.4.4
[PEAR] PEAR           - installed: 1.10.12
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/home/install/php/php-7.4.12/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin/phar.phar
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/

3)以上终于完成PHP的源码编译安装了,下面就是配置PHP

# 配置PHP
[root@localhost php-7.4.12]# php -v
bash: php: 未找到命令...
[root@localhost php-7.4.12]# /usr/local/php/bin/php -v
PHP 7.4.12 (cli) (built: Nov 16 2020 19:43:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

为PHP添加环境变量

export PATH=$PATH:/usr/local/php/bin

php -v 直接就能查看php版本,不需要再 /usr/local/php/bin/php -v 这么长了

[root@localhost php-7.4.12]# php -v
PHP 7.4.12 (cli) (built: Nov 16 2020 19:43:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

4)配置PHP-fpm,(请注意我的目录,是一直在PHP7的解压目录下操作命令)
/home/install/php/php-7.4.12/ 是我下载PHP包解压出来的目录
/usr/local/php/ 是PHP编译安装的目录

3.png

开始配置PHP-fpm,复制一些配置文件,做好备份准备

[root@localhost php-7.4.12] cp php.ini-development /etc/php.ini
[root@localhost php-7.4.12] cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.12] cd /usr/local/php/etc
[root@localhost etc] cp php-fpm.conf.default php-fpm.conf
[root@localhost etc] cp php-fpm.d/www.conf.default php-fpm.d/www.conf
[root@localhost etc]chmod +x /etc/init.d/php-fpm


# /etc/init.d/php-fpm文件的内容,确保正确
prefix=/usr/local/php
exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid

这时候就开始启动php-fpm了

# service php-fpm {start|stop|force-quit|restart|reload|status|configtest}
service php-fpm start  #启动命令
ps ax|grep php-fpm    # 查看是否启动php-fpm
[root@localhost etc]  ps ax | grep php-fpm   # 或者  netstat -ant | grep 9000
 33891 ?        Ss     0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
 33892 ?        S      0:00 php-fpm: pool www
 33893 ?        S      0:00 php-fpm: pool www
 34443 pts/0    S+     0:00 grep --color=auto php-fpm

终于完成了......

最后补个小tips

假如在编译配置里加入这两个配置而导致启动失败
--with-fpm-user=nginx
--with-fpm-group=nginx
如果启动php-fpm失败,则需要在安装完之后的目录 /usr/local/php/etc/php-fpm.d/www.conf(配置完后的文件)

找到user和group修改他们的值为 nobody 就可以启动成功了

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = nobody
group = nobody
上一篇下一篇

猜你喜欢

热点阅读