很久没用PHP了,最近重拾。
MySQL
https://dev.mysql.com/downloads/installer/
下载
mysql-installer-community-5.7.21.0.msi
安装
基本没什么问题
PHP
http://windows.php.net/download/
下载的VC15 Thread Safe 64位版本Zip包
下载到本地后,解压到某路径,貌似不能有空格
然后复制一份php.ini-development改名为php.ini
取消注释extension_dir,切值为php根目录中的ext路径,此处应为绝对路径,例如
extension_dir = "d:/php/ext"
取消注释extension=mysqli,extension=pdo_mysql
Apache
https://www.apachelounge.com/download/
下载php对应的VC、x64 or x86的apache Zip
解压到某路径
修改config/httpd.conf
修改apache软件所在目录:
ServerRoot "D:/Apache24"
修改主机名:
ServerName localhost:80
修改www目录:
DocumentRoot "D:/www"
<Directory "D:/www">
修改默认索引以支持PHP:
DirectoryIndex index.php index.html index.htm
开启rewrite功能:
LoadModule rewrite_module modules/mod_rewrite.so
自定义404页面(可选):
ErrorDocument 404 /missing.html
加载PHP模块:
#php7
LoadModule php7_module D:/php/php7apache2_4.dll
<IfModule php7_module>
PHPIniDir "D:/php/"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>
开启url重写
<Directory />
AllowOverride All
Require all denied
</Directory>
<Directory "F:/PHPProject/ServerRoot">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
第一次貌似需要install,不确定
D:\Apache24\bin>httpd.exe -k install
启动Apache
D:\Apache24\bin>httpd.exe -k start
stop停止
restart重启
Apache会自动启用PHP,不必像Nginx手动开启
遇到的问题
1、ThinkPHP报 Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' 错误
基本是因为PHP配置中关于mysql的配置错误造成的
一个是
extension_dir = "d:/php/ext"
是否是绝对路径,此处如果为相对路径,则会出问题。
再有是否取消注释extension=mysqli,extension=pdo_mysql,这两个都需要取消注释
2、只能访问主页,不能访问其他路径,报The requested URL /xxxx was not found on this server