Apache2.4.46 + PHP 7.4.5 源码编译安装
- php
- 2020-08-29
- 5299
- 0
Apache2.4.46 + PHP 7.4.5
apache
安装依赖
yum clean all
yum update -y
yum install expat-devel -y
yum groupinstall base -y
yum grouplist -y
yum groupinstall 'Development tools' -y
yum groupinstall 'Debugging Tools' -y
yum groupinstall 'Compatibility libraries' -y
yum install pcre* pcre-devel* openssl-devel* -y
yum install cmake -y
yum install python-devel -y
yum -y install gd *openssl*
下载最新版本
wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
wget http://apache.communilink.net/apr/apr-1.7.0.tar.gz
wget http://apache.communilink.net/apr/apr-util-1.6.1.tar.gz
解压以上三个文件包
将 apr 、 apr-util 移动到 httpd-2.4.41/srclib/ 目录下
mv apr-1.7.0 httpd-2.4.41/srclib/apr
mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-util
安装 apr
cd /path/httpd-2.4.41/srclib/apr
./configure --prefix=/usr/local/apr
make&&make install
安装 apr-util
cd /path/httpd-2.4.41/srclib/apr-util
make clean
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make&&make install
安装 httpd
cd /path/httpd-2.4.41
./configure --prefix=/usr/local/apache --sysconfdir=/usr/local/apache/etc --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=prefork --with-included-apr --libdir=/usr/lib64 --enable-ssl --with-ssl
make && make install
创建 apace 用户和用户组
groupadd apache
useradd --shell /sbin/nologin -g apache apache
chown -R apache:apache /usr/local/apache/
编辑 http.conf 文件
vim /usr/local/apache/etc/httpd.conf
ServerName 0.0.0.0
cd /usr/local/apache/bin/
./apachectl start 启动
./apachectl stop 关闭
./apachectl restart 重启
添加防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
添加 systemctl 命令
vim /lib/systemd/system/apache.service
[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecReload=/usr/local/apache/bin/apachectl restart
ExecStop=/usr/local/apache/bin/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
// 命令
systemctl enable apache //
systemctl start|stop|restart apache
参考
https://www.osyum.com/article/show/379/
PHP
安装依赖
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt libicu-devel libxslt-devel oniguruma-devel
下载最新版
wget https://www.php.net/distributions/php-7.4.5.tar.gz
tar -xvf php-7.4.5.tar.gz
明确 apsx 路径
find / -name 'apxs*'
/usr/local/apache/bin/apxs
整合 apache,apxs功能是使用mod_so中的LoadModule指令,加载指定模块到 apache,要求 apache 要打开SO模块
检测
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-pdo --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir= --enable-xml --enable-session --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --enable-maintainer-zts --with-xsl --enable-tokenizer
make && make install
复制配置文件
cp php.ini-production /usr/local/php/etc/php.ini
修改配置文件
vim /usr/local/php/etc/php.ini
session.save_path = "/usr/local/php/tmp"
expose_php = Off
date.timezone = PRC
参考
https://zhuanlan.zhihu.com/p/59466324
https://www.ikraddy.com/63.html
https://blog.51cto.com/frankch/1755487
整合 Apache 和 php
Apache 配置文件路径 /etc/httpd/conf/httpd.conf
检测加载php模块,这个在安装php后会自动修改,检查一下就行
LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so
修改配置
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
重启 Apache