This article picks up where we left off in my last article titled “XAMPP or WampServer or…? Think again!” where basic idea was to point out that you might not need bulky WAMP packages, and we also covered simpler yet smarter alternatives. In this article, we are going to install Apache 2.4 and PHP 7.1 on a Windows 10 machine.
If you don’t really require components such as FileZilla FTP server, Mercury Mail, MySQL or MariaDB, Perl, etc… that comes built-in with XAMPP, you can always opt to individually install the ones that you do need. This is in fact a better and modest choice.
Before we proceed…
Are you certain that your app “requires” to be developed in Apache environment? You may also look at this article that covers installing and configuring PHP 7 with Nginx web server on windows 10. Most importantly, If you are just looking forward to execute simpler PHP scripts or tests in a web browser then you don’t really need a fully loaded web server since PHP has its own built-in web server since PHP 5.4, and our primary article covers how you can use it, click here.
You need to have Microsoft Visual C++ Redistributable 15 (2017) and/or 14 (2015) (depending on packages that you select) installed on your PC beforehand. If not already installed, You may download VC15 and 14 from official Microsoft page: https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
2. Installing PHP 7.1
Note: Procedure is identical if you want to install a different version of PHP (i.e. 7.0 or 7.2)
- Download thread-safe PHP 7.1 binaries from this official PHP downloads page for Windows OS.
- Extract ZIP archive on a relevant location. (i.e. C:\PHP 7.1)
- Rename the php.ini-development file to simply php.ini
3. Installing Apache 2.4 web server
Please note that binaries for Windows 10 are not directly downloadable from official Apache website. Therefore you may download latest binaries of Apache 2.4 for Windows from either ApacheHaus or ApacheLounge.
The Apache HTTP Server Project itself does not provide binary releases of software, only source code. Individual committers may provide binary packages as a convenience, but it is not a release deliverable.
- Download a binaries package. In this example, I have downloaded Apache 2.4.29 for VC15 from ApacheLounge downloads page.
- Obviously, Extract this ZIP archive once downloaded
- Copy Apache24 directory into drive C: (i.e. C:\Apache24)
4. Configuring Apache 2.4 to work with PHP 7.1
- Open httpd.conf file in C:\Apache24\conf in a text editor.
DocumentRoot declaration and change paths to your own working directory. (You may also skip this step by simply moving all your work files to working directory that is already configured)
So, if your working directory is D:\Work, you will change paths to:
DirectoryIndex directive and add “index.php”
- Add following lines at top of this
LoadModule php7_module "c:/PHP 7.1/php7apache2_4.dll"PHPIniDir "c:/PHP 7.1"AddHandler application/x-httpd-php .phpAddType application/x-httpd-php .php
- Save and close configuration file!
- Create a simple phpinfo file in your working directory
- Execute C:\Apache24\bin\httpd.exe file (Command prompt window will stay open until you close this window or terminate process manually which will cause Apache to stop working as well)
- Open web browser and visit http://localhost/ to open your phpinfo file
Here are screenshots from a local machine after successful installation:
6. Install Apache 2.4 as service
Optionally, you may install Apache 2.4 as service to have it running in background all the time. This may be preferred since you will not be required to keep a command prompt window open all the time.
- Open command prompt (as Administrator)
- Navigate to c:\Apache24\bin
- To install, execute httpd.exe -k install
- To start or stop, execute net start Apache2.4 or net stop Apache2.4
- To uninstall as service, execute httpd.exe -k uninstall
Note: You may also create a shortcut to “ApacheMonitor.exe” on desktop. Opening this will show ApacheMonitor icon in notifications tray area and you will be able to manage Apache 2.4 once it has been installed as service.