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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM