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:
cd C:\Apache24\bin
httpd
Open http://localhost in a browser and an “It works!” message should appear.

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.
extension=curl
extension=gd
extension=mbstring
extension=pdo_mysql
Step 5: Add C:\php to the Path environment variable

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
# PHP8 module
PHPIniDir "C:/php"
LoadModule php_module "C:/php/php8apache2_4.dll"
AddType application/x-httpd-php .php
Optionally, you can change the DirectoryIndex setting to load index.php instead of index.html when it can be found. The initial setting is:
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
Change it to:
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
Run the command below
cd C:\Apache24\bin
httpd -t
Syntax OK should appear If all went well, restart Apache with httpd 

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:
<?php
phpinfo();
?>
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. 
You can now create PHP sites and applications in any sub-folder of C:\Apache24\htdocs.






Comments

Popular Posts

Golang gRPC Microservice

Dropwizard MySQL Integration Tutorial

Asynchronous Processing (@Async) in Spring Boot