HTTP server Basic Configuration [Windows + Nginx + MySQL + phpMyAdmin]

Source: Internet
Author: User
Tags wrapper phpmyadmin

The smell says Nginx always has the advantage of high performance, concurrency, and less memory, more "reverse proxy" and "Load Balancing" features. Using nginx+php as a development environment, performance is several times higher than apache+php. This article takes the current version of each program as an example to introduce a way to build a Nginx+php+mysql+phpmyadmin classic development environment under Windows (x64).

1. Application package with initial path settings

Nginx (current latest 1.7.9): http://nginx.org/download/;5

PHP (current latest 5.6.6rc1): http://windows.php.net/qa/, select VC11 x86 Thread safe version;

MySQL (current latest 5.6.23): Http://dev.mysql.com/downloads/mysql, we recommend that you choose Windows (x86, 64-bit) ZIP Archive, or you can use Windows (x86, 64- Bit) MySQL Installer MSI installation version;

PhpMyAdmin (current latest 4.3.9): http://www.phpmyadmin.net/home_page/index.php;

Runhiddenconsole: This procedure is slightly;

Assuming that the installation directory for all applications is C:\Server\, the folder structure in the directory is as follows: (The following tutorial will follow the folder name in this directory)

2. Configure MySQL

This tutorial takes the zip version of the MySQL package as an example, accustomed to make the management with the interface MysQL can install MSI version, the specific method slightly.

Unzip the zip package, copy all MySQL files to C:\Server\MySQL (C:\Server\MySQL should include bin, data folder);

Run cmd, go to MySQL directory:cd C:\Server\MySQL\bin (make sure the current directory is under C drive, otherwise use CD. / command to return the C-disk directory);

Install MySQL:MySQLd--install MySQL56

Run SQL:net start MySQL56

Modify MySQL Password:mysql-u root-p ;

Under normal circumstances will appear enter password: the content, directly enter can (password is empty), then will appear mysql> words;

Input use MySQL; rear return, display database changed;

Enter UPDATE user SET Password=password (' $pwd '), user= ' $user ' WHERE user= ' root '; After enter, where $pwd and $user respectively for their own defined password and user name, input after the Query OK, 3 Rows Affected (0.00 sec), then the user name and password has been modified;

Input flush privileges; After you enter, refresh the database.

At this time the database has been configured to complete, as long as the run MySQL.exe can open the database, in order to facilitate, write a few. bat batch for MySQL installation, uninstall, start, stop operation:

Install.bat:
CD C:\Server\MySQL\bin
MySQLd--install MySQL56

Uninstall.bat:SC Delete MySQL56

Start.bat:net start MySQL56

Stop.bat:net stop MySQL56

After you write the 4 bat files, you can do the bat program directly after you perform the appropriate operation. To see the results of the execution, you can add a pause to all the bat files at the end.

3. Configure PHP

The PHP version selected here is php-5.6.6rc1-win32-vc11-x86. Although PHP under Nginx is fastcgi mode, in theory with non-thread-safe (NTS) version, but because it is in the Windows environment, or choose a thread-safe version to ensure its stability, and after the test, NTS in connection with the database failure ( such as deliberately shut down the MySQL service and connected to the database, there will be a strong php-cgi phenomenon, and the thread-safe version of the normal display of connection errors, so still use NTS to ensure stability is better.

Unzip the package, copy the php5 file to C:\Server\php;

Copy the php.ini-development and name the new file as PHP.ini (you can also copy the Php.ini-produceion, the former used for the development and the latter for the formal production, see the situation, beginners suggested with development), open php.ini;

In the #736 line, locate Extension_dir = , remove the preceding semicolon and change to Extension_dir = "C:\Server\php\ext", indicating that the path to extension is defined and takes effect;

In the #704 line, find always_populate_raw_post_data =-1, the preceding semicolon is removed, indicating that this sentence takes effect (this setting is mainly used in PHP to use "php://input" to get post source data);

On the #927 line, locate Data.timezone = , remove the preceding semicolon and change to DATA.TIMEZONE=PRC, which indicates that the time zone is defined and takes effect (for the date (), the () function in PHP);

Starting with the #878 line, select the DLL extension you want and make it effective, and the common modules are the following:

Php_curl.dll: Used to simulate HTTP requests for curl;
Php_mysql and Php_mysqli: For MySQL connection, MySQL must be selected;
Php_mbstring: Used to support various codes, MySQL must be selected;
PHP_OPENSSL: for HTTPS requests;
PHP_GD2: Used for GD2 graph library related functions;

In the #773 line, find cgi.fix_pathinfo=1, the preceding semicolon removed, indicating that this sentence to take effect;

For more than 5.5 versions, the "Libeay32.dll", "Ssleay32.dll", "Libssh2.dll" three DLL files in the PHP directory are copied to the c:\windows\system32,x64 system and copied to the C + + WINDOWS\SYSWOW64, otherwise some libraries such as curl will be invalid.

PHP runs with Nginx and does not need to be started separately, and is now configured to complete.

4. Configure Nginx

Nginx configuration is the same as the Apache principle, but relatively simple.

On the #44 line, change to root C:\Server\localhost, which indicates the site root directory location;

On the #45 line, change to index index.html index.htm index.php, which indicates support for more types of default home page;

In the #65-#71行, remove the previous well number, indicating that the configuration takes effect, instead:
root C:\Server\localhost;
Fastcgi_pass 127.0.0.1:9000;
Include fastcgi.conf;
Where Root is the Web site root directory, and #44 line configuration, fastcgi_pass php bound port, the following will be introduced;

On the #32 line, add fastcgi_intercept_errors on, indicating that the fastcgi (PHP) error is returned to Nginx processing;

In the #48 line, the error_page before the well number is removed, indicating that the configuration takes effect, the 404 error is directed to the/404.html page (or default), otherwise access to the non-existent PHP will only display the no input file specified text, does not show 404.

At this time Nginx is also configured, you can try to run a bit.

Open cmd, enter Nginx directory:cd C:\Server\Nginx;

Start Nginx:nginx

Open another cmd and go to PHP directory:cd C:\Server\php;

Start php:php-cgi-b 127.0.0.1:9000, where 127.0.0.1:9000 is the Fastcgi_pass bound address and port.

Open the browser, enter the 127.0.0.1, found that the page appears 403 Forbidden, because C:\Server\localhost has no index home, but can prove that nginx+php has been running.

For convenience, you can still write a few bat control Nginx start and end: (Need to use runhiddenconsole)

Start.bat:
CD C:\Server\Nginx
Start Nginx
CD C:\Server\
Runhiddenconsole Php\php-cgi-b 127.0.0.1:9000

Stop.bat:
taskkill/f/im Nginx.exe
taskkill/f/im Php-cgi.exe
taskkill/f/im Conhost.exe

5. Configure phpMyAdmin

After extracting the PhpMyAdmin compressed package and copying the files to C:\Server\localhost\phpMyAdmin, note that it is now easy to debug in localhost and open the libraries\config.default.php:

On #252 line, the $cfg[' Servers ' [$i] [' user '] = ' root ' will be changed to the user name of MySQL;

In #259, enter MySQL password in $cfg[' Servers ' [$i] [' password '] = ';

In #39 line, enter the address of the server in $cfg[' pmaabsoluteuri ' = '; (local server is http://127.0.0.1)

Open the browser, enter http://127.0.0.1/phpMyAdmin/index.php, follow the prompts to log in.

In addition, if the local test state, in order to facilitate the need not each time the password entered, you can:

On #230 line, will $cfg [' Servers '] [$i] [' auth_type '] = ' cookie '; Change the cookie to config so that the next time you visit index.php, you will be logged in directly.

6. Create a virtual directory

Similarly, Nginx and Apache also have virtual directory features, such as the 1th directory structure, phpMyAdmin is not in the default directory localhost, but can still be accessed with http://127.0.0.1/phpMyAdmin, The virtual directory provides a directory mapping feature. Open nginx\nginx.conf:

After location/{} (#47行位置) join:
location/phpmyadmin/{
Alias C:/server/phpmyadmin;
Index index.php
}
Location ~ ^/phpmyadmin/(. *\.php) $ {

Alias C:/server/phpmyadmin/$1;
Fastcgi_pass 127.0.0.1:9000;
Include fastcgi.conf;
}

Nginx uses alias to represent the directory mapping relationship, the first sentence location represents the actual path of server/phpmyadmin with/phpmyadmin/, and index.php represents the default path, and the second sentence represents a match/phpmyadmin/ The php-extension file is bound to the 127.0.0.1:9000 port as the PHP settings.

Open the browser into the 127.0.0.1/phpmyadmin/index.php, you can normally log in to the database (of course, MySQL to start).

Simply explain the nginx+fastcgi mode of operation. Nginx does not provide standard modules like Apache, and all external program calls must be implemented via the FASTCFI interface (socket). So PHP must be bound to the socket, through fastcgi and Nginx communication. When the Nginx receives the request, through the fastcgi to forward the request to wrapper (bound on the socket, to start the PHP program), wrapper received after the generation of a new PHP thread, waiting for PHP processing to receive the data generated by the script, Then pass the data to Nginx via fastcgi. In this example, wrapper binds to the 127.0.0.1:9000, and the Socket,nginx can exchange data with PHP.

Now do an example: Open the LocalHost folder and create a new two file index.php,test.php.
Write in test.php:

<?php    echo ' Test ';? >

Write in index.php:

<?php    Echo file_get_contents ("http://127.0.0.1/test.php");? >

Then enter in the browser: http://127.0.0.1/index.php.

This program is very simple, is to request the local test.php through index.php, the output of test.php output in the browser. However, it can be found that the program reads about 40 seconds each time, and 500 results occur. In Apache test this program, found that no 1 seconds program will be executed, but in Nginx has been the result of 500.

This reason is related to the fastcgi characteristics of nginx. Reference to this example, is mainly to elicit one of the features of Nginx, load balancing. The phenomenon of this instance can be solved by load balancing. As for the meaning of load balancing and how it is implemented, the next section will be described in detail.

HTTP server Basic Configuration [Windows + Nginx + MySQL + phpMyAdmin]

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.