Download a copy of Apache from Apache Lounge. You will probably want to download a current 64-bit edition (httpd-2.4.43-win64-VS16.zip). Once the .zip file is downloaded, extract the contents. Move the Apache24 folder to a location where you would like it to reside permanently. Note that Apache24, as a rule, should not be placed in:
- Any “Program Files” folders.
- Any “User” folder.
- Anywhere under AppData.
Apache should reside in a path without spaces (e.g. C:Apache24 by default). You will likely need to install the proper Visual Studio 2015-2019 C++ Redistributables as well.
Once you have Apache, download PHP. As indicated by the PHP.net sidebar, when using Apache, you need to use the “Thread Safe” versions of PHP. The latest Thread Safe version of PHP 64-bit is php-7.4.3-Win32-vc15-x64.zip. Similar to Apache, extract the .zip file and place its contents in a location where you would like it to reside permanently (e.g. C:PHP7). You will likely wish to avoid the same system-controlled folders as for Apache (above).
Lastly, download MySQL Community Edition. You can use the version which you find the most suitable, but for maximum compatibility you may wish to consider the older MySQL 5.x branch. As a recommendation, I might suggest the last 5.5 branch 64-bit installer (mysql-5.5.62-winx64.msi). You may wish to select a Custom installation type and place MySQL in a folder other than “Program Files”, however this is less important than with Apache or PHP.
Note that MySQL comes with a “MySQL Server Instance Configuration Wizard”. This can be ran automatically after installing MySQL. However, you can uncheck this option after installation is completed and run the same wizard at any time with MySQLInstanceConfig.exe in your MySQL bin folder.
Assuming you installed Apache into C:Apache24 (above), Apache should need no further tweaking to run. You should be able to start Apache with C:Apache24binhttpd.exe and go to localhost or 127.0.0.1 and see It Works! as a message returned in the browser. The default folder for web documents (.html files, .php scripts, etc.) is e.g. C:Apache24htdocs.
Copy either php.ini-development or php.ini-production and rename the duplicated file php.ini (all of these are typically located in the root of your PHP installation folder e.g. C:PHP7). The choice of which file to base your configuration off of (php.ini-development versus php.ini-production) is up to you. As indicated, php.ini-development is a configuration intended for developers and php.ini-production is a slightly more secure configuration intended for production (i.e. for use on servers exposed to the internet).
PHP generally shouldn’t need additional configuration unless your script requires specific functions or modules that aren’t a part of PHP’s defaults. That said, you can uncomment any necessary options in php.ini once it is created (remove the # at the start of the line and save the file). Any specific PHP configuration options required by your script(s) would likely be found with the source of the original script (i.e. on the website).
Run MySQLInstanceConfig.exe under the bin directory of your MySQL installation directory (e.g. C:MySQL Server 5.5binMySQLInstanceConfig.exe). Choose Detailed Configuration. The following options should work as a basic setup:
- Developer Machine (minimal memory usage).
- Multifunctional Database (InnoDB and MyISAM storage engines).
- Default placement of the InnoDB datafile (installation path).
- Online Transaction Processing (OLTP). Up to 500 connections. Note that selecting this option can be extremely important. Using a different option/number of connections may prevent the MySQL service from starting.
- Default networking options (Enable TCP/IP connections on port 3306, make sure to check “Add firewall exception for this port”, Enable Strict Mode).
- Standard Character Set (Latin1). If you are not using a “Western European” language, you may wish to choose “Best Support for Multilingualism” (UTF8).
- Install As A Windows Service. Check the “Launch the MySQL Server automatically” option.
- Include Bin Directory in Windows Path (optional). This simply makes it possible to run programs in your MySQL bin folder from the command line (in case you need them in a script, to check your MySQL version with mysqld -V, to easily manage MySQL as a service, etc.).
- Modify Security Settings (type in a new root password for accessing MySQL so you can log in with e.g. username root and password password_you_chose). For security, “Create An Anonymous Account” can be left unchecked in most cases, as can “Enable root access from remote machines” (unless you really need it).
Once all the appropriate options are selected, press the “Execute” button to apply your changes. The basic options given will be recorded in my.ini in your root MySQL directory. MySQL should now be running in the background as a service (independent of Apache/PHP).
Apache & PHP
To enable PHP processing with Apache, you will need to edit your httpd.conf file (e.g. C:Apache24confhttpd.conf) as indicated below . Place the following lines at the end of httpd.conf:
# —– PHP Configuration —– # LoadModule php7_module “c:/PHP7/php7apache2_4.dll” LoadModule php7_module “c:/PHP7/php7apache2_4.dll” AddHandler application/x-httpd-php .php # Configure the path to php.ini # PHPIniDir “c:/PHP7” PHPIniDir “c:/PHP7”
c:/PHP7 should match whatever directory you installed PHP into and php.ini should already exist (see PHP Configuration above). Don’t forget to save your changes and restart your Apache server.
You can verify that PHP is working on Apache by creating a .php file with the following line:
Save this as ex. version.php and place it in your root web directory (e.g. C:Apache24htdocs). You should be able to then navigate to ex. http://localhost/version.php and see a large amount of information about your PHP installation.
Starting Apache manually (i.e. not as a service) by running httpd.exe directly should generally produce no errors. However, to avoid a warning regarding Apache being unable to resolve a FQDN for the server, you may wish to uncomment the ServerName entry in httpd.conf (e.g. C:Apache24confhttpd.conf). The default www.example.com:80 works fine.
As indicated already, after updating httpd.conf or php.ini, you should always restart Apache to ensure your changes take effect.
If Apache will not start and/or generates errors, you should have a look at the logs to determine a cause (e.g. C:Apache24logserror.log).
Starting Apache manually with httpd.exe or with httpd.exe -k start (if Apache is installed as a service) may reveal specific configuration issues and the relevant files/line(s) Apache is having trouble with parsing.
To use an installation directory other than C:Apache24 or a web document root other than C:Apache24htdocs, you will need to edit httpd.conf. There may be other changes you need to make to this file to set up your web server correctly as well.
To enable SSL connections (HTTPS), you will need to obtain an SSL certificate and you will need to edit httpd-ssl.conf.
Apache is moderately security-conscious regarding which folders it allows to run scripts. If your PHP scripts are failing, they may not have the correct permissions to run.
Services can be managed via Services (Start Menu → Run/Search → “services” Enter).
Working with any Windows service requires administrative privileges, including an elevated command prompt (Start Menu → Run/Search → “cmd” Control + Shift + Enter).
You can install Apache as a service with httpd.exe. From an elevated command prompt (above), navigate to e.g. C:Apache24bin and run:
httpd -k install -n “Apache2.4”
On Windows, “Apache2.4” should be the default Apache service name. Using any other service name may cause issues.
If you have attempted to install Apache or MySQL as a service before, you may need to ensure they are no longer registered with Windows. First, make certain the service is stopped (again, you can check this with the Services via Start Menu → Run/Search → “services” Enter). Assuming the service isn’t running, open an elevated command prompt (above), then run e.g. sc delete Apache2.4 or sc delete MySQL.
Alternately, Apache and MySQL have ex. httpd -k uninstall -n “Apache2.4” (e.g. C:Apache24binhttpd.exe) and ex. mysqld –remove (e.g. C:MySQL Server 5.5binmysqld.exe) to remove each respective service.
- As already noted under the MySQL configuration section, selecting anything other than Online Transaction Processing (OLTP) for the number of concurrent connections (up to 500) may prevent the MySQL service from starting. Symptoms include the MySQL Server Instance Configuration Wizard “hanging” when attempting to start the MySQL service (after pressing “Execute”) or the inability to manually start the service in Windows (System error 1607 has occurred.)