Programming Tutorials

Installing PHP with nginx-server under windows

By: Donald in PHP Tutorials on 2011-03-26  

Installing PHP with nginx on Windows involves several steps:

  1. Download and install the nginx server: You can download the latest stable version of nginx for Windows from the official website: https://nginx.org/en/download.html. Once downloaded, extract the contents of the archive to a directory of your choice, for example, C:\nginx.

  2. Download and install PHP: You can download the latest stable version of PHP for Windows from the official website: https://windows.php.net/download/. Choose the appropriate version of PHP for your system architecture (32-bit or 64-bit) and the required version of VC++ runtime. Once downloaded, extract the contents of the archive to a directory of your choice, for example, C:\php.

  3. Configure PHP to work with nginx: Open the PHP installation directory and locate the php.ini-production file. Rename it to php.ini. Edit the php.ini file and make the following changes:

    • Uncomment the following line by removing the semicolon (;) at the beginning: extension_dir = "ext"

    • Add the following lines to the end of the file: fastcgi.impersonate = 1 cgi.fix_pathinfo = 1 cgi.force_redirect = 0

  4. Configure nginx to work with PHP: Open the nginx configuration file (nginx.conf) located in the conf directory of your nginx installation directory. Add the following lines to the http section of the configuration file:

    server { listen 80; server_name localhost; root /path/to/your/web/root; index index.php;

    location / { try_files $uri $uri/ /index.php?$query_string; }

    location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }

    Replace /path/to/your/web/root with the actual path to the root directory of your web server, for example, C:\nginx\html.

  5. Start the nginx server: Open a command prompt and navigate to the directory where nginx.exe is located, for example, C:\nginx. Run the following command:

    nginx.exe

  6. Start the PHP FastCGI process: Open another command prompt and navigate to the directory where php-cgi.exe is located, for example, C:\php. Run the following command:

    php-cgi.exe -b 127.0.0.1:9000

    This will start the PHP FastCGI process and bind it to the local IP address 127.0.0.1 on port 9000.

  7. Test your PHP installation: Create a file named info.php in the root directory of your web server with the following content:

    <?php phpinfo(); ?>

    Open your web browser and go to http://localhost/info.php. If everything is set up correctly, you should see the PHP information page.

That's it! You have now successfully installed and configured PHP with nginx on Windows.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in PHP )

Latest Articles (in PHP)