Windows 7 上PHP环境搭建
Windows 7 下PHP环境搭建
??? 有一段时间没有写东西了,这几天弄了点PHP的东西,现在给大家分享个PHP的运行环境搭建,
虽然网上有很多LMAP和WMAP一类的一键安装工具,但是我认为,还是自己动手,才能理解这门语言的运行环境,在以后的开发中更游刃有余。
因为在Linux中开发用得比较少,我下面就本机的Windows 7 系统下安装PHP运行环境给大家做个介绍,分享一下我的成果。
?首先,我们要准备好相关的运行环境安装包,我用的是PHP5.3 + Apache2.2+ MySQL5.5
下载地址分别是:
?
?PHP:http://windows.php.net/downloads/releases/php-5.4.7-Win32-VC9-x86.zip
Apache:http://mirror.bjtu.edu.cn/apache//httpd/binaries/win32/httpd-2.2.22-win32-x86-no_ssl.msi
MySQL:http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28-win32.msi
?
这里我仅拿本人PC进行配置,路径是我自己的本机路径,各位可以按照自己实际安装路径进行配置。
?
?
一、我们先来配置Apache(安装步骤就省略了,这个不难)
?
?1、找到Apache安装目录下的conf文件夹,我这里是C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf,找到httpd.conf文件。这个是Apache的核心配置文件,我们需要增加以下几行:
?
#加载PHP处理模块
LoadModule php5_module "C:/php/php5apache2_2.dll"?
#添加PHP后缀的处理
AddType application/x-httpd-php .php???
PHPIniDir "C:/php"
?
看#号我写的注释大家应该也明白了,先是要加载PHP的处理模块,这样访问Apache的时候它才会调用PHP进行请求处理。
如果在PHP安装包中找不到php5apache2_2.dll,那么说明你下的PHP版本不对
我们在PHP官网看到,PHP分两个版本,一个是VC9 x86 Non Thread Safe ,一个是VC9 x86 Thread Safe ,就是说一个带Apache模块,一个不带Apache模块,这里一定要注意选择带Apache的ZIP包。
?
然后第二句是添加PHP后缀的处理,表示当Apache接收到内容头为application/x-httpd-php 或后缀为.php的文件时,将交给PHPIniDir 下的相关进行处理,这样我们的PHP文件就能通过Apache然后让PHP进行编译了。
?
2、将DocumentRoot 与 Directory 目录均改为网页目录所在路径,其实就是自定义一个工作空间,以后开发PHP都把项目放到这个工作空间下,浏览器访问本地IP就可以浏览所有的PHP项目了,非常方便。
我这里改为
?? DocumentRoot "D:/PHPWorkspace"?
??
??
?
? 大家按自己实际情况改。
?
OK,Apache方面配置完成。
?
二、然后来配置PHP:
?
1、 php.ini
?
将下载好的PHP源包解压到C盘PHP下(这个可以自己放位置,但建议不要放到太深层的目录以及目录名不能包含中文和空格,这可能会让你郁闷到抓狂)。
?
然后找到PHP目录下的php.ini-development文件,这里有两个相似的文件,一个是php.ini-development,一个是php.ini-production,从文件名我们也可以看出来,一个是适合开发用的,一个适合项目发布用的,所以,我们修改php.ini-development这个文件,直接把文件名php.ini后面的删掉(最好先备份),这样就变成了php.ini,嘿嘿,是不是很熟悉呢,对的,我们要的就是这个配置文件。接着打开它,我们要修改的一个是
?
;extension_dir="ext"
?
查找到这句,然后改成
;extension_dir = "C:/php/ext"
?
并且把前面作注释用的? ;?? 号 去掉,就变成了这样
?extension_dir = "C:/php/ext"
?
即ext的本地绝对路径,这个按照自己的实际情况改。
然后还有一个就是让PHP支持MYSQL,很简单,找到??
;extension=php_mysql.dll?
这句,把 ;? 号去掉就OK了。这个不用解释了吧。
?
?
?三、MYSQL(安装步骤省略)
?
前面在PHP.ini 中我们已经配置好了允许PHP使用MYSQL,这里就不需要任何配置了
?,只要保证MYSQL是能正常使用的就OK了
?
四、调试
?
我们在之前定义的工作空间下新建个PHP文件,内容是:
?
$link=mysql_connect('localhost','root','admin');
if(!$link) echo "失败!";
else echo "成功!";
mysql_close();
?>
相信懂PHP的人都看得懂这句话,一句数据库接连代码,然后我们保存,浏览器输入127.0.0.1访问一下,
就可以看到我们刚才新建的PHP文件,点击链接进去如果输出成功, 那么我们的环境就配置成功了。
?
五、常见问题:
?
1,如果运行PHP文件时没有看到网页而是出现下载提示框 ,那么就说明你的PHP文件没有被Apache识别并交给PHP进行处理,这个问题出在Apache的httpd.conf文件中的那三句代码。
2、如果PHP文件能看到网页内容但是显示
????? Fatal error: Call to undefined function mysql_connect() in D:\PHPWorkspace\test.php on line 2
????
???? 那么就表示你的PHP文件已经能被编译,Apache方面已经正常了,问题出在php.ini,没有允许使用MYSQL数据库或是ext目录没有被定位到,即?extension_dir = "C:/php/ext"的问题。
3、记得修改一般修改配置文件的时候都要重启Apache让更改生效。
?
?
?
由于本人也是正在学习的过程中,写的文章技术含量不高,但能记录我学习旅途上的点点滴滴,这些东西仅适合于新手,高手见笑了。??????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????By 小敏
?

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 uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

Deploying Hadoop Distributed File System (HDFS) on a CentOS system requires several steps, and the following guide briefly describes the configuration process in stand-alone mode. Full cluster deployment is more complex. 1. Java environment configuration First, make sure that the system has Java installed. Install OpenJDK with the following command: yumininstall-yjava-1.8.0-openjdk-devel Configure Java environment variables: echo "exportJAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk">>/etc/profileecho"ex
