首先官网下载php环境,解压到任意目录并将目录添加到环境变量Path
启动项目
将目录中的 php.ini-development 文件或者 php.ini-production 文件复制出来一份,修改后缀为.ini 完整的文件名为php.ini,该文件为启动的配置文件。
php -S localhost:8000 -t public -c D:\xxx\php.ini
其中参数: -S 指定地址,-t 指定启动目录 -c 指定配置文件(php.ini)地址
如果启动后页面提示报错,常见的缺少引用错误如下:
Fatal error: Call to undefined function mb_strtolower()
修改配置文件
由于php的一些扩展模块需要手动启用,编辑php.ini文件
php.ini 的每一行的开头的”;”为注释符号,类似与windows环境的配置文件中的”#”
首先找到
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
;extension_dir = "./"
; On windows:
; extension_dir = "ext"
由于我们是window环境,将 extension_dir = "ext"
取消注释,修改为如下
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
;extension_dir = "./"
; On windows:
extension_dir = "ext"
````
*注:extension_dir 配置的是可使用扩展模块的保存目录*
然后根据找到下面的位置
``` ini
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename
;
; For example:
;
; extension=mysqli
;
; When the extension library to load is not located in the default extension
; directory, You may specify an absolute path to the library file:
;
; extension=/path/to/extension/mysqli.so
;
; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
;
; Notes for Windows environments :
;
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
; extension folders as well as the separate PECL DLL download (PHP 5+).
; Be sure to appropriately set the extension_dir directive.
;
;
;extension=bz2
;extension=curl
;extension=ffi
;extension=ftp
;extension=fileinfo
;extension=gd2
;extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=ldap
;extension=mbstring
;extension=exif ; Must be after mbstring as it depends on it
;extension=mysqli
;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
;extension=odbc
;extension=openssl
;extension=pdo_firebird
;extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
;extension=pdo_sqlite
;extension=pgsql
;extension=shmop
; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
;extension=snmp
;extension=soap
;extension=sockets
;extension=sodium
;extension=sqlite3
;extension=tidy
;extension=xmlrpc
;extension=xsl
可以看到加载扩展可以分为两种
- 扩展模块在我们上面配置的文件夹中,可以使用下面的写法
extension=modulename
例:
extension=mysqli
- 扩展模块不在我们上面配置的默认文件夹中,使用完整路径
extension=/path/to/extension/mysqli.so
另外好需要注意,如果扩展有依赖,需要注意引用的先后顺序,同一扩展不能多次引用。根据需要取消上面的注释即可。
修改完成之后需要重新启动.