Home  >  Article  >  Backend Development  >  PHP environment setup_PHP tutorial

PHP environment setup_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:11:061324browse

I just installed Windows 7 in the past two days. It happened that some time ago a friend asked me how to install and build a PHP environment under Windows, so I plan to work hard and manually build a PHP environment step by step. I will not use the PHP environment to build software for the time being. Here Detailed illustrations of the tutorial on installing and configuring the PHP+Apache+Mysql environment under Windows 7. I hope it will be helpful to PHP beginners.
To build a PHP environment under Windows 7, you first need to download the PHP code package and the installation software packages for Apache and Mysql.

The first step in setting up a PHP environment: Install the Apache service under Windows 7.


Apache configuration information

Here we mainly configure the Network Domain, Server Name, Email address and the port occupied by the Apache service. The default is port 80. You can configure other ports as needed. You can use the default directory or choose the Apache installation directory as needed. Installation directory.
After completing the installation of the Apache service, enter http://localhost/ in the browser, and the words It’s work! appear, indicating that the Apache service is installed successfully.

The second step of setting up PHP environment: Install Mysql service under Windows 7.


Install Mysql database and select the installation directory

Click the Mysql installer to install automatically. During this period, you can choose the installation directory of the Mysql database as needed. I always use the default directory.
Note: After installing the Mysql database, you need to configure the Mysql database to connect using PHP. How to configure it will be mentioned later.

The third step in setting up a PHP environment: Install PHP under Windows 7.

In fact, it is very simple to install PHP under Windows 7. Since I downloaded the PHP code package, I just need to unzip php-5.3.2-Win32-VC6-x86 and rename the folder to php, and copy it to the C drive Directory to complete the PHP installation.

The fourth step in setting up a PHP environment: How to configure the PHP environment under Windows 7.

The configuration of the PHP environment on Windows 7 is much simpler than that on Windows XP. No copying or other operations is required. You only need to rename the php.ini-development configuration file to the php.ini configuration file. Then do the following configuration operations:

1. Open the php.ini configuration file and find


; On windows:
; extension_dir = "ext"

was changed to


; On windows:
extension_dir = "C:/php/ext"

indicates specifying the specific directory of the PHP extension package in order to call the corresponding DLL file.

2. Since the default PHP does not support automatic connection to Mysql, the corresponding extension library function needs to be enabled, such as php_mysql.dll, etc., which will be


extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_pdo_mysql.dll
extension=php_pdo_odbc.dll
extension=php_xmlrpc.dll

The semicolon (;) before these extensions is removed.

3. Configure PHP’s Session function

When using the session function, we must configure the saving directory of the session file on the server, otherwise the session cannot be used. We need to create a new readable and writable directory folder on Windows 7. This directory is best independent of the WEB host. Outside the program directory, here I created the phpsessiontmp directory on the root directory of drive D, and then found

in the php.ini configuration file


;session.save_path = "/tmp"

was changed to


session.save_path = "D:/phpsessiontmp"

4. Configure PHP file upload function. How to write PHP file upload function?

Like session, when using PHP file upload function, we must specify a temporary folder to complete the file upload function, otherwise the file upload function will fail. We still need to create a readable and writable directory on Windows 7 folder, here I created the phpfileuploadtmp directory on the root directory of drive D, and then found

in the php.ini configuration file


;upload_tmp_dir =

was changed to


upload_tmp_dir = "D:/phpfileuploadtmp"

5. Modify date.timezone, otherwise the date part will report an error when executing phpinfo:

Warning: phpinfo() [function.phpinfo]…

We need to


;date.timezone =

was changed to


date.timezone = Asia/Shanghai

You can also click to refer to more configurations about PHP.INI

At this point, the PHP environment configuration on Windows 7 is completed, but completing these configurations is not enough. We need Apache to support PHP, so we also need to complete the corresponding PHP configuration in the Apache configuration file.

Step 5 of setting up PHP environment: Configure Apache to support PHP

1. Add

under #LoadModule vhost_alias_module modules/mod_vhost_alias.so


LoadModule php5_module "c:/php/php5apache2_2.dll"
PHPIniDir "c:/php"
AddType application/x-httpd-php .php .html .htm

We can see multiple php5apache DLL files in the PHP directory. Since we are using Apache2.2.15, of course we need to use php5apache2_2.dll, and then specify the PHP installation directory and the program extension to be executed.

2. We should know that the directory where the default Apache server executes the WEB main program is Apache2.2/htdocs, so when your WEB main program directory changes, we need to modify the corresponding Apache configuration, which will be


DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"

was changed to


DocumentRoot "D:/PHPWeb"

was changed to


3. Finally modify the specific index file sequence. Since the PHP function is configured, of course index.php needs to be executed first


DirectoryIndex index.html

was changed to


DirectoryIndex index.php index.html

4. Restart the Apache server

At this point, the PHP environment configuration on the Apache server is completed. You only need to create a new PHP file in the D:/PHPWeb directory and write



phpinfo();
?>

Then enter http://localhost in the browser, and you will see the specific configuration page of PHP, which means that the PHP environment configuration work on Window 7 is completed.

After completing the PHP environment configuration on Windows 7, we need to complete the last step of setting up the PHP environment, which is to support the Mysql database.

First you need to configure the Mysql server.

Click Mysql Server Instance Config Wizard in the Mysql Server5.1 menu under the start menu to complete the Mysql configuration wizard.


Select the type of Mysql server

I personally think that both the first and second options can be selected. If it is only used as a WEB database, it is recommended to choose the second option.
Mysql database usage

Select the number of concurrent connections for Mysql database

Select the number of concurrent connections for Mysql. The first item is the maximum number of concurrent connections of 20, the second item is the maximum number of concurrent connections of 500, and the last one is customized. You can choose according to your own needs.
Select the port number of the Mysql service, usually the default is sufficient

Select the character set of Mysql database

It is recommended to use UTF8 here, which is more versatile, otherwise it will easily cause garbled characters.

PHP environment setup_PHP tutorial

Set Mysql as a Windows service


Set the password for the Mysql database root user

Considering the boot speed issue here, I will cancel the automatic login to the Mysql service. Generally, you can choose this option. If not, you can use net start mysql to start the Mysql service.
Set the password for the Mysql database root user

PHP environment setup_PHP tutorial

Execute Mysql service configuration options




The configuration file of the Mysql database is saved in C:Program FilesMySQLMySQL Server 5.1my.ini. If there are any changes in the future, you can modify this file.
At this point, the configuration of the Mysql database is complete. In order to verify whether PHP can connect to Mysql, you can create the following code in index.php


$connect=mysql_connect(“127.0.0.1″,”root”,”your mysql database password”);
if(!$connect) echo “Mysql Connect Error!”;
else echo "Welcome to the PHP website development tutorial website-www.leapsoul.cn";
mysql_close();
?>

Then enter http://localhost/ in the browser, and when you see the words: Welcome to the PHP website development tutorial network-www.leapsoul.cn, it means that the PHP connection to Mysql is successful.

Solution to the problem of being unable to use localhost to connect to MYSQL5.3 under Windows 7

In Windows 7, when PHP connects to Mysql, by default it can only use the IP address to connect to Mysql, but cannot use localhost to connect to Mysql. The solution is to open the hosts file under C:WindowsSystem32driverstc and change

1
# 127.0.0.1 localhost

Just remove the comments in

.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477398.htmlTechArticleI just installed Windows 7 in the past two days. It happened that a friend asked me some time ago how to install and build a PHP environment under Windows. So I plan to work hard and manually build a PHP environment step by step. I won’t use the PHP environment for the time being...
Statement:
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