PHP 8 is on the way. In this tutorial, I will show you how to install PHP 8 on your Windows 10 machine using Apache as a webserver.
Download the necessary files
You can download PHP binaries from the URL: //windows.php.net/download/.
Currently, the final version of PHP 8 has not been released, therefore, it cannot be found on the main page. Select the "QA Releases" from the top menu or navigate directly to //windows.php.net/qa/.
Download the thread-safe, 32, or 64-bit version depending on your Windows type. As all versions have been compiled with VisualStudio 16 [2019], so later, you need a suitable Apache binary and a "Microsoft Visual C++ 2019 Redistributable" package installed on your PC.
Prepare PHP location
I like the programs to be in the Program Files folder. Besides this, over time, you will install several different versions of PHP. Therefore, I create the following directory structure:
For the sake of ease of use, I make some sacrifices in the security of my development machine. I give local users full permission to the PHP directory on my machine.
Once you have created the directory, copy the contents of the downloaded zip file.
Check if PHP works
As I mentioned earlier, PHP 8 was compiled with Visual Studio 2019. Thus, if the appropriate Redistributable is not installed on your machine, you will get the following error:
... VCRUNTIME140.dll was not found. ..
You can download the file from Microsoft Redistributable download
If all went well, you can use PHP from the command line. You can check the installation with the command:
extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
4 and the result should be something similar:To make working with PHP more convenient, you can put the PHP directory on the path. Click on start and just type
extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
5. From the list click on "Edit the system environment variables" and the System Properties dialog will appear. Click the "Environment Variables..." and select "Path" from the System variables block. Add the new PHP folder to the list.Configure PHP
Now PHP is running but not yet configured properly. Configuring PHP 8 at the base level is no different from older versions.
The PHP folder contains 2 example configuration files:
- php.ini-production
- php.ini-development
Copy the development version to the same directory as
extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
6 and open this for editing. What you need to set is the location of the extensions and session data. You have to set the
extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
7 parameter to the valid location: extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
8extension_dir = "c:\Program Files\PHP\php-8.0.0RC2\ext"
You also have to uncomment the required extensions from the list. Usually, the curl, gd, mbstring, mysqli, pdo_mysql extensions are required for complex php apps.
extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
Finally, you need to set the location where to save the session data:
extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
9session.save_path = "w:/tmp"
Installing Apache
Even if PHP has a built-in web server, production systems use Apache, Ngnix, Lightspeed, and so on. For a Windows development environment, Apache is the easiest choice.
You can download the latest Apache webserver from the ApacheLounge website. Download the 32 or 64-bit version depending on your OS type.
As I mentioned before, I don't like everything in the C: root, so I also create a directory for Apache in the Program Files folder. Don't forget to allow permissions for the users.
Now you can copy the content of the Apache24 folder of the zip file to the new location. Pay attention to the exact directory structure.
As with PHP, you can add Apache to the path, but in this case, you need to add the
session.save_path = "w:/tmp"
0 folder.Basic Apache configuration
Apache configuration files are located in the
session.save_path = "w:/tmp"
1 directory. The main config file is the session.save_path = "w:/tmp"
2 . To start the webserver you need to set the server root [session.save_path = "w:/tmp"
3] parameter in the config file to the correct location as follows: Define SRVROOT "c:/Program Files/Apache/httpd-2.4.46"
ServerRoot "$ {SRVROOT}"
It is a good idea to set the
session.save_path = "w:/tmp"
4 explicitly to prevent problems during startup. As we will use virtual hosts later, you can simply set it to session.save_path = "w:/tmp"
5ServerName localhost:80
An optional step - but usually required by most PHP applications - to enable Apache modules. For example, the mod_rewrite module is disabled by default but almost always required. Just uncomment the line and you are done.
LoadModule rewrite_module modules/mod_rewrite.so
Install Apache as a service
To install Apache as a windows service, you have to open a command prompt as an administrator. Navigate to the Apache bin directory and execute the command:
session.save_path = "w:/tmp"
6Then you can start the webserver using
session.save_path = "w:/tmp"
7Allow access:
If everything is correct, then you get the prompt back without any message.
Open a browser and type
session.save_path = "w:/tmp"
8 as the URL. You should get a welcome page similar to this:
Setup virtual hosts
The default document location is the
session.save_path = "w:/tmp"
9folder in the installation directory. However, this is not optimal. If you are a developer, you probably work on multiple web projects. So it would be nice to have a dedicated folder and URL for each project. For example, if Define SRVROOT "c:/Program Files/Apache/httpd-2.4.46"
ServerRoot "$ {SRVROOT}"
0 and Define SRVROOT "c:/Program Files/Apache/httpd-2.4.46"
ServerRoot "$ {SRVROOT}"
1 are the production sites, then you probably want a Define SRVROOT "c:/Program Files/Apache/httpd-2.4.46"
ServerRoot "$ {SRVROOT}"
2 and Define SRVROOT "c:/Program Files/Apache/httpd-2.4.46"
ServerRoot "$ {SRVROOT}"
3 URLs with a dedicated target folder for your development.
Virtual hosts are the solution to this problem.
Again, it is a good idea to store your code separated from drive C.
For example, you can create a directory structure like this:
Now you have to configure virtual hosts and enable it. First, open the
session.save_path = "w:/tmp"
2 file and uncomment the line that includes the Define SRVROOT "c:/Program Files/Apache/httpd-2.4.46"
ServerRoot "$ {SRVROOT}"
5 file.# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Then, open the
Define SRVROOT "c:/Program Files/Apache/httpd-2.4.46"
ServerRoot "$ {SRVROOT}"
5 file that is in the Define SRVROOT "c:/Program Files/Apache/httpd-2.4.46"
ServerRoot "$ {SRVROOT}"
7 folder. Add one entry for each project you want. The session.save_path = "w:/tmp"
4 , Define SRVROOT "c:/Program Files/Apache/httpd-2.4.46"
ServerRoot "$ {SRVROOT}"
9 , and ServerName localhost:80
0 are the important parameters, you can skip the others.
ServerName site1.local
DocumentRoot "w:/Websites/site1.local"
ErrorLog "w:/Websites/site1.local/error.log"
Besides this, you have to allow access to these folders so add a common
ServerName localhost:80
1 block with the following content before the VirtualHosts entries.Your final virtual host config file should look like this:
Options FollowSymLinks
AllowOverride All
Require all granted
ServerName site1.local
DocumentRoot "w:/Websites/site1.local"
ErrorLog "w:/Websites/site1.local/error.log"
ServerName site2.local
DocumentRoot "w:/Websites/site2.local"
ErrorLog "w:/Websites/site2.local/error.log"
You also need to extend the Windows hosts file that is located in
ServerName localhost:80
2. Open the file for editing with administration privileges and add the server names used before to the file pointing to the local 127.0.0.1 IP address. # localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 site1.local
127.0.0.1 site2.local
Put a simple index.html file in the site roots with different content for testing purposes.
Now you can restart Apache using
ServerName localhost:80
3 . If everything is correct, then no error message is displayed. Navigate to site1.local and site2.local, and your browser should display the corresponding Html content.Setup Apache to use PHP 8
The setup is almost done, but we haven’t configured PHP and Apache to work together.
First, we have to add the php extension to the known mime types. To do this, add the following line at the end of the
ServerName localhost:80
4 config file: ServerName localhost:80
5extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
0To execute the
ServerName localhost:80
6 automatically if a directory is requested, extend the ServerName localhost:80
7 property with ServerName localhost:80
6 in session.save_path = "w:/tmp"
2 .extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
1After that, the most important step is to load the php module. To do this, specify the PHP install directory and the appropriate module in the
session.save_path = "w:/tmp"
2 file. Just insert the lines at the end of the session.save_path = "w:/tmp"
2 :extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
2Now you can restart apache and check for any error. If everything is fine then create a small inf.php file in the server document root with a simple phpinfo like this:
extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
3Visiting site1.local/info.php should result in a PHP information page in your browser.
Troubleshooting
The "Can't locate API module structure 'php8_module' in file ..." error message is a common problem. Verify that exactly
LoadModule rewrite_module modules/mod_rewrite.so
2 is in the LoadModule line. Neither the old LoadModule rewrite_module modules/mod_rewrite.so
3 nor the expected LoadModule rewrite_module modules/mod_rewrite.so
4 is good.