基本環境:CentOS7 PHP7.3.8 Apache(httpd2.4.39)
第一步:源碼編譯PHP的configure需要增加Apche相關配置
#./cofigure --prefix=/usr/local/php --with-apxs2=/usr/local/apche/bin/apxs
第二步:將php源文件根目錄下的php.ini-production文件拷貝至安裝文件中。本環境中php源目錄為/source/php-7.3.8,安裝目錄為/usr/local/php
#cp /source/php-7.3.8/php.ini-production /usr/local/php/lib/php.ini
第三步:Apache中httpd.conf配置文件下增加指令
<FilesMatch "\.ph(p[2-6]?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
這段指令告訴apache,碰到文件名以.php, .php2, .php3, .php4, .php5, .php6或phtml結尾的文件使用libphp7.so模塊進行解析
第四步:編寫index.php文件進行測試,文件內容
<?php
phpinfo();
?>
第五步:html中有php語句,無法解析
在Apache配置文件httpd.conf中增加如下命令即可
AddHandler php7-script .php .html
AddType text/html .php .html