How to install Php in Windows 11?

Posted by

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Installing PHP on Windows 11 is a straightforward process that involves downloading, configuring, and setting up the PHP runtime environment. Here’s a detailed guide to help you get started.

Step 1: Download PHP

  1. Visit the PHP Website:
  2. Choose the Right Version:
    • Download the Non Thread Safe (NTS) or Thread Safe (TS) version, depending on your server configuration. For development purposes, it’s common to choose the Thread Safe version.
    • Ensure you select the Windows x64 build for compatibility with Windows 11.

Step 2: Extract the PHP Files

  1. Locate the Download:
    • Navigate to the directory where the PHP .zip file is saved.
  2. Extract the Files:
    • Right-click the .zip file and select Extract All… or use tools like WinRAR or 7-Zip to extract it.
    • Extract the contents to a folder (e.g., C:\php).

Step 3: Add PHP to the System Path

  1. Open Environment Variables:
    • Right-click on This PC or My Computer and select Properties.
    • Click on Advanced System Settings → Environment Variables.
  2. Modify the Path Variable:
    • Under System Variables, locate the variable named Path and click Edit.
    • Add the path to your PHP folder (e.g., C:\php) and click OK to save.

Step 4: Configure PHP.ini

  1. Locate PHP.ini:
    • In the PHP folder, you will find two files: php.ini-development and php.ini-production.
  2. Choose and Rename:
    • Rename php.ini-development to php.ini for development purposes.
  3. Edit PHP.ini:
    • Open the php.ini file in a text editor (e.g., Notepad or VS Code).
    • Enable required extensions by uncommenting lines (remove the ; at the beginning). For example: extension=curl extension=mbstring extension=mysqli
    • Set the timezone to your region: date.timezone = Asia/Kolkata

Step 5: Verify the Installation

  1. Open Command Prompt:
    • Press Win + R, type cmd, and hit Enter.
  2. Check PHP Version:
    • Type the following command: php -v
    • If PHP is installed correctly, the version details will appear.

Step 6: Optional – Integrate with a Web Server

PHP can run standalone, but integrating it with a web server like Apache or Nginx is common for development.

For Apache:

  1. Download and install XAMPP or configure Apache manually.
  2. Update the httpd.conf file in the Apache conf directory to include PHP: LoadModule php_module "C:/php/php8apache2_4.dll" AddHandler application/x-httpd-php .php PHPIniDir "C:/php"
  3. Restart Apache.

For Nginx:

  1. Install Nginx and configure it to point to PHP by adding the following in nginx.conf: location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
  2. Restart Nginx.

Step 7: Test PHP

  1. Create a Test File:
    • Create a new file named info.php in your web server’s root directory (e.g., htdocs for XAMPP).
    • Add the following code: <?php phpinfo(); ?>
  2. Run in Browser:
    • Open a web browser and navigate to http://localhost/info.php.
    • If PHP is installed correctly, you will see the PHP info page.

Conclusion

Congratulations! You have successfully installed PHP on Windows 11. This setup allows you to run PHP scripts locally and start building dynamic web applications. For a seamless development experience, consider using IDEs like VS Code, PhpStorm, or Sublime Text. Happy coding! 🚀

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x