Installing PHP on Windows 10 and 11

Installing php on windows 10 and 11

If you're new to PHP or have a Microsoft Windows machine you want to install a fresh copy of PHP on, then this guide is for you. There are countless ways to install PHP on your Windows PC, some require third-party software, and others don't. In this guide, we will step you through the process of installing PHP directly onto your machine without the need for third-party software. With this guide, you'll end up with PHP installed natively on your machine, with the application coming directly from the source, php.net. We will also provide the necessary steps to ensure you can also use PHP on the command line (CLI) using the command prompt "cmd.exe".

What is PHP?

Before we begin down the installing route of PHP, what is PHP and why might you be looking to install the open-source programming language on your Windows machine?

Known for its ease of use, and versatility, PHP is a hugely popular server-side scripting language, mainly used in web development for all shapes and sized websites. PHP is the programming language by many popular companies globally and is the perfect choice when creating dynamically driven web applications. Installing PHP directly onto your Windows 10 and 11 machine allows you to code, build, and test your web application locally (on your device) before you're ready to unless it to the world, known as local development. When you first start out, playing with what PHP has to offer, using your own computer as a sandbox is a great way to learn. You don't risk breaking something important on a "live" environment, nor need to fork out web servers in order to run your PHP application. That all comes later! Installing PHP on your local machine is a relatively simple process, let's explore how we can get PHP installed and set up on Windows.

Installing PHP on Windows 10 and 11

This step-by-step guide applies to Windows 10 and 11, other versions of Windows may require additional steps and these steps do not apply if you're on a Unix-based system, like Untubu.

Step 1. Download the PHP programming language

First things first, you need to obtain PHP from the official PHP website. To get hold of the latest version go to the PHP download for Windows section of php.net. Here they provide four different versions which you can choose from and are designed for different styles of development.

Firstly you have two-bit editions, 32-bit, and 64-bit. Depending on what system architecture you have, you should download the version that matches your architecture. The easiest way to check is by viewing your computer's information, from the Windows settings section.

Next, you need to decide if you want to download the thread-safe or non-thread-safe version. The version you require depends on the type of server you wish to run, including the types of extensions you might run in PHP. Typically, we choose the thread-safe version if you're thinking of running an Apache web server with the PHP module "mod_php" (VS16 x84 thread-safe). However, if you're going to be running the FastCGI module instead, you should opt for a non-thread-safe version (VS16 x84 non-thread-safe).

If you're still unsure at this point which is best, most commonly the thread-safe version is run as this has wider support for the most common web server software available. It's worth noting that you can still use FastCGI with Apache if this is what's required, to do that you'll need the "mod_fastcgi" module installed. As FastCGI is a protocol for interfacing web servers with applications like PHP, it can be used with a variety of different types of web servers, such as Microsoft IIS, and Nginx.

Step 2. Extract the files to the PATH location on your machine

Once you've downloaded the PHP software, you'll need to use Window's built-in ZIP extractor to save the files locally on your machine. For this, it's easiest to choose a location that is already in your system's PATH location, i.e. C:\php. instead of Desktop or My Documents for example. By installing PHP in one of your system's PATH locations, you'll be able to use PHP on the command line without any extra configuration.

Step 3. Configure PHP

Next, you can configure PHP ready for use. In each install, there should be a file called; "php.ini-development". This is the example php.ini file PHP provides for you to use within your application. Using this file marks a good starting point to help get PHP up and running. Before it can be used, you should rename the file by removing the words "-development", resulting in the filename called; "php.ini". When PHP is run, PHP itself looks for php.ini in various locations. That's why, in order for it to work, it must have this filename.

The php.ini file contains all the configuration settings for the PHP application, such as memory limit, timezone, enabled PHP exertions, and more. Anything related to PHP's internal configuration should go in this file.

Step 4. Restart your web server or use PHP's built-in

Next, you should restart your web server software to take into account changes made to PHP. However, if you're building a development box, you can use PHP's built-in web server using PHP on the command line. By passing "-S" (capital "S"), you can ask PHP to act as a web server at a location of your choice. The easiest and most common is "localhost" and most people tend to tell PHP a predefined port number too; typically 8080 or 8000. You normally do this so it doesn't clash with our ports on your system. It's important to note, that using PHP's built-in web server isn't recommended for production-level applications, and you should use something like Apache instead. For development staging websites, it works just great! With PHP's built-in server, it can also be used to connect to other services on your machine like MySQL using the MySQLi extension.

# start a web server at localhost
php -S localhost

# or specify the port too
php -S localhost:8000

# load with the MySQLi support
php -S localhost:8000 -d extension=mysqli

Step 5. Test PHP

Now it's time to check PHP has been installed and works as expected. Create a PHP file "index.php" inside your webserver's root directory, on Windows, that's typical "C:\inetpub\wwwroot" and add some PHP code inside the file. The easiest code to add is the PHP info function, which is built into PHP.

phpinfo();

With the file saved with this code inside, next in your web browser navigate to "http://localhost/index.php" or just "http://localhost" because by default PHP will attempt to load a file called "index.php". Remember to navigate to non-HTTPs as your web server won't be configured to support a self-signed SSL certificate, and you may experience an error in the web browser.

Conclusion

Once you've got PHP installed on your local machine you can start building web applications and generally have fun with PHP. This guide covers how to install Windows-based machines running either version 10 or 11. The steps taken will be similar for other versions of Windows too if you're running something different.

  • Download the correct version for your system's architecture
  • Install PHP in a folder that is in your PATH location so you can use PHP's built-in server on the command line
  • Configure the php.ini to match your requirements
  • Spin up a web server using Apache, PHP built-in web server, or similar
  • Check PHP works, by adding a file into the webroot and then browsing to it
  • Start creating great things and learning how truly powerful PHP can be

Senior PHP developer. Author of Dev Lateral guides and tools. The complete place for PHP programmers. Available to hire to help you build or maintain your PHP application.

Looking for industry-leading PHP web development?

API development WordPress Hosting ★ and more 🐘

We use cookies to enhance your browsing experience, and analyse website traffic in accordance with our Privacy and Cookie Policy. Our cookies, including those provided by third parties, collect anonymous information about website usage and may be used for targeted advertising purposes. By clicking "Reject non-essential" you can opt out of non-essential cookies. By clicking "Accept all" you agree to the use of all cookies.


Reject non-essential Accept all