For a long time, getting PHP and MySQL to work correctly together under Windows was an argument for using Linux. Many of the kinks have been worked out, but this path still has several potholes.
Windows IIS has always had its challenges. If Linux isn't an option for you, you can minimise the pain of running PHP on a Windows server by using Apache rather than IIS as a web server—there are several Apache-MySQL-PHP installation stacks requiring you to do little more than point-and click to install and manage the web server, PHP and MySQL.
If you need to manage the details yourself ...
Change # ServerName www.example.com:80
to ...
ServerName localhostUncomment or edit
AllowOverride
directives so they read ...
AllowOverride None AllowOverride AllUncomment
#LoadModule rewrite_module modules/mod_rewrite.so
so it reads ...
LoadModule rewrite_module modules/mod_rewrite.soSave httpd.conf and leave it open it your text editor. In a commandline window, navigate to c:\apache\bin and type ...
httpd -k startIf there is an error message, re-edit httpd.conf and retry till Apache runs error-free.
In your browser's navigation control, type ...
localhostThe web page should say "It works!". If an app other than Apache responds, that app has already captured port 80. Fix that by running regedit, then navigating in regedit to ...
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\... and find the
ServiceName
that is the name of the Windows service which responded to your
web browser localhost
. That's the progeam that's taken control of port 80. In the right pane,
right click on DependsOnService
, select Modify
from the context menu,
add Apache24
to the list of dependencies; click OK; close Regedit.
Once Apache responds correctly to
To install PHP to run under IIS see here.
Copy php-ini-development.ini to php.ini.
Edit Windows environmental variables, select
Again editing c:\Apache\conf\httpd.conf in your text editor, add ...
When Apache runs without errors, write the following to c:\apache\htdocs\phpinfo.php:
Finally, run [Latest rev: 27 Oct 2020]localhost
, skip to Install PHP.
Enable IIS
If you've decided to use IIS instead of Apache, run appwiz.cpl, select
"Turn Windows features on or off", select "Internet Information Services",
click the checkbox. Windows will whir for a while then will tell you it's done.
In your browser's navigation control, type ...
localhost
The web page should say "IIS" in huge letters.
Install PHP for Apache
If you propose to use the MySQL version 8.0.22 and later default caching_sha2_password
authemtication plugin, you will need PHP 7.4 or later; download it from
here. Otherwise, choose your preferred PHP version from here. Unzip the download to c:\php.
Path
, add
PHPIniDir “C:/PHP”
AddHandler application/x-httpd-php .php
LoadModule php7_module “C:/PHP72/php7apache2_4.dll”
Save, and in the commandline window over c:\apache, run ...
httpd -k stop
httpd -k start
While errors occur, fix php.ini or httpd.conf and retry.
<?php
phpinfo();
?>
In your browser's navigation control, type localhost/phpinfo.php
...
and you will see your PHP settings.
Configure PHP to access MySQL and SSL
In your text editor, edit php.ini to uncomment these directives ...
extension=openssl
extension=mysqli
Restart Apache as before, run localhost/phpinfo.php
as before, and this time check
that mysqli is enabled.
services.msc
, scroll to Apache
, make sure the service is "Automatic",
and restart it. You're done.