PHP Environment Build _php Tutorial

Source: Internet
Author: User
Tags configuration php mysql connect php file upload php web development phpinfo web database
This two days just installed Windows 7, happened to have a friend in the previous time asked me how to install the PHP environment under Windows, so I intend to work hard, manual step by step to build PHP environment, for the moment, do not use PHP environment to build software, in this detailed diagram in Windows 7 installation configuration php+ Apache+mysql Environment tutorial, want to help PHP beginners.
To build a PHP environment under Windows 7, you first need to download the PHP code package and the Apache and MySQL installation packages.

PHP Environment Build First step: Install Apache service under Windows 7.


Apache Configuration information

Here the main configuration network Domain, Server Name, email address and the Apache service occupies the port, the default is 80 port, you can configure on the other ports as needed, Apache installation directory You can use the default directory or choose your own installation directory as needed.
After completing the installation of the Apache service, enter http://localhost/in the browser and it's work! to indicate that the Apache service was installed successfully.

PHP Environment Build Second step: Install MySQL service under Windows 7.


Install the MySQL database and select the installation directory

Click on the MySQL installer to install automatically, during which you can select the MySQL database installation directory, I will always use the default directory.
Note: After the MySQL database has been installed, the MySQL database configuration needs to be re-configured to use PHP to connect, and later will refer to how to configure.

PHP Environment Build Step three: Install PHP under Windows 7.

In fact, the installation of PHP in Windows 7 is very simple, because I am under the PHP code package, as long as the decompression php-5.3.2-win32-vc6-x86 and renamed as a folder PHP, copy it to the C-drive directory to complete the PHP installation.

The PHP environment builds the fourth step: How to configure the PHP environment under Windows 7.

The configuration of the PHP environment on Windows 7 is much simpler than Windows XP, and requires no duplication, just rename the php.ini-development configuration file to the PHP.ini profile. Then do the following configuration operations:

1. Open the PHP.ini configuration file to find


; On Windows:
; Extension_dir = "ext"

Revision changed to


; On Windows:
Extension_dir = "C:/php/ext"

Represents the specific directory for the specified PHP expansion pack in order to invoke the appropriate DLL file.

2, because the default PHP does not support automatic connection to MySQL, you need to open the corresponding expansion library functions, such as Php_mysql.dll, 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

These extension before the semicolon (;) removed.

3. Configure the session function of PHP

When using the session function, we must configure the session file on the server to save the directory, otherwise we can not use the session, we need to create a new read-write directory folder on Windows 7, this directory is best independent of the Web main program directory, Here I established the Phpsessiontmp directory on the D-Packing directory and found it in the php.ini configuration file.


; Session.save_path = "/tmp"

Revision changed to


Session.save_path = "D:/phpsessiontmp"

4, configure the PHP file upload function How to write PHP file upload function?

As with the session, when using PHP file Upload function, we must specify a temporary folder to complete the file upload function, or the file upload function will fail, we still need to create a read-write directory folder on Windows 7, Here I established the Phpfileuploadtmp directory on the D-Packing directory and found it in the php.ini configuration file.


; Upload_tmp_dir =

Revision changed to


Upload_tmp_dir = "D:/phpfileuploadtmp"

5. Modify Date.timezone, otherwise the date part will be error when executing phpinfo:

Warning:phpinfo () [Function.phpinfo] ...

We need to


;d Ate.timezone =

Revision changed to


Date.timezone = Asia/shanghai

You can also click for more information about the php.ini configuration

At this point in the Windows 7, the environment configuration of PHP is complete, but the light to complete these configurations is not enough, we need Apache support PHP, so we also need to complete the PHP configuration file in the appropriate configuration.

PHP Environment Build Fifth step: 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, because we are using Apache2.2.15, we certainly need to use Php5apache2_2.dll, then specify the PHP installation directory and the program extension to execute.

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


DocumentRoot "C:/Program Files/apache software Foundation/apache2.2/htdocs"

Revision changed to


DocumentRoot "D:/phpweb"

Revision changed to


3, the final revision of the specific index file order, due to the configuration of PHP functions, of course, need to index.php priority implementation


DirectoryIndex index.html

Revision changed to


DirectoryIndex index.php index.html

4. Restart Apache Server

At this point, the PHP environment configuration work on the Apache server is complete, you just need to create a new PHP file in the D:/phpweb directory, write


Phpinfo ();
?>

Then enter http://localhost in the browser, you can see the specific PHP Configuration page, representing the PHP Environment on window 7 configuration work is completed.

After completing the PHP environment configuration work on Windows 7, we need to complete the final step of building the PHP environment, which is to support the MySQL database.

You first need to configure the MySQL server.

Click the MySQL Server Instance Config Wizard in the MySQL Server5.1 menu under the Start menu to complete the MySQL configuration guide.


Choose the type of MySQL server

Personally, the first and second items are optional, if only as a Web database, it is recommended to select the second item.
MySQL Database usage

Select the number of concurrent connections for the MySQL database

Select the number of concurrent connections for MySQL, the first is the maximum number of 20 connection concurrency, the second is the maximum number of 500 concurrent connections, the last is custom, you can choose according to your own needs.
Choose the port number of the MySQL service, which is generally the default

Select the character set of the MySQL database

It is recommended to use UTF8, more general, or easily garbled.

Setting up MySQL for Windows services


Set the password for the MySQL database root user

Here to consider the issue of boot speed, I will automatically login to the MySQL service canceled, generally you can choose this option, if not selected, you can use the net start MySQL start MySQL service.
Set the password for the MySQL database root user

Perform MySQL service configuration options




The MySQL database configuration file is saved in C:\Program Files\mysql\mysql Server 5.1\my.ini, and you can modify this file if there are any changes in the future.
Now that the MySQL database configuration is complete, in order to verify that 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 PHP Web Development tutorial Network-www.leapsoul.cn";
Mysql_close ();
?>

Then enter the http://localhost/in the browser, see: Welcome to the PHP Web site development Tutorial Network-www.leapsoul.cn words that the PHP connection to MySQL even if it succeeds.

Workaround for MYSQL5.3 cannot be connected using localhost under Windows 7

In Windows 7, PHP connection to MySQL by default can only use the IP address to connect to MySQL, and cannot use localhost to connect to MySQL, the workaround is to open the Hosts file under C:\Windows\System32\drivers\etc, will

1
# 127.0.0.1 localhost

Can be removed from the comment.

http://www.bkjia.com/PHPjc/477398.html www.bkjia.com true http://www.bkjia.com/PHPjc/477398.html techarticle This two days just installed Windows 7, happened to have friends in the previous period of time asked me how to install the PHP environment under Windows, so I intend to work hard, manually step by step to build PHP environment, for the moment do not use the PHP environment ...

  • 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.