完整的Apache+PHP8+MYSQL的配置
创始人
2024-05-21 14:22:35
0

1.下载Apache和PHP

下载Apache,地址:http://www.apachelounge.com/download/,如下图:

将下载的压缩包解压到某个文件夹(比如:D:\software), 将解压后的文件夹重命名为Apache24

下载PHP压缩包,地址:https://windows.php.net/download,(一定要下载Thread Safe版本)

将下载的压缩包解压到某个文件夹(比如:D:\software), 将解压后的文件夹重命名为php

2.配置Apache

  1. 修改"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}"
  1. 修改"D:\software\Apache24\ conf\httpd.conf "文件,末尾添加对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"
  1. 打开网址http://localhost/即可看到It works!,就这么愉快的配置好了服务环境

3.配置PHP

  1. 将 PHP 的根目录下的 php.ini-development 或者 php.ini-production复制一份并改名为 php.ini,作为PHP的配置文件,取消extension_dir的注释,即删除前面的";"

extension_dir ="ext"
  1. 修改php.ini文件,设置默认的时区:

[Date]
; Defines the default timezone used by the date functions
; https://php.net/date.timezone
date.timezone = Asia/Shanghai
  1. 修改php.ini文件,设置 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
  1. 修改php.ini文件,修改需要加载的扩展文件,下面代码是取消部分扩展程序的注释之后的代码(直接复制到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.dllextension=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.配置环境变量

右键我的电脑,属性->高级,找到最下面的环境变量按钮,选中当前用户的PATH变量,编辑新建分别添加以下环境变量:

D:\software\Apache24\bin

D:\software\php

D:\software\php\ext

5.使用Apache部署php项目

  1. 修改"D:\software\Apache24\ conf\httpd.conf "文件,添加监听项目端口(比如:8888)


#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the 
# 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
  1. 修改"D:\software\Apache24\ conf\httpd.conf "文件,添加服务端口(比如: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
  1. 修改"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
  1. 在"D:/web/php" 目录(此目录也可为你PHP项目的根目录)下新建index.php文件内容如下


  1. 修改"D:\software\Apache24\ conf\extra\httpd-vhosts.conf "文件,在文件末尾添加以下内容

# I:/web/php是项目目录
DocumentRoot "D:/web/php"Options AllAllowOverride AllRequire all granted

6.启动Apache服务

以管理员身份打开cmd命令行,输入下列命令重启Apache服务,之后在浏览器进入此链接http://localhost:8888/index.php即可看到如下效果

(初次启动服务需要install命令,后面修改Apache配置文件后只需要运行restart命令即可)

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

PS:

修改Apache配置文件后需要运行httpd.exe -k restart命令重启Apache

在命令行输入httpd -t,可以查看是不是Apache的启动问题

如果报错说无法加载php8apache2_4.dll文件,说明下载的PHP版本不对,应该下载Thread safe版本

7.MYSQL的配置

前面将Apache和PHP关联了起来,可以运行php文件了,还有一个组合就是运行MYSQL数据库

根据自己的操作系统来下载,下载地址:https://dev.mysql.com/downloads/installer/

直接复制链接,建议使用迅雷下载:https://cdn.mysql.com//Downloads/MySQLInstaller/mysql-installer-community-8.0.31.0.msi

下载之后安装,安装过程忽略了,很简单,端口3306不想默认就自己修改。

打开php.ini

去掉注释:

extension=mysqli
extension=pdo_mysql

然后我们连接试下,看是否成功:

在"D:/web/php" 目录(此目录也可为你PHP项目的根目录)下新建2.php文件内容如下

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
一帆风顺二龙腾飞三阳开泰祝福语... 本篇文章极速百科给大家谈谈一帆风顺二龙腾飞三阳开泰祝福语,以及一帆风顺二龙腾飞三阳开泰祝福语结婚对应...
美团联名卡审核成功待激活(美团... 今天百科达人给各位分享美团联名卡审核成功待激活的知识,其中也会对美团联名卡审核未通过进行解释,如果能...