Php environment Configuration

Source: Internet
Author: User
Tags configuration php php session
Note: During the configuration process, all inputs are in English, especially double quotation marks with punctuation marks. Chinese quotation marks may be used in the text. Once you copy and paste them directly, configuration may fail !!! Also, if you copy the path directly in the windows Folder system, there is a backslash () between the folders, but the configuration uses a slash (), please do not enter an error

Note: During the configuration process, all inputs are in English, especially double quotation marks with punctuation marks. Chinese quotation marks may be used in the text. Once you copy and paste them directly, configuration may fail !!! Also, if you copy the path directly in the windows Folder system, there is a backslash (\) between the folders, but the configuration uses a slash (/), please do not enter an error

Note: During the configuration process, all inputs are in English, especially double quotation marks with punctuation marks. Chinese quotation marks may be used in the text. Once you copy and paste them directly, configuration may fail !!!

Also, if you copy the path directly in the windows Folder system, there is a backslash (\) between the folders, but the configuration uses a slash (/), please do not enter an error.

PHP configuration

First, go to the PHP decompressed directory, find the php. ini-development configuration file, and rename it as php. ini. This file is the php configuration file of the current system. Open the php. ini configuration file and configure it as prompted below.

Find the following content:

; On windows:

; Extension_dir = "ext"

Change

; On windows:

Extension_dir = "E:/ProgramFiles (x86)/PHP/ext"

Note that the semicolon before extension_dir needs to be removed, and the value must be changed to the ext folder path under the PHP folder. This configuration is used to update the PHP extension path folder, all extended libraries are in this folder.

Next, we need to enable PHP to support MySQL databases, and enable extensions such as CURL, GD2, XML, and PDO. Find the following content and remove the semicolon (;) in front of it.

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

We all know that PHP supports the session function. By default, the PHP session is stored in the file system, so we need to set the Save folder for the Session.

Find the following content:

; Session. save_path = "/tmp"

Change

Session. save_path = "E:/Program Files (x86)/PHP/custom/session"

Remove the semicolon and reset any path to ensure that the folder exists. For ease of management, we recommend that you set it to the PHP installation path to avoid accidental deletion.

After completing the session settings, we also need to configure a folder path, that is, the temporary file path of PHP. All PHP students know that when uploading files through PHP, the file is first in a temporary folder.

Find the following content:

; Upload_tmp_dir =

Change

Upload_tmp_dir = "E:/Program Files (x86)/PHP/custom/upload"

Finally, PHP versions later than 5.3 need to set the time zone forcibly. Otherwise, an error will be reported during phpinfo () and some programs.

Find the following content:

; Date. timezone =

Change

Date. timezone = Asia/Shanghai

Configure Apache to support PHP

In the Apache configuration directory E: \ Program Files (x86) \ Apache Software Foundation \ Apache2.2 \ conf (this is my installation directory, note that the paths directly copied in windows use the backslash as the separator, and all the configuration files use the diagonal line as the separator. Please note that !), Find the httpd. conf configuration file.

In

# LoadModule vhost_alias_module modules/mod_vhost_alias.so

Add the following content in the following line.

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

The first line of this configuration specifies the module path of PHP and Apache. The module File is generally located in the php root directory, the second line is used to specify the path of PHP in Win7, and the third line is used to add the file type, the first and second lines need to be modified according to the PHP installation path.

Next, we need to specify the root directory of the WEB server for Apache. By default, the Apache root directory is the htdocs folder under the Apache directory. To facilitate development, we will set it to the htdocs directory under the e disk. First, create the htdocs directory under the e disk. Of course, you can also change it to any WEB root directory you want to name. Then, find the following content in the configuration file.

DocumentRoot "E:/Program Files (x86)/ApacheSoftwareFoundation/Apache2.2/htdocs"

Change

DocumentRoot "E:/htdocs"

Finally, modify the root directory file. apacheusers uses index.html as the initial directory file. Here, we make some modifications to make Apache search for the PHP file first.

Find the following content:

DirectoryIndex index.html

Change

DirectoryIndex index. php index.html

At this point, Apache supports related PHP configuration, restart the server, create the index. PHP file in the new directory, and write the following content.

Phpinfo ();

?>

Open the browser again and access localhost. If everything is normal, the php configuration information is displayed, as shown in.

PHP configuration information

Test PHP's support for MySQL

Finally, we need to test whether PHP can connect to the database. During the configuration process, we will remove the semicolon before a series of MySQL-related extensions, such as extension = php_mysql.dll, in this way, PHP can perfectly support corresponding programs through these extensions. Create the mysql. php file in the root directory and write the following content.

$ Dbc = mysql_connect ("127.0.0.1", "root", "(your mysql password )");

If (! $ Dbc ){

Echo "Database Link error! ";

} Else {

Echo "PHP environment setup: Windows 7 System Configuration PHP + Apache + MySQL environment tutorial ";

}

Mysql_close ();

?>

Visit 127.0.0.1/mysql. php In the browser. If the prompt "PHP environment setup: Windows 7 System Configuration PHP + Apache + MySQL environment tutorial" is displayed, it indicates that PHP supports MySQL perfectly.

Related Article

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.