Windows nginx PHP Configuration

Source: Internet
Author: User
Tags mysql download php and mysql php download
The legendary Nginx is more than the load balance of Apache, called the artifact. Alas, I have always been to new things not cold. However, there are many servers on the server with Nginx to do HTTP server, today snatch understand. Search the Internet, most of the introduction of Linux under the Nginx and PHP configuration. I now want to try under windows, found that the information is not many, and is not very accurate. In the meantime also encountered a lot of problems, fortunately toss a few times finally fix. Below the windows of the Nginx and PHP configuration, the wrong place everyone more magnanimous.

Prepare resources:

Originally I was using APM, very useful, integrated apache,php and MySQL. Turn it off this time and you need to download these three files again. Resources must be ready, otherwise play does not turn ah. Oh.

Nginx Download Address: http://sysoev.ru/nginx/nginx-0.8.16.zip

PHP Download Address: http://cn.php.net/distributions/php-5.2.11-Win32.zip

MySQL Download Address: http://download.mysql.cn/download_file/zip/5.0/mysql-5.0.22-win32.zip

To configure PHP:

Download the downloaded PHP to: D:\php, you can find a place, you like it good. Back up the php.ini-recommended and rename it to PHP.ini. Then edit the php.ini.

Basically, like using Apache, PHP configuration file changes are not a lot of places, such as open extension files are not discussed, there are a few important points to note:

Specify Docroot?? The directory where PHP files are stored, that is, your documentroot. Doc_root = "E:\www"

Extended storage directory Extension_dir?? Change to a real extended storage address. Extension_dir = "./ext"

Default time zone changes?? added in [Date]: Date.timezone = asia/chongqing

Because Nginx needs to be CGI PHP, so the following are the key points, or Nginx cannot open the PHP file:

ENABLE_DL = On
Cgi.force_redirect = 0
Cgi.fix_pathinfo=1
Fastcgi.impersonate = 1
Cgi.rfc2616_headers = 1

If you use MySQL, copy php5ts.dll and Libmysql.dll (open MySQL) to C:\WINDOWS\system32 below. and copy the php.ini to the C:\WINDOWS directory.

Configure Nginx:

Unzip the downloaded nginx into the D:\nginx directory. It's obvious that the Conf directory should be a configuration file, so what do you say? It was necessary to change the nginx.conf file in the past.

Do not see do not know, a look is really very happy, this configuration file is very clear, very simple. At least it's much simpler than Apache. Let people look at the joy from the heart. The specific configuration is as follows:

Open error log: Error_log logs/error.log;
The thread number is changed because it is used locally, so the threads are not open too much: worker_connections 64;
Change default file Encoding: CharSet GBK;

There are some specific configurations, but it is not appropriate to give them here, but later I give the full text and description of my configuration file. You can look at it in detail.

Start Nginx and PHP:

Start Nginx is very simple, using the Nginx.exe under the Nginx directory double-click. However, PHP startup is a bit special because it uses CGI. I downloaded the RunHiddenConsole.exe on the Internet, using the tool to execute the CMD window will automatically close, otherwise you see a CMD window has been dangling, the head will faint.

Create Start_php.bat to start PHP with the following file contents:

@echo off
echo Starting PHP FastCGI ...
RunHiddenConsole.exe d:\php\php-cgi.exe-b 127.0.0.1:9000-c D:\php\php.ini

Create Stop_nginx.bat, to close the PHP and Nginx process, the file contents are as follows:

@echo off
echo Stopping Nginx ...
taskkill/f/im nginx.exe > nul
echo Stopping PHP FastCGI ...
taskkill/f/im php-cgi.exe > nul
Exit

Because I'm using the default port of 80, you can access localhost directly. Here are two of them.

Welcome Nginx

NGINX directory Structure

Configuration file Plots:

Here the figure is casually cut a bit, the text is not marked red, yours faithfully against the look. Write their own, the useless places are removed (not useless, I did not change and extend these configurations).

Nginx conf desc

Nginx configuration file:

PHP.ini will not give out, a moment to download the address come on, that thing is too long. Only the Nginx configuration file released, yours faithfully Mo Strange.

#user nobody;
Worker_processes 1;

Error_log Logs/error.log;
#error_log Logs/error.log Notice;
#error_log Logs/error.log Info;
#pid Logs/nginx.pid;


Events {
Worker_connections 64;
}


HTTP {
Include Mime.types;
Default_type Application/octet-stream;

#log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
# ' $status $body _bytes_sent ' $http _referer '
# ' "$http _user_agent" "$http _x_forwarded_for" ';

#access_log Logs/access.log Main;

Sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
Keepalive_timeout 65;

#gzip on;

server {
Listen 80;
server_name localhost;

CharSet GBK;

#access_log Logs/host.access.log Main;

Location/{
Root e:\www;
Index index.html index.htm index.php;
AutoIndex on;
}

#error_page 404/404.html;

# REDIRECT Server error pages to the static page/50x.html
#
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}

# Proxy The PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# Proxy_pass http://127.0.0.1;
# }

# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root HTML;
# Fastcgi_pass 127.0.0.1:9000;
# Fastcgi_index index.php;
# Fastcgi_param Script_filename/scripts$fastcgi_script_name;
# include Fastcgi_params;
# }
Location ~ \.php$ {
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename E:\www$fastcgi_script_name;
Include Fastcgi_params;
}
# Deny access to. htaccess files, if Apache ' s document Root
# concurs with Nginx ' s one
#
#location ~/\.ht {
# Deny All;
# }
}


# Another virtual host using mix of ip-, name-, and port-based configuration
#
#server {
# Listen 8000;
# Listen somename:8080;
# server_name somename alias Another.alias;

# location/{
# root HTML;
# index index.html index.htm;
# }
# }


# HTTPS Server
#
#server {
# Listen 443;
# server_name localhost;

# SSL on;
# ssl_certificate Cert.pem;
# Ssl_certificate_key Cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers all:! Adh:! Export56:rc4+rsa:+high:+medium:+low:+sslv2:+exp;
# ssl_prefer_server_ciphers on;

# location/{
# root HTML;
# index index.html index.htm;
# }
# }

}

Nginx configuration file PHP configuration file
  • 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.