安装需要的依赖
yum -y install gcc autoconf automake make pcre pcre-devel openssl openssl-devel#pcre是正则表达式库#openssl是安全通信的库
安装apr和apr-until
#apr是Apache可移植运行时#apr-until是Apache可移植运行时实用程序库wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gzwget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gztar xf apr-1.7.0.tar.gztar xf apr-util-1.6.1.tar.gzcd apr-1.7.0./configuremake && make installcd ..cd apr-util-1.6.1./configure --with-apr=/usr/local/apr/make && make installcd ..
安装Apache
服务和模块
wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.gztar xf httpd-2.4.41.tar.gzcd httpd-2.4.41./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl --enable-rewrite --with-mpm=worker --with-suexec-bin --with-apr=/usr/local/apr/make && make installvim /usr/local/apache2/conf/httpd.conf #Apache配置文件/usr/local/apache2/bin/apachectl start #启动Apache服务/usr/local/apache2/bin/apachectl stop #停止
选项 | 描述 |
---|---|
--prefix | 指定 Apache httpd 程序的安装主目录 |
--enable-so | 开启模块化功能,支持DSO(动态共享对象) |
--enbale-ssl | 支持 SSL 加密 |
--enable-rewrite | 支持地址重写 |
--with-mpm | 设置 Apache httpd 工作模式 |
--with-suexec-bin | 支持 SUID、SGID |
--with-apr | 指定 apr 程序的绝对路径 |
将其设置为开机启动
mv /root/httpd-2.4.41/build/rpm/httpd.init /etc/rc.d/init.d/httpd #从源码包移动脚本到启动目录vim /etc/rc.d/init.d/httpd #修改以下内容 httpd=${HTTPD-/usr/local/apache2/bin/httpd} pidfile=${PIDFILE-/usr/local/apache2/logs/${prog}.pid} CONFFILE=/usr/local/apache2/conf#在/etc/rc.d/init.d目录下运行,以下命令chkconfig --add httpdchkconfig --level 2345 httpd on #设置为开机启动chkconfig --list #可以看到httpd已经添加到开机启动,且2345为on
源码安装PHP
安装依赖
yum -y install libxml2 libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel
安装PHP和所需模块
wget https://www.php.net/distributions/php-7.3.12.tar.gztar xf php-7.3.12.tar.gzcd php-7.3.12./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-libxml-dir --with-curl --with-gd --with-openssl --enable-sockets --with-pear --enable-exif --with-mysqli=mysqlnd --with-pdo-mysql=mysqlndmake && make install
参数解释:https://blog.csdn.net/niluchen/article/details/41513217
如果PHP不解析,用以下方法
#在apache配置文件中添加以下信息,然后重启apacheAddType application/x-httpd-php .phpDirectoryIndex index.php index.html