Apache和Mariadb安装基本都没有什么问题
PHP7.4安装过程中出现很多报错,网络大佬够已经给解决,下边安装步骤已经亲测:
需要安装apache的:
安装:yum -y install httpd
systemctl satart httpd
systemctl status httpd
需要安装mariadb的:
yum -y install mariadb-server mariadb
yum -y install mariadb-server php-mysql
systemctl start/restart/stop/status mariadb
systemctl enable mariadb
#设置密码
mysql_secure_installation
1、首先安装依赖包:
yum -y install 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 epel-release
2、下载解压PHP7.4
wget http://php.net/distributions/php-7.4.0.tar.gz
tar -zxvf php-7.4.0.tar.gz
cd php-7.4.0
# 编译前,新增用户组,用户,用于编译使用
groupadd www
useradd -g www www
编译配置:(跟进自己情况删减)
./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-fpm-user=www --with-fpm-group=www --with-curl --with-freetype-dir --enable-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm
3、编译报错解决办法:
解压完后先不要编译,请检查是否安装了gcc ,没有的话执行yum install gcc
检查是否安装了libxml2 ,没有的话执行yum install libxml2
检查是否安装了libxml2-devel,没有的话执行yum install libxml2-devel
编译安装 PHP 7.4 提示 No package oniguruma found
解决办法:
yum install -y epel-release
yum install -y oniguruma oniguruma-devel
error: Package requirements (sqlite3 > 3.7.4) were not met
yum install libsqlite3x-devel -y
error: Package requirements (oniguruma) were not met
yum install oniguruma-devel -y
报错:Cannot find libpq-fe.h. Please specify correct PostgreSQL
installation path
解决办法:
yum -y install postgresql-devel
4、编译安装
# make
make && make install
5、环境变量
# 查看版本
/usr/local/php/bin/php -v
# 添加环境变量
vim /etc/profile
# 在最后添加
PATH=$PATH:/usr/local/php/bin
export PATH
# 更新环境变量
source /etc/profile
# 查看版本
php -v
返回结果如下所示,表示安装成功。
PHP 7.4.0 (cli) (built: Dec 6 2022 22:30:44) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
# 配置php-fpm
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
# 启动php
/etc/init.d/php-fpm start 或者 service php-fpm start
6、测试PHP解析
运行以下命令,在Apache网站根目录创建测试文件。
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
systemctl restart httpd
访问
http://ip地址/phpinfo.php
如果打开显示PHP版本信息说明解析成功,否则解析不成功,继续第7步。
7、如果PHP不解析:
安装
yum install mod_php71w
安装后再从试步骤6
8、php安装redis扩展
方法一:
yum -y install git
git clone https://github.com/nicolasff/phpredis # 一般就在/usr/local
/usr/local/php7/bin/phpize
#找不到phpize的路径可用whereis命令查看:whereis phpize 得到路径
./configure --with-php-config=/usr/local/php/bin/php-config
#此处为php-config的路径,可用whereis php-config查看路径
make && make install
# 修改配置文件
vim /etc/php.ini #编辑配置文件,在最后一行添加以下内容
extension="redis.so"
# 重启nginx和php-fpm
service nginx restart
/etc/init.d/php-fpm restart
方法二:
# phpredis安装
pecl install redis
# 改配置文件
vim /etc/php.ini
# 在最后加上
[redis]
extension=redis.so
# 重启php
/etc/init.d/php-fpm restart
# 访问验证