安装apache
查看是否自带了httpd,如果有需要先卸载:
# 查看是否已安装httpd
rpm -qa|grep httpd
# 卸载
yum remove httpd
安装方法参考CentOS7编译安装Apache2.4
安装php7.4
安装依赖包
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-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 libmemcached-devel oniguruma-devel libcurl-devel
安装编译工具
yum groupinstall 'Development Tools'
安装libzip
wget https://libzip.org/download/libzip-1.3.2.tar.gz
tar xvf libzip-1.3.2.tar.gz
cd libzip-1.3.2
./configure
make
make install
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
下载php7.4源文件
更多版本在这里:https://www.php.net/releases/
cd /home
wget https://www.php.net/distributions/php-7.4.33.tar.gz
解压
tar xf php-7.4.33.tar.gz
编译安装
cd /home/php-7.4.33
./configure --prefix=/www/server/php74 --with-apxs2=/www/server/apache/bin/apx --with-config-file-path=/www/server/php74/etc --with-curl --with-freetype --enable-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --enable-xml --with-mysqli --with-openssl --with-pdo-mysql --with-pear --with-jpeg --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --with-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --with-zip --enable-fpm
make && make install
设置环境变量
vim /etc/profile
添加
PATH=$PATH:/www/server/php74/bin
export PATH
立即生效
source /etc/profile
查看php版本
php -v
配置apache
编辑/www/server/apache/conf/httpd.conf
在AddType application/x-gzip .gz .tgz
下方添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
搜索以下代码是否已自动添加,如已自动添加则不用添加
LoadModule php7_module modules/libphp7.so
重启apache
测试php
在web目录下,新建一个1.php,内容如下:
<?php
phpinfo();
访问该文件,如果可以正常打开页面,则说明php环境配置成功: