search
HomeBackend DevelopmentPHP Tutorialphp+nginx environment configuration

php+nginx environment configuration

Apr 04, 2018 am 09:36 AM
phpenvironment

The content of this article is the configuration of PHP and nginx environments. I share it with everyone here and give a reference to friends in need

<br>

##php+ nginx environment configuration

<br>

<br>

1. First, you need to prepare the application package.

nginx: nginx/Windows-1.0.4

php:php-5.2.16-nts-Win32-VC6-x86.zip (php under nginx runs in FastCGI mode, so We download the non-thread-safe php package of nts)

(will also be used) RunHiddenConsole: RunHiddenConsole.zip

2. Installation and configuration.

 1) Installation and configuration of php.

Directly decompress the downloaded php package and go to the PHP directory on drive D (D:\PHP). Here, rename the decompressed folder to php7. Enter the folder and modify the php.ini-recommended file to php.ini, and open it with Wordpad. Find the

php configuration file php.ini and save it.

<br>

Search for "extension_dir" and find: e;xtension_dir = "ext" First remove the semicolon in front and change it to extension_dir = "C:\wnmp\php \ext"

Search for "date.timezone" and find: ;date.timezone = Remove the preceding semicolon first and then change it to date.timezone = Asia/Shanghai

Search for "enable_dl", Found: enable_dl = Off Change to enable_dl = On

Search for "cgi.force_redirect"; cgi.force_redirect = 1 First remove the semicolon in front and then change it to cgi.force_redirect = 0

Search for " fastcgi.impersonate", find: ;fastcgi.impersonate = 1 Remove the preceding semicolon

Search for "cgi.rfc2616_headers", find: ;cgi.rfc2616_headers = 0 Remove the preceding semicolon first and then change it to cgi. rfc2616_headers = 1

Search for "php_mysql" and find: "extension=php_mysql.dll and extension=php_mysqli.dll Remove the previous ";"extension=php_mysql.dll and extension=php_mysqli. dll (supports MYSQL database)

Please change other configurations according to your own needs

<br>

##Among them. php_mysql means:

<br>

<br>

<br>

##;extension=php_mysql.dll;extension=php_mysqli.dll

After specifying the ext path of php earlier, just remove the corresponding ";" in front of the required expansion package. Open php_mysql.dll and php_mysqli.dll here to let php support mysql. Of course, don’t forget that a very important step is to copy the

libmysql.dll file in the php5 directory to the C:\Windows directory. You can also specify the path in the system variable. Of course, I chose it here for more convenience. Method ^_^.

#At this point, php can already support mysql.

Next we configure php so that php can be combined with nginx. Find

##

<br>
<br>

<br>

;cgi.fix_pathinfo

=1We remove the semicolon here.

<br>

cgi.fix_pathinfo

=1

This step

Very important, here are the CGI settings of php.  2) Installation and configuration of nginx.

Extract the downloaded nginx-1.0.4 package to the PHP directory on drive D and rename it to nginx. Next, we configure nginx so that it can work with php. Enter the nginx conf directory, open the nginx configuration file nginx.conf, and find

<br>##location

/ { root html;   #This is the root directory of the site index index.html index.htm;}Change root

html; to root D :/PHP/hostdoc (that is, the file where you will put the code in the future);

Go down further and find

php+nginx environment configuration

<br>

# 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;

#}

php+nginx environment configuration

First remove the "#" in front, and also change root html; to root D :/PHP/hostdoc;. Then change the /scripts marked in red to "$document_root". The "$document_root" here refers to the site path pointed to by the previous "root". This is the changed version:

<br>

php+nginx environment configuration

<br>

pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#location ~ \.php$ {                             D:/wnmp/www;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;

}

php+nginx environment configuration

##Save the configuration file and that’s it.

 

3. The nginx+php environment has been initially configured, let’s take a look. We can enter the command

to start php and start nginx manually. Of course, we can also use a script to achieve this.

<br>

<br>

<br>

#4. The function of RunHiddenConsole.exe is to automatically close the script after executing the command line script, and the process started from the script will not be closed. First, unzip the downloaded RunHiddenConsole.zip package into the nginx directory. The function of RunHiddenConsole.exe is to automatically close the script after executing the command line script, and from Processes started in the script are not closed. Then create a script, named "start_nginx.bat", we edit it in Notepad++

<br>

##

<br>
php+nginx environment configuration@echo

off

##REM

Not valid under Windows REM set PHP_FCGI_CHILDREN=5REM The maximum number of requests handled by each process, or set For Windows environment variables

set

PHP_FCGI_MAX_REQUESTS=1000

echo Starting PHP FastCGI...

RunHiddenConsole D:/wnmp/php5/php-cgi. exe -b 127.0.0.1:9000 -c

D:/wnmp/php5/php.ini

##echo Starting nginx...

RunHiddenConsole D:/wnmp/nginx /nginx.exe -p

D:/wnmp/nginx

php+nginx environment configuration##Create another one named stop_nginx The .bat script is used to shut down nginx

<br>

#

<br>
php+nginx environment configuration@echo

off

echo Stopping nginx... taskkill

/F /IM nginx .exe > nul

## echo Stopping PHP FastCGI...taskkill

/

F /IM php-cgi.exe > nul

exit

php+nginx environment configuration

After it is done, it will look like this

In this way, our service scripts have been created. Double-click start_nginx.bat and see if there are two nginx.exe processes and one php-cgi.exe process in the process manager?

In this way, the nginx service is started, and php is also run in fastCGI mode.

Go to the site directory, create a new phpinfo.php file, and edit it

<br>

<br>

<br>

php phpinfo();?>

After saving, open the browser Enter "http://localhost/phpinfo.php". If you see

, it means that the nginx+php environment has been configured, haha~

<br>

The above is the detailed content of php+nginx environment configuration. For more information, please follow other related articles on the PHP Chinese website!

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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor