时隔多年搭建win php apache mysql笔记
2018-02-20 14:22
148 查看
很久没用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
基本是因为Apache URL重写配置错误
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
基本是因为Apache URL重写配置错误
相关文章推荐
- 关于在win下搭建apache+php+mysql环境的笔记
- Windows下搭建wamp(win apache mysql php)环境
- win环境20分钟搭建php+sql服务器Apache+php+mysql在windows下的安装与配置图解
- php apache mysql服务器搭建学习笔记
- php开发环境搭建 win 7 + apache + mysql
- Win 7(64位) apache+php+mysql环境搭建
- php学习笔记1--开发环境搭建:apache+php+mysql
- Mac OS Apache MySQL PHP (mamp)环境搭建笔记
- win10.64位搭建Php开发环境(PHP7.0.11+Apache2.4.23+Mysql-5.7.15 )安装配置图文教程
- Apache+PHP+MySQL环境搭建笔记
- apache+mysql+php开发环境搭建笔记
- Mac OS Apache MySQL PHP (mamp)环境搭建笔记
- Ubuntu下LAMP环境搭建 Apache、MySQL、PHP
- Apache+PHP+MySQL环境搭建
- Windows 2003搭建Apache PHP MySQL环境经验分享
- 搭建LAMP(Linux + Apache + Mysql + PHP/Perl/Python)站点
- Lamp(linux+apache+mysql+php)环境搭建
- ios程序员容易上手的服务器程序php入门【apache+php+mysql】开发环境搭建(一)
- win平台下 MySql+PHP+Apache+Openssl
- FreeBSD 安装Mysql apache PHP 个人笔记