1、安装基本依赖软件:

yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y

2、安装libiconv软件:


  1. cd /data/soft
  2. wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
  3. tar zxf libiconv-1.14.tar.gz
  4. cd libiconv-1.14
  5. ./configure –prefix=/usr/local/libiconv
  6. make
  7. make install

3、安装其他软件包:


  1. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
  2. yum -y install libmcrypt-devel mhash mcrypt

4、安装php:


  1. cd /data/soft/
  2. tar xf php-7.4.30.tar.gz
  3. cd php-7.4.30

5、在解压后的PHP目录内执行:


  1. ln -s /data/server/mysql/lib/libmysqlclient.so.18 /usr/lib64/
  2. touch ext/phar/phar.phar
    ./configure \
  3. –prefix=/data/server/php-7.4.30 \
  4. –with-mysql=/data/server/mysql \
  5. –with-pdo-mysql=mysqlnd \
  6. –with-iconv-dir=/usr/local/libiconv \
  7. –with-freetype-dir \
  8. –with-jpeg-dir \
  9. –with-png-dir \
  10. –with-zlib \
  11. –with-libxml-dir=/usr \
  12. –enable-xml \
  13. –disable-rpath \
  14. –enable-bcmath \
  15. –enable-shmop \
  16. –enable-sysvsem \
  17. –enable-inline-optimization \
  18. –with-curl \
  19. –enable-mbregex \
  20. –enable-fpm \
  21. –enable-mbstring \
  22. –with-mcrypt \
  23. –with-gd \
  24. –enable-gd-native-ttf \
  25. –with-openssl \
  26. –with-mhash \
  27. –enable-pcntl \
  28. –enable-sockets \
  29. –with-xmlrpc \
  30. –enable-zip \
  31. –enable-soap \
  32. –enable-short-tags \
  33. –enable-static \
  34. –with-xsl \
  35. –with-fpm-user=www \
  36. –with-fpm-group=www \
  37. –enable-ftp
  38. #编译时可能会出错,先执行上面的操作再编译安装
  39. make
  40. make install

6、php文件配置

创建目录,生成程序文件,这里失败的话/data/server下就不会有php的目录

注意:如果server下没有php那么从上面报错的地方一步步纠正,直到有php才算安装成功

[root@localhost php-7.4.30]# ls /data/server/

mysql  mysql-5.6.35-linux-glibc2.5-x86_64  nginx  php-7.4.30

7、创建一个软链接,方便使用,更新软件时,重新创建软链接即可


  1. cd /data/server
    ln -s php-7.4.30 php

8、把解压包内的php解析文件拷贝到php安装目录下


cd /data/soft/php-7.4.30
cp php.ini-production /data/server/php/lib/php.ini

9、修改php.ini文件,开启session功能


vim /data/server/php/lib/php.ini
[Session]
; Handler used to store/retrieve data.
; http://php.net/session.save-handler
session.save_handler = files
原内容:
;session.save_path = “/tmp
修改后内容:
session.save_path = “/tmp

10、复制php-fpm的配置文件,默认没有该文件但是有一个备份文件


cd /data/server/php/etc/
cp php-fpm.conf.default php-fpm.conf

11、启动php,和nginx一样,使用程序目录下的启动命令来启动php,然后检查进程和端口号即可


  1. /data/server/php/sbin/php-fpm
  2. netstat -tnulp | grep php-fpm

如果报错:

报错: No pool defined. at least one pool section must be specified in config file

解决方法:
进入安装目录:/usr/local/php/etc/php-fpm.d
拷贝www.conf.default为www.conf即可。

[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-7.4.20]# /etc/init.d/php-fpm start Starting php-fpm done

至此php安装成功结束