Home > Backend Development > PHP Problem > How to set up a PHP environment in Windows 7 system

How to set up a PHP environment in Windows 7 system

PHPz
Release: 2023-04-21 10:39:17
Original
1304 people have browsed it

PHP is a programming language that runs on the server side and is widely used in the field of web development. Although the Windows platform is not the most commonly used deployment environment for PHP, during the development process, we still need to build a PHP environment locally. This article will introduce how to set up a PHP environment in Windows 7 system.

1. Install Apache

Apache is a popular web server software that can run on Windows systems. Therefore, we first need to install Apache. The latest stable version can be downloaded from the official website http://www.apache.org/.

During the installation process, select custom installation, ensure that Apache is installed as a service, and set the port number to 80. After the installation is completed, start Apache.

2. Install PHP

Download the latest stable version of PHP from the PHP official website https://windows.php.net/download/. After the download is completed, unzip it to the Apache installation directory (the default is C:\Program Files (x86)\Apache Group\Apache2\, hereinafter referred to as the Apache root directory).

In the Apache root directory, find the httpd.conf file and open it. Search for "LoadModule", find the following two lines, and delete the comment character # in front of them to make them effective.

LoadModule php7_module "C:/Program Files (x86)/PHP/php7apache2_4.dll"
AddHandler application/x-httpd-php .php

Then, add the following at the end of the file Content:

PHPIniDir "C:/Program Files (x86)/PHP/"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Save the file and restart Apache.

3. Test the PHP environment

In the Apache root directory, create a new file test.php and enter the following content in it:

phpinfo();
?>

Save the file and upload test.php to the Apache root directory.

Open the browser and visit http://localhost/test.php. If the browser displays the phpinfo information form, it proves that the PHP environment has been set up successfully.

4. Configure PHP

In Windows 7 system, the PHP configuration file is php.ini. In the PHP installation directory, you can find a php.ini-development file, copy it and rename it to php.ini.

Open the php.ini file, search for "extension_dir", and change its corresponding path to the ext folder in the current PHP installation directory. For example, if PHP is installed in C:\Program Files (x86)\PHP, then set extension_dir to: extension_dir="C:\Program Files (x86)\PHP\ext"

Then, search for "; extension=php_mysql.dll", delete the comment character # in front of it and enable the MySQL extension module.

Finally, save the file and restart Apache.

5. Install MySQL

MySQL is a relational database software that can be easily integrated with PHP. Download the latest stable version from the MySQL official website https://dev.mysql.com/downloads/mysql/.

During the installation process, select custom installation, select the Typical installation type, and set a password. After the installation is complete, start MySQL.

6. Test the connection between PHP and MySQL

In the Apache root directory, create a new file testmysql.php and enter the following content in it:

$con = mysqli_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysqli_error()) ;
}
echo 'Connected successfully';
mysqli_close($con);
?>

Change the "Password" column in the above code to your own MySQL administrator password.

Save the file and upload testmysql.php to the Apache root directory.

Open the browser and visit http://localhost/testmysql.php. If the browser displays "Connected successfully", it proves that the connection between PHP and MySQL has been successful.

7. Summary

This article introduces how to build a PHP environment in Windows 7 system, and achieves a A complete web development environment. The content introduced in this article is suitable for beginners, but for developers with certain experience, you can further understand the implementation principles of PHP development by adjusting configuration files.

The above is the detailed content of How to set up a PHP environment in Windows 7 system. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template