1.下載Apache和PHP
下載Apache,地址:http://www.apachelounge.com/download/,如下圖:

將下載的壓縮包解壓到某個(gè)文件夾(比如:D:\software), 將解壓后的文件夾重命名為Apache24
下載PHP壓縮包,地址:https://windows.php.net/download,(一定要下載Thread Safe版本)

將下載的壓縮包解壓到某個(gè)文件夾(比如:D:\software), 將解壓后的文件夾重命名為php
2.配置Apache
修改"D:\software\Apache24\ conf\httpd.conf "文件,修改SRVROOT
為Apache根目錄
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path. If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used. If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
Define SRVROOT "D:\software\Apache24"
ServerRoot "${SRVROOT}"
修改"D:\software\Apache24\ conf\httpd.conf "文件,末尾添加對(duì)PHP的支持及PHP的安裝路徑
# php7 support
LoadModule php_module "D:/software/php/php8apache2_4.dll"
AddType application/x-httpd-php .php .html .htm
# configure the path to php.ini
PHPIniDir "D:/software/php"
打開網(wǎng)址http://localhost/即可看到It works!,就這么愉快的配置好了服務(wù)環(huán)境

3.配置PHP
將 PHP 的根目錄下的 php.ini-development 或者 php.ini-production復(fù)制一份并改名為 php.ini,作為PHP的配置文件,取消extension_dir的注釋,即刪除前面的";"
extension_dir ="ext"
修改php.ini文件,設(shè)置默認(rèn)的時(shí)區(qū):
[Date]
; Defines the default timezone used by the date functions
; https://php.net/date.timezone
date.timezone = Asia/Shanghai
修改php.ini文件,設(shè)置 ssl :
[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
openssl.cafile= cacert.pem
修改php.ini文件,修改需要加載的擴(kuò)展文件,下面代碼是取消部分?jǐn)U展程序的注釋之后的代碼(直接復(fù)制到php.ini文件即可):
extension=php_bz2.dll
extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_exif.dll ; Must be after mbstring as it depends on it
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client
extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
;extension=php_shmop.dll
; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
;extension=php_snmp.dll
extension=php_soap.dll
extension=php_sockets.dll
extension=php_sqlite3.dll
;extension=php_sybase_ct.dll
extension=php_tidy.dll
extension=php_xmlrpc.dll
extension=php_xsl.dll
4.配置環(huán)境變量
右鍵我的電腦,屬性->高級(jí),找到最下面的環(huán)境變量按鈕,選中當(dāng)前用戶的PATH變量,編輯新建分別添加以下環(huán)境變量:
D:\software\Apache24\bin
D:\software\php
D:\software\php\ext
5.使用Apache部署php項(xiàng)目
修改"D:\software\Apache24\ conf\httpd.conf "文件,添加監(jiān)聽項(xiàng)目端口(比如:8888)
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
#Listen 80
Listen 88
Listen 8888
修改"D:\software\Apache24\ conf\httpd.conf "文件,添加服務(wù)端口(比如:8888)
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName localhost:80
ServerName localhost:88
ServerName localhost:8888
修改"D:\software\Apache24\ conf\httpd.conf "文件,取消Include conf/extra/httpd-vhosts.conf的注釋
# Real-time info on requests and configuration
Include conf/extra/httpd-info.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf
在"D:/web/php" 目錄(此目錄也可為你PHP項(xiàng)目的根目錄)下新建index.php文件內(nèi)容如下
<?php
phpinfo();
?>
修改"D:\software\Apache24\ conf\extra\httpd-vhosts.conf "文件,在文件末尾添加以下內(nèi)容
# I:/web/php是項(xiàng)目目錄
<VirtualHost _default_:8888>
DocumentRoot "D:/web/php"
<Directory "D:/web/php">
Options All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
ps:打開C:\Windows\System32\drivers\etc\hosts添加一行
127.0.0.1 www.xiatiancc.com
重啟Apache,我們打開測試下,http://www.xiatiancc.com:8888/
6.啟動(dòng)Apache服務(wù)
以管理員身份打開cmd命令行,輸入下列命令重啟Apache服務(wù),之后在瀏覽器進(jìn)入此鏈接http://localhost:8888/index.php即可看到如下效果
(初次啟動(dòng)服務(wù)需要install命令,后面修改Apache配置文件后只需要運(yùn)行restart命令即可)

httpd.exe -k install
httpd.exe -k restart

PS:
修改Apache配置文件后需要運(yùn)行httpd.exe -k restart命令重啟Apache
在命令行輸入httpd -t,可以查看是不是Apache的啟動(dòng)問題
如果報(bào)錯(cuò)說無法加載php8apache2_4.dll文件,說明下載的PHP版本不對(duì),應(yīng)該下載Thread safe版本
7.MYSQL的配置
前面將Apache和PHP關(guān)聯(lián)了起來,可以運(yùn)行php文件了,還有一個(gè)組合就是運(yùn)行MYSQL數(shù)據(jù)庫
根據(jù)自己的操作系統(tǒng)來下載,下載地址:https://dev.mysql.com/downloads/installer/
直接復(fù)制鏈接,建議使用迅雷下載:https://cdn.mysql.com//Downloads/MySQLInstaller/mysql-installer-community-8.0.31.0.msi
下載之后安裝,安裝過程忽略了,很簡單,端口3306不想默認(rèn)就自己修改。
打開php.ini
去掉注釋:
extension=mysqli
extension=pdo_mysql


然后我們連接試下,看是否成功:文章來源:http://www.zghlxwxcb.cn/news/detail-441365.html
在"D:/web/php" 目錄(此目錄也可為你PHP項(xiàng)目的根目錄)下新建2.php文件內(nèi)容如下文章來源地址http://www.zghlxwxcb.cn/news/detail-441365.html
<?php
$link = mysqli_connect("127.0.0.1","root","123456") or die("連接失??!");
if($link){
echo "數(shù)據(jù)庫連接成功";
}
?>

到了這里,關(guān)于完整的Apache+PHP8+MYSQL的配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!