Centos 7.8 编译安装PHP 7.4.7-pdo-PHP Fatal error: Class PDO not found

准备

  1. 系统版本检查
[root@ecs ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
  1. 检查是否曾经安装过php
[root@ecs ~]# php -v
-bash: php: command not found

不存在php命令,说明未成功安装PHP

安装

  1. 下载安装编译工具
yum groupinstall -y 'Development Tools'
  1. 安装依赖包
yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel sqlite-devel
  1. 下载并解压php7.4.7
wget http://php.net/distributions/php-7.4.7.tar.gz
#如果wegt下载的慢就直接去官网下载后上传到服务器
#https://www.php.net/downloads.php
tar -zxvf php-7.4.7.tar.gz
  1. 编译安装
cd php-7.4.7
./configure
make && make install 
  1. 检查
php -v

PHP模块

  1. PDO
    利用PDO对数据库进行操作,类似的还有mysql、mysqli
yum install -y php-pdo

遇到的问题

  1. 编译后报错
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
No package 'sqlite3' found

解决办法,安装依赖包在重新编译,(已经加入到第2步中,所以按照上面的来不会出现这个问题了)

yum install -y sqlite-devel
  1. Apache无法自动加载php7.4
    其它帖子只有解决php7.2的办法。。那个yum还没有php7.4模块

References

  • 个性化配置教程 https://www.cnblogs.com/liubaoqing/p/12176017.html
  • 官网 https://www.php.net/downloads.php#v7.4.7
  • 问题解决方案 https://www.cnblogs.com/liyuanhong/p/12016767.html
  • Apache配置php7 https://editor.csdn.net/md?articleId=107119689
  • https://blog.csdn.net/qq_41170899/article/details/80696200

你可能感兴趣的:(Centos,PHP,php,linux)