Configuring PHP under the Windows operating system Apache server

Source: Internet
Author: User

Before the PHP project is published on the Apache Web server, it needs to be configured so that the server can parse the PHP text and display the contents of the PHP dynamic page normally. The Apache server has been installed by default in the Windows system before the PHP configuration, and the server is functioning properly, that is, the published static HTML page can be accessed via an IP address or domain name. Under Windows installation configuration Apache, refer to: Install Apache server under Windows.

1.PHP Downloads

Go to the PHP download page http://php.net/downloads.php, select the version you want to download, click Windows Downloads, go to the download page, download the thread safe version (Note: thread Safe with Apache server, non thread safe with IIS server), download complete is a zip compressed file.

2.PHP Configuration

Unzip the folder, go to the PHP root directory, copy the php.ini-development to the root directory, copy it to backup, and change the copy name to PHP.ini.

Open php.ini with Notepad, press ctrl+f, find Extension_dir, and change the value of Extension_dir to the absolute path of ext under the PHP root, for example: Extension_dir = "C : \program Files\php-7.0.8-win32-vc14-x86\ext" , note to remove the semicolon in front of the Extension_dir (Figure 2.1).

Figure 2.1

The same way to find the "extension" parameter, similar to, Extension=php_pdo_mysql.dll , according to their own project requirements to modify the parameter value, such as the need to make PHP support MySQL, you need to ; extension =php_mysqli.dll and Extension=php_pdo_mysql.dll in front of the semicolon (Figure 2.2).

Figure 2.2

Configure the time zone, locate the Date.timezone parameter, change its value to PRC (indicated as China's standard Time), and remove the semicolon preceding the parameter.

Figure 2.3

3. Configure Environment variables

Right-click the "Computer" Property Change settings "Advanced" environment variable, find the path in the system environment variable, add the absolute path of the PHP root directory and the absolute path of the Ext folder under the PHP root directory, save the settings. Note that you append the environment variable value (Figure 2.4) to save the settings.

Figure 3.1

4. Configure Apache

PHP text represents a Dynamic Web page, the Apache server needs to be configured to be able to follow certain rules to resolve the. php file, and then send the parsed content to the client browser, displaying what we want to see, otherwise the PHP code for the. php file is displayed in the browser.

Locate the httpd.conf file in the Conf folder in the Apache root directory and have Notepad open, add the following three attributes anywhere in the file (Figure 4.1), and note that the attribute values should be changed according to the directory where PHP is located. Enables Apache to load PHP modules and parse PHP files.

" C:\Program Files\php-7.0.8-win32-vc14-x86\php7apache2_4.dll "  "C:\Program files\php-7.0.8-win32-vc14-x86"AddType application/ x-httpd-php. php. html. htm

Figure 4.1

Similarly, find the directoryindex inside the <ifmodule dit_module> tag in the httpd.conf file, adding index.php behind it (Figure 4.2) so that index.php can be used as the default document. That is, enter the IP address to automatically first display the index.php content of the resolution.

Figure 4.2

5. Deploy one of the simplest PHP projects

Create a new index.php text file in any location in the system, and enter the following to save it. The file is the first page of our project and is the only one for the entire project O (∩_∩) o~~.

<? PHP Phpinfo ();? >

Open the httpd.conf file in the Conf folder in the Apache root directory, locate the DocumentRoot and directory properties, and change these values to the path where our project directory is located and save. For example, if the project is in the same folder as C:\myapp and the file index.php in the folder, the value should be changed to the following form (Figure 4.3) to save the file.

" C:/myapp " " C:/myapp ">

Figure 4.3

Restart the Apache server, enter the computer's IP address and port number in the browser (I host IP address is ***.***.***.28, port number is 88), If you can display a page similar to the following (Figure 4.4), then the Apache server configuration based on the Windows operating system is basically successful. If the browser is displayed in PHP code, it means that the configuration failed, that is, the PHP file has not been successfully parsed, need to find the reason.

Figure 4.4

Configuring PHP under the Windows operating system Apache server

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.