php环境配置
注意:配置过程中使用的输入均为英文输入,尤其是标点符号的双引号,文中可能为中文引号,一旦直接复制粘贴,可能导致配置失败!!! 还有,如果在windows的文件夹系统直接复制路径,文件夹之间是反斜线(\),但是配置中使用的均为斜线(/),请不要输入错
注意:配置过程中使用的输入均为英文输入,尤其是标点符号的双引号,文中可能为中文引号,一旦直接复制粘贴,可能导致配置失败!!!
还有,如果在windows的文件夹系统直接复制路径,文件夹之间是反斜线(\),但是配置中使用的均为斜线(/),请不要输入错误。
PHP配置
首先进入PHP解压的目录,找到php.ini-development配置文件,并将其重命名为php.ini,该文件即为当前系统php的配置文件。打开php.ini配置文件,根据下面提示进行配置。
找到如下内容
; On windows:
; extension_dir = "ext"
修改为
; On windows:
extension_dir = "E:/ProgramFiles (x86)/PHP/ext"
请注意,extension_dir前面的分号需要去掉,另外将值修改为PHP文件夹下的ext文件夹路径,该配置用于更新PHP扩展路径文件夹,所有的扩展库都在该文件夹中。
接着,我们需要让PHP支持MySQL数据库,并开启如CURL,GD2,XML,PDO等扩展,找到如下内容,将其前面的分号(;)去掉。
extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
extension=php_pdo_odbc.dll
extension=php_xmlrpc.dll
我们都知道PHP支持session功能,默认的,PHP的session是保存在文件系统中的,那么我们需要为Session设置保存文件夹。
找到如下内容
; session.save_path = "/tmp"
修改为
session.save_path = "E:/Program Files (x86)/PHP/custom/session"
将分号取出,并重新设置任意路径,确保文件夹存在即可,为了管理方便,建议你设置到PHP的安装路径当中,防止不小心给删掉。
完成session设置之后,我们还需要配置一个文件夹路径,即PHP的临时文件路径,学习PHP的同学都知道,在通过PHP上传文件时,文件首先是在一个临时文件夹当中的。
找到如下内容
; upload_tmp_dir =
修改为
upload_tmp_dir = "E:/Program Files (x86)/PHP/custom/upload"
最后,PHP在5.3版本之后需要强制设置时区,否则在运行phpinfo()及部分程序时将报错无法运行。
找到如下内容
;date.timezone =
修改为
date.timezone = Asia/Shanghai
配置Apache支持PHP
在Apache配置目录E:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf中(这是我的安装目录,请注意windows下直接复制的路径使用反斜线做分隔符,配置文件中全部是使用斜线做分隔符,请千万注意!),找到httpd.conf配置文件。
在
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
下面一行添加如下内容。
LoadModule php5_module "E:/Program Files (x86)/PHP/php5apache2_2.dll"
PHPIniDir "E:/Program Files (x86)/PHP"
AddType application/x-httpd-php .php .html .htm
该配置第一行指定PHP及Apache的模块路径,该模块文件一般位于php根目录下,第二行用于指定PHP在Win7中的路径,第三行添加文件类型,其中,第一及第二行需要根据PHP的安装路径进行修改。
接着,我们需要为Apache指定WEB服务器的根目录,默认的,Apache根目录为Apache目录下的htdocs文件夹,为了方便开发,我们将其设置在E盘下的htdocs目录。首先在E盘下建立htdocs目录,当然你也可以修改为任意你想命名的WEB根目录,然后,在配置文件中分别找到如下内容。
DocumentRoot "E:/Program Files (x86)/ApacheSoftwareFoundation/Apache2.2/htdocs"
修改为
DocumentRoot "E:/htdocs"
最后,修改根目录的初始文件类型,Apache默认使用index.html作为目录的初始文件,这里为了让Apache首先寻找php文件,我们做些修改。
找到如下内容
DirectoryIndex index.html
修改为
DirectoryIndex index.php index.html
到此,Apache支持PHP的相关配置完成,重启服务器,在新的目录中创建index.php文件,并写入如下内容。
phpinfo();
?>
再次打开浏览器,访问localhost,一切正常的话,就会显示php的相关配置信息了,如下图所示。
PHP配置信息
测试PHP对MySQL的支持
最后我们需要测试下PHP是否已经能够连接数据库,我们在配置过程中,曾经将;extension=php_mysql.dll等一系列与MySQL相关的扩展之前的分号给去除,这样PHP就能够通过这些扩展完美支持相应的程序。在根目录中创建mysql.php文件,并写入如下内容。
$dbc= mysql_connect("127.0.0.1","root","(你的mysql密码)");
if(!$dbc) {
echo"数据库链接错误!";
}else{
echo"PHP环境搭建:Windows7系统配置PHP+Apache+MySQL环境教程";
}
mysql_close();
?>
在浏览器中访问,127.0.0.1/mysql.php,如果提示“PHP环境搭建:Windows7系统配置PHP+Apache+MySQL环境教程”,则说明PHP已经完美支持MySQL了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
