CentOS 搭建Apache2.4/PHP7.2

环境准备

yum install -y gcc gcc-c++ zlib-devel expat-devel libxml2-devel libtoos openssl-devel wget vim curl-devel libjpeg-devel libpng-devel

文件准备

# Apache-2.4 http://httpd.apache.org/download.cgi#apache24
wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.39.tar.gz

# apr https://apr.apache.org/
# APR-1.7.0
wget http://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
# APR-util 1.6.1
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
# APR-iconv 1.2.2
wget http://mirror.bit.edu.cn/apache//apr/apr-iconv-1.2.2.tar.gz
# PCRE https://ftp.pcre.org/pub/pcre/
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz

# php https://www.php.net/downloads.php
wget https://www.php.net/distributions/php-7.2.2.tar.gz

安装APR

tar -zxvf apr-1.7.0.tar.gz
cd apr-1.7.0
./configure --prefix=/usr/local/apr
make && make install
# 如提示"libTools"安装失败请修改./configure文件
vim ./configure
RM "cfgfile"
变更为
# RM "cfgfile"
再次重新编译及安装一次即可

安装APR-ICONV

tar -zxvf apr-iconv-1.2.2.tar.gz
cd apr-iconv-1.2.2
./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr
make && make install

安装APR-UTIL

tar -zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-apr-iconv
make && make install

安装PCRE

tar -zxvf pcre-8.43.tar.gz
cd pcre-8.43
./configure --prefix=/usr/local/pcre
make && make install

安装Apache

tar -zxvf httpd-2.4.39.tar.gz
cd httpd-2.4.39
./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --with-pcre=/usr/local/pcre --with-apr-util=/usr/local/apr-util --with-apr=/usr/local/apr --enable-so --enable-ssl --enable-cgi --enable-rewrite
make && make install

安装PHP(如不需要PHP可略过此步)

tar -zxvf php-7.2.2.tar.gz
cd php-7.2.2
./configure --prefix=/usr/local/apache2/php/php7 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/etc/php/php7/ --with-zlib-dir --with-libxml-dir=/usr --with-curl --with-zlib --with-gd --with-pdo-sqlite --with-pdo-mysql --with-mysqli --with-mysql-sock --enable-mysqlnd --with-zlib --with-openssl
make && make install

#创建目录
mkdir -p /etc/php/php7

#配置文件移至配置目录
# php.ini-development     测试开发环境
# php.ini-production      生产环境
cp  php.ini-development /etc/php/php7/php.ini

配置Apache

groupadd _www #创建用户组
useradd -s /sbin/nologin -g _www -M www #创建用户
vim /etc/httpd/httpd.conf #编辑配置文件

#添加对php文件的支持
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

启动/停止/重启

/usr/local/apache2/bin/apachectl start #启动
/usr/local/apache2/bin/apachectl stop #停止
/usr/local/apache2/bin/apachectl restart #重启

发表评论

电子邮件地址不会被公开。 必填项已用*标注