最近又要开始用 PHP 做开发,每次都要查一遍怎么安装配置环境,各个地方写的还不一样很烦。自己写。
Apache
- 进入官网,打开
Download页面
,下载最新版的压缩包; - 解压到自己想安装的目录下,我这里是放到了
F:\Program Files\Apache
中; - 进入
F:\Program Files\Apache\conf
目录,编辑器打开httpd.conf
文件。修改如下部分:
line 37: ServerRoot "c:/Apache24" -> ServerRoot "F:/Program Files/Apache"
line 58: Listen 80 -> Listen 8080
line 218: ServerName www.example.com:80 -> ServerName www.example.com:8080
line 242: DocumentRoot "c:/Apache24/htdocs" -> DocumentRoot "F:/Projects/php"
line 243: <Directory "c:/Apache24/htdocs"> -> <Directory "F:/Projects/php">
line 276: DirectoryIndex index.html -> DirectoryIndex index.php index.htm index.html
line 359: ScriptAlias /cgi-bin/ "c:/Apache24/cgi-bin/" -> ScriptAlias /cgi-bin/ "F:/Program Files/Apache/cgi-bin"
line 375: <Directory "c:/Apache24/cgi-bin"> -> <Directory "F:/Program Files/Apache/cgi-bin">
- 加上对PHP的支持,在文件末尾加上下面的内容:
# php5 support
LoadModule php5_module "F:/Program Files/php/php5apache2_4.dll"
PHPIniDir "F:\Program Files\php"
AddType application/x-httpd-php .php .html .htm
# configure thepath to php.ini
如此,Apache 就配置完成。
PHP
- 进入官网,在
Download
找到下载链接,下载压缩包; - 解压到自己想安装的目录下,我这里是放到了
F:\Program Files\php
中; - 进入
F:\Program Files\php
目录,将php.ini-development
重命名为php.ini
,并用编辑器打开这个文件。修改如下部分:
line 736: extension_dir = "ext" -> extension_dir = "F:/Program Files/php/ext"
line 807: upload_tmp_dir = -> upload_tmp_dir = "/upload-files"
line 881: ;extension=php_curl.dll -> extension=php_curl.dll
line 883: ;extension=php_gd2.dll -> extension=php_gd2.dll
line 890: ;extension=php_mbstring.dll -> extension=php_mbstring.dll
line 892: ;extension=php_mysql.dll -> extension=php_mysql.dll
line 895: ;extension=php_openssl.dll -> extension=php_openssl.dll
line 897: ;extension=php_pdo_mysql.dll -> extension=php_pdo_mysql.dll
line 899: ;extension=php_pdo_odbc.dll -> extension=php_pdo_odbc.dll
line 915: ;extension=php_xmlrpc.dll -> extension=php_xmlrpc.dll
line 930: ;date.timezone = -> date.timezone = Asia/Chongqing
line 1417: ;session.save_path = "/tmp" -> session.save_path = "/session"
并在line 892
后添加:extension=php_mysqli.dll
- 进入 xdebug官网,打开
Download页面
,下载对应系统和PHP版本的dll文件; - 将下载好的dll放入
F:\Program Files\php\ext
中; - 继续编辑
php.ini
,在文件末尾添加如下内容:
[XDebug]
zend_extension = "F:\Program Files\php\ext\php_xdebug-2.3.3-5.6-vc11-x86_64.dll"
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "F:\Program Files\php\xdebug"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.trace_output_dir = "F:\Program Files\php\xdebug"
- 在firefox安装easiest Xdebug插件;
- 启动phpstorm的电话筒监听;
- 启动xdebug插件
- 设置程序调试断点即可
至此,配置完成。MySQL太简单,就不写了。