How to Install PHP on Windows and Enable Modules
In this guide, we will walk you through the process of installing PHP on a Windows machine using Chocolatey (choco) package manager. We will also show you how to enable the necessary modules in the php.ini
configuration file to run popular PHP applications like the Laravel framework.
Prerequisites
Before you begin, make sure you have the following prerequisites in place:
-
Windows Operating System: This guide is specifically for Windows.
-
Chocolatey Installed: If you don’t have Chocolatey installed, you can install it by following the instructions on the Chocolatey website.
Step 1: Install PHP with Chocolatey
Open a command prompt or PowerShell window with administrator privileges and run the following command to install PHP:
|
|
Chocolatey will download and install PHP along with its dependencies.
Step 2: Locate the php.ini
Configuration File
The php.ini
file is the configuration file for PHP. You will need to locate and edit this file to enable the required modules for your application.
By default, Chocolatey installs PHP in the C:\ProgramData\chocolatey\lib\php\tools
directory. The php.ini
file is usually found in this path:
C:\ProgramData\chocolatey\lib\php\tools\php.ini
You can use a text editor like Notepad or Visual Studio Code to edit this file.
Step 3: Enable PHP Modules
To run a framework like Laravel or any other PHP application, you may need to enable specific PHP modules. Open the php.ini
file and search for the following lines:
|
|
These lines contain a list of PHP extensions that are commented out by default (the ;
at the beginning of the line indicates a comment). To enable an extension, remove the semicolon (;
) at the beginning of the line.
For example, to enable the GD and MySQLi extensions, your php.ini
file should look like this:
|
|
Save the php.ini
file after making these changes.
Step 4: Restart the Web Server
If you are using a web server like Apache or Nginx, you will need to restart the web server to apply the changes.
Step 5: Verify PHP Installation
To verify that PHP is installed and the modules are enabled, create a PHP file with the following content:
|
|
Save this file with a .php
extension (e.g., phpinfo.php
) in your web server’s document root directory.
Access this file through your web browser (e.g., http://localhost/phpinfo.php), and you should see a page displaying detailed information about your PHP installation, including the enabled modules.
That’s it! You have successfully installed PHP on Windows using Chocolatey and enabled the necessary modules to run PHP applications like Laravel. You can now proceed to set up and configure your PHP application as needed.