Centos7源码安装Apache和PHP

源码安装Apache

安装需要的依赖

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.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar xf apr-1.7.0.tar.gz
tar xf apr-util-1.6.1.tar.gz
cd apr-1.7.0
./configure
make && make install
cd ..
cd apr-util-1.6.1
./configure --with-apr=/usr/local/apr/
make && make install
cd ..

安装Apache服务和模块

wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
tar xf httpd-2.4.41.tar.gz
cd 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 install
vim /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 httpd
chkconfig --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.gz
tar xf php-7.3.12.tar.gz
cd 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=mysqlnd
make && make install

参数解释:https://blog.csdn.net/niluchen/article/details/41513217

如果PHP不解析,用以下方法

#在apache配置文件中添加以下信息,然后重启apache
AddType application/x-httpd-php .php
DirectoryIndex index.php index.html
posted @ 2019-11-30 20:14  AKA邓紫棋  阅读(1007)  评论(0编辑  收藏  举报