How to install Apache and PHP on Windows
Step 1: Install Apache
Download the latest ZIP file from Apache website Extract Apache24 folder to C: drive. You also need to install latest Visual C++ Redistributable Visual Studio. The link for this is present on the same Apache page. To start Apache web server, please use the command below:
Open http://localhost in a browser and an “It works!” message should appear.
1 2 | cd C:\Apache24\bin httpd |
To change any settings, Apache’s configuration file is located at C:\Apache24\conf\httpd.conf
I usually prefer to run Apache on port 8080. In C:\Apache24\conf\httpd.conf, change the line Listen 80 to Listen 8080. Restart Apache and, from that point onward, you can load web files at http://localhost:8080
The server can be stopped with the command: Ctrl + C
Step 2: Download PHP
Download the ZIP file from PHP site. I have used x64 Thread Safe ZIP package
Step 3: Extract it
Extract it to C:/php
Step 4: Configure php.ini
PHP’s configuration file is named php.ini. This doesn’t exist initially, so copy C:\php\php.ini-development to C:\php\php.ini
Open php.ini in a test editor and ensure the lines below are uncommented by removing the semi colon before these entries.
Step 5: Add C:\php to the Path environment variable
1 2 3 4 | extension=curl extension=gd extension=mbstring extension=pdo_mysql |
Go to System Properties, click on Environment Variables
Scroll down the System variables list and click Path followed by the Edit button. Click New and add C:\php
Step 6: Configure PHP as Apache module
Ensure Apache is not running and open its C:\Apache24\conf\httpd.conf configuration file in a text editor. Add the following lines to the bottom of the file to set PHP as an Apache module
Optionally, you can change the DirectoryIndex setting to load index.php instead of index.html when it can be found. The initial setting is:
Change it to:
Run the command below
Syntax OK should appear
If all went well, restart Apache with httpd
1 2 3 4 | # PHP8 module PHPIniDir "C:/php" LoadModule php_module "C:/php/php8apache2_4.dll" AddType application/x-httpd-php .php |
1 2 3 | < IfModule dir_module> DirectoryIndex index.html </ IfModule > |
1 2 3 | < IfModule dir_module> DirectoryIndex index.php index.html </ IfModule > |
1 2 | cd C:\Apache24\bin httpd -t |
Step 7: Test a PHP file
Create a new file named index.php in Apache’s web page root folder at C:\Apache24\htdocs and add the following PHP code:
Open a web browser and enter your server address: http://localhost:8080. A “PHP version” page will appear showing the various PHP and Apache configuration settings.
1 2 3 | <? php phpinfo(); ?> |
You can now create PHP sites and applications in any sub-folder of C:\Apache24\htdocs.
Comments
Post a Comment