Apache2.4.46 + PHP 7.4.5 源码编译安装
- php
- 2020-08-29
- 220
- 0
Apache2.4.46 + PHP 7.4.5
apache
安装依赖
yum clean allyum update -yyum install expat-devel -yyum groupinstall base -yyum grouplist -yyum groupinstall 'Development tools' -yyum groupinstall 'Debugging Tools' -yyum groupinstall 'Compatibility libraries' -yyum install pcre* pcre-devel* openssl-devel* -yyum install cmake -yyum install python-devel -yyum -y install gd *openssl*
下载最新版本
wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.46.tar.gzwget http://apache.communilink.net/apr/apr-1.7.0.tar.gzwget 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/aprmv 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/aprmake&&make install
安装 apr-util
cd /path/httpd-2.4.41/srclib/apr-utilmake clean./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmake&&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-sslmake && make install
创建 apace 用户和用户组
groupadd apacheuseradd --shell /sbin/nologin -g apache apachechown -R apache:apache /usr/local/apache/
编辑 http.conf 文件
vim /usr/local/apache/etc/httpd.confServerName 0.0.0.0cd /usr/local/apache/bin/./apachectl start 启动./apachectl stop 关闭./apachectl restart 重启
添加防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanentfirewall-cmd --reload
添加 systemctl 命令
vim /lib/systemd/system/apache.service[Unit]Description=apacheAfter=network.target[Service]Type=forkingExecStart=/usr/local/apache/bin/apachectl startExecReload=/usr/local/apache/bin/apachectl restartExecStop=/usr/local/apache/bin/apachectl stopPrivateTmp=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.gztar -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-tokenizermake && make install
复制配置文件
cp php.ini-production /usr/local/php/etc/php.ini
修改配置文件
vim /usr/local/php/etc/php.inisession.save_path = "/usr/local/php/tmp"expose_php = Offdate.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