Build a PHP environment on Windows 7

Source: Internet
Author: User
Tags vc9 lmap
How to build a PHP environment in Windows 7 ??? I haven't written anything for a while. I have made some PHP stuff over the past few days. now I want to share with you how to build a PHP runtime environment, although there are a lot of one-click installation tools such as LMAP and WMAP on the Internet, I think you can understand the runtime environment of this language by yourself, and it will be more comfortable in future development. Because Linux is rarely used for development, I will install the PHP environment in Windows 7 on the Windows 7 system.

??? I haven't written anything for a while. I have made some PHP stuff over the past few days. now I want to share with you how to build a PHP runtime environment,

Although there are a lot of one-click installation tools such as LMAP and WMAP on the Internet, I think you can understand the runtime environment of this language by yourself, and it will be more comfortable in future development.

Because Linux is rarely used for development, I will introduce how to install the PHP runtime environment in Windows 7 on the local machine and share my achievements.

? First, we need to prepare the relevant runtime environment installation package. I use PHP5.3 + Apache2.2 + MySQL5.5

They are:

?

? 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

?

Here, I only use my PC for configuration. The path is my own local path. you can configure it according to your actual installation path.

?

?

1. configure Apache first (the installation steps are omitted. this is not difficult)

?

? 1. find the conf folder under the Apache installation directory. here I am C: \ Program Files (x86) \ Apache Software Foundation \ Apache2.2 \ conf and find the httpd. conf file. This is the core configuration file of Apache. we need to add the following lines:

?

# Loading the PHP processing module
LoadModule php5_module "C:/php/php5apache2_2.dll "?
# Add PHP suffixes
AddType application/x-httpd-php. php ???
PHPIniDir "C:/php"

?

Check #. the comments I wrote should also be clear. First, we need to load the PHP processing module so that it will call PHP for request processing only when accessing Apache.

If php5apache2_2.dll cannot be found in the PHP installation package, it indicates that your PHP version is incorrect.

We can see on the PHP official website that PHP has two versions: VC9 x86 Non Thread Safe and VC9 x86 Thread Safe, that is, a module with Apache and a module without Apache, you must select a ZIP package with Apache.

?

The second sentence is to add the PHP suffix, indicating that when Apache receives the content header, it is application/x-httpd-php or the suffix is. php files will be handed over to PHPIniDir for processing, so that our PHP files can be compiled through Apache and php.

?

2. change the DocumentRoot and Directory directories to the path where the webpage Directory is located. In fact, it is to customize a Workspace. in the future, PHP developers will put projects under this workspace, the browser can access the local IP address to browse all PHP projects, which is very convenient.

Here I change

?? DocumentRoot "D:/PHPWorkspace "?

??

??

?

? You can change it according to your actual situation.

?

OK. Apache configuration is complete.

?

2. configure PHP:

?

1. php. ini

?

Decompress the downloaded PHP source package to the PHP drive C (this can be placed on your own, but it is recommended that you do not place it in a too deep directory and the directory name cannot contain Chinese characters and spaces, this may make you crazy ).

?

Find the PHP under the php directory. ini-development file, which contains two similar files: php. ini-development, one is php. ini-production. we can also see from the file name that one is suitable for development and one is suitable for project release. Therefore, we modify php. ini-development, directly put the file name php. delete the file after ini (it is best to back up the file first), so it becomes php. ini, Hey, are you familiar with this configuration file. Next, open it. the one we want to modify is

?

; Extension_dir = "ext"

?

Find this sentence and change it

; Extension_dir = "C:/php/ext"

?

Which of the following is used for commenting? ;?? Remove the number.

? Extension_dir = "C:/php/ext"

?

That is, the local absolute path of ext, which is changed according to your actual situation.

The other one is to make PHP support MYSQL, which is very simple. find ??

; Extension = php_mysql.dll?

This sentence, put ;? No. removed and OK. You don't need to explain this.

?

?

? III. MYSQL (installation steps omitted)

?

In PHP. ini, we have configured to allow PHP to use MYSQL. no configuration is required here.

?, It is okay to ensure that MYSQL can be used normally.

?

IV. debugging

?

Create a php file in the previously defined workspace. the content is:

?

$ Link = mysql_connect ('localhost', 'root', 'admin ');
If (! $ Link) echo "failed! ";
Else echo "successful! ";
Mysql_close ();
?>

I believe anyone who understands PHP can understand this sentence. a database is followed by code. then we save it and enter 127.0.0.1 in the browser to access it,

We can see the php file we just created. click the link. if the output is successful, the environment is configured successfully.

?

5. FAQs:

?

1. if a download prompt box appears when you run the PHP file instead of seeing the webpage, it means that your PHP file is not recognized by Apache and handed over to PHP for processing. this problem lies in Apache httpd. the three codes in the conf file.

2. if the php file shows the webpage content but displays

?????Fatal error: Call to undefined function mysql_connect () inD: \ PHPWorkspace \ test. phpOn line2

????

???? So it indicates that your php file can be compiled and Apache is normal. the problem lies in php. ini. you are not allowed to use the MYSQL database or the ext directory is not located, that is? Extension_dir = "C:/php/ext.

3. remember to restart Apache to make the change take effect when modifying the configuration file.

?

?

?

As I am also learning, I write articles with a low technical level, but I can record the details of my learning journey. these things are only suitable for beginners, the experts are smiling .????????????????????????????????????? ?????????

???????????????????????????????????????? ???????????????????????????????????????? ???????????????????????????????????????? ??????????????????????????????? By Xiaomin

?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.