Php Installation On Windows 10

Posted on
  1. Install Php On Windows 10 Command Line
  2. Php 7 Installation On Windows 10
  3. Php Installation On Windows Server 2012
  4. Install Php 7.3 On Windows 10
  • To install PHP by using Web PI Open a browser to the following website: Microsoft Web Platform Installer 3.0. Click Download It Now, and then click Run. At the top of the Web Platform Installer window, click Products.
  • But, Microsoft now offers a great option for PHP developers who work on Windows: The Windows Subsystem for Linux (WSL). WSL is a compatibility layer for running Linux binary executables (in ELF format) natively on Windows 10.

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: https://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 https://windows.php.net/qa/.

Open up the FastCGI settings window and then click on Add Application on the right hand side. The Full Path should be the path to the php-cgi.exe file within the folder that you previously unzipped the install files to. Make sure to select the php-cgi.exe and not the php.exe file. These are the previous steps to install PHP in Windows 10. In order for the Apache server to correctly interpret the PHP language, it is necessary to rename the index.html file located in the following path: C:Apache24htdocs. Once the file is selected, change its extension to.php.

PHP For Windows. This site is dedicated to supporting PHP on Microsoft Windows. It also supports ports of PHP extensions or features as well as providing special builds for the various Windows architectures. If you like to build your own PHP binaries, instructions can be found on.

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.

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. .

Php

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: php -v 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 env. 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.

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:

Windows
  • php.ini-production
  • php.ini-development

Copy the development version to the same directory as php.ini 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_dir parameter to the valid location: extension_dir = 'c:Program FilesPHPphp-8.0.0RC2ext'


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.


Finally, you need to set the location where to save the session data: session.save_path = 'w:/tmp'

Installing Apache

Php Installation On Windows 10

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 bin folder.

Apache configuration files are located in the conf directory. The main config file is the httpd.conf . To start the webserver you need to set the server root (SRVROOT) parameter in the config file to the correct location as follows:

It is a good idea to set the ServerName explicitly to prevent problems during startup. As we will use virtual hosts later, you can simply set it to 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.

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: httpd -k install
Then you can start the webserver using httpd -k start

Allow access:

If everything is correct, then you get the prompt back without any message.

Open a browser and type http://localhost as the URL. You should get a welcome page similar to this:

The default document location is the htdocsfolder 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 site1.com and site2.com are the production sites, then you probably want a site1.local and site2.local 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 httpd.conf file and uncomment the line that includes the httpd-vhosts.conf file.


Then, open the httpd-vhosts.conf file that is in the extra folder. Add one entry for each project you want. The ServerName , DocumentRoot , and ErrorLog are the important parameters, you can skip the others.


Besides this, you have to allow access to these folders so add a common Directory block with the following content before the VirtualHosts entries.
Your final virtual host config file should look like this:

You also need to extend the Windows hosts file that is located in c:WindowsSystem32driversetchosts. 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.

Put a simple index.html file in the site roots with different content for testing purposes.
Now you can restart Apache using httpd -k restart . 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 mime.types config file: application/x-httpd-php php

To execute the index.php automatically if a directory is requested, extend the DirectoryIndex property with index.php in httpd.conf .

Installation

After 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 httpd.conf file. Just insert the lines at the end of the httpd.conf :

Now 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:

Visiting site1.local/info.php should result in a PHP information page in your browser.

The 'Can't locate API module structure 'php8_module' in file ..' error message is a common problem. Verify that exactly php_module is in the LoadModule line. Neither the old php7_module nor the expected php8_module is good.

Install Php On Windows 10 Command Line

Video

If you need to install a PHP on your local Windows machine with Internet Information Services (IIS), Microsoft has already provided a way where you can do it fairly quickly using WPI.

Keep in mind though, this setup has not been tested for production environment. So only use it as a PHP development environment for Windows. Internet edge download freebitsoftsoftsc.

Steps

  1. Open Control Panel ->Programs and Features ->Turn Windows features on or off. Under Internet Information Services ->World Wide Web Services ->Application Development Features, make sure that option CGI is checked. This enables both the CGI and FastCGI services.

  2. Download Web Platform Installer. For this example for Windows 10 64-bit, it’s the WebPI 5.0 x64.

  3. Double-click on WebPlatformInstaller_amd64_en-US.msi to install it.

  4. Once installed, you should see a file with the name wpilauncher.exe. Double-click it.

  5. When you see the Window, click on the Products link and search for “php” and press ENTER.

  6. Add PHP 7.0.9 (x64) (or later version if available) as an item to install. Selecting this will automatically add Windows Cache Extension and PHP Manager for IIS.

  7. (Optional) If you need to connect to SQL Server using PHP, you need to install Microsoft Drivers 4.0 (x64) for PHP v7.0 for SQL Server in IIS.

  8. Click on Install button.

Php 7 Installation On Windows 10

The downside of this installation is probably WPI may have a mind on its own and install other components that you didn’t choose as shown below:

If you see a failed installation for PHP Manager for IIS like above, don’t worry about it. That component is only used to provide a GUI for managing PHP from IIS. You can still use the command line and text editor to make configuration changes.

As always you can always test your PHP installation by creating a test.php file with this PHP code.

Php Installation On Windows Server 2012

And run it from your browser (i.e., http://localhost/test.php). If PHP is installed correctly, you will see something similar to this:

You may notice that the version of PHP installed using WPI is usually several versions behind the release version. Fortunately, you can always download PHP for Windows yourself and upgrade your PHP installation on Windows to a newer version with just a few additional steps explained on this post.

Further Reading

PHP for the Web: Visual QuickStart Guide (5th Edition)
Modern PHP: New Features and Good Practices
How to Upgrade to PHP 7.1 on Windows 10
How to Upgrade from PHP 7.1 to PHP 7.2 on IIS (Windows 10)
FastCGI
Using FastCGI to Host PHP Applications on IIS 7

Install Php 7.3 On Windows 10

Download