Apache2.4.46 + PHP 7.4.5 源码编译安装

Apache2.4.46 + PHP 7.4.5

apache

  1. 安装依赖

    1. yum clean all
    2. yum update -y
    3. yum install expat-devel -y
    4. yum groupinstall base -y
    5. yum grouplist -y
    6. yum groupinstall 'Development tools' -y
    7. yum groupinstall 'Debugging Tools' -y
    8. yum groupinstall 'Compatibility libraries' -y
    9. yum install pcre* pcre-devel* openssl-devel* -y
    10. yum install cmake -y
    11. yum install python-devel -y
    12. yum -y install gd *openssl*
  2. 下载最新版本

    1. wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
    2. wget http://apache.communilink.net/apr/apr-1.7.0.tar.gz
    3. wget http://apache.communilink.net/apr/apr-util-1.6.1.tar.gz
  3. 解压以上三个文件包

  4. 将 apr 、 apr-util 移动到 httpd-2.4.41/srclib/ 目录下

    1. mv apr-1.7.0 httpd-2.4.41/srclib/apr
    2. mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-util
  5. 安装 apr

    1. cd /path/httpd-2.4.41/srclib/apr
    2. ./configure --prefix=/usr/local/apr
    3. make&&make install
  6. 安装 apr-util

    1. cd /path/httpd-2.4.41/srclib/apr-util
    2. make clean
    3. ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    4. make&&make install
  7. 安装 httpd

    1. cd /path/httpd-2.4.41
    2. ./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
    3. make && make install
  8. 创建 apace 用户和用户组

    1. groupadd apache
    2. useradd --shell /sbin/nologin -g apache apache
    3. chown -R apache:apache /usr/local/apache/
  9. 编辑 http.conf 文件

    1. vim /usr/local/apache/etc/httpd.conf
    2. ServerName 0.0.0.0
    3. cd /usr/local/apache/bin/
    4. ./apachectl start 启动
    5. ./apachectl stop 关闭
    6. ./apachectl restart 重启
  10. 添加防火墙

    1. firewall-cmd --zone=public --add-port=80/tcp --permanent
    2. firewall-cmd --reload
  11. 添加 systemctl 命令

    1. vim /lib/systemd/system/apache.service
    2. [Unit]
    3. Description=apache
    4. After=network.target
    5. [Service]
    6. Type=forking
    7. ExecStart=/usr/local/apache/bin/apachectl start
    8. ExecReload=/usr/local/apache/bin/apachectl restart
    9. ExecStop=/usr/local/apache/bin/apachectl stop
    10. PrivateTmp=true
    11. [Install]
    12. WantedBy=multi-user.target
    13. // 命令
    14. systemctl enable apache //
    15. systemctl start|stop|restart apache

参考

https://www.osyum.com/article/show/379/

PHP

  1. 安装依赖

    1. 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
  2. 下载最新版

    1. wget https://www.php.net/distributions/php-7.4.5.tar.gz
    2. tar -xvf php-7.4.5.tar.gz
  3. 明确 apsx 路径

    1. find / -name 'apxs*'
    2. /usr/local/apache/bin/apxs

    整合 apache,apxs功能是使用mod_so中的LoadModule指令,加载指定模块到 apache,要求 apache 要打开SO模块

  4. 检测

    1. ./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
    2. make && make install
  5. 复制配置文件

    1. cp php.ini-production /usr/local/php/etc/php.ini
  6. 修改配置文件

    1. vim /usr/local/php/etc/php.ini
    2. session.save_path = "/usr/local/php/tmp"
    3. expose_php = Off
    4. 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

  1. 检测加载php模块,这个在安装php后会自动修改,检查一下就行

    1. LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so
  2. 修改配置

    1. <FilesMatch \.php$>
    2. SetHandler application/x-httpd-php
    3. </FilesMatch>
    4. <IfModule dir_module>
    5. DirectoryIndex index.html index.php
    6. </IfModule>
  3. 重启 Apache



评论 0

发表评论

Top