How to install and configure PHP on windows 10
Here is a quick example of how to securely install PHP and configure it. In this quick article, you will learn how to install php, configure it and run your first php script.
The first thing you'll need to do is, obviously, install php. But which version ? The two main versions currently available are the 7.4.x and the 8.0.x. They are both equal except that the version 8 has new features.
You can see all these new features on the php 8 release page.
The installation process is exactly the same.
First, go to the php download page for windows and select the release version you want : 7.4.x or 8.0.x. Then, you will have to choose the php version.
Understanding the versions
Indeed, there are multiple version of the same release version : x86, x64, TS, NTS, ...
Let me explain these terms. x86 and x64 correspond to the build version. 32-bits processors will only support a x86 build version and 64-bits processors can support both. In most cases, you should download the x64 build version.
To check the architecture of your processor (32-bits or 64-bits) by typing
systemon the windows search bar. Then you should be able to find your processor architecture on the
Let's explain what TS and NTS mean. TS stands for Thread Same. This version is used to ensure that the data created and manipulated by multiple threads are same. In other words, a thread can not corrupt data manipulated by another thread. NTS is the opposite. Data manipulated by a thread can by corrupted by another one.
In most cases, you will need to download the x64 version with the Thread Same option. To download it, you just need to download
zip file which should be around 24 Mo.
Check the checksum hash
The next step is to check the sha256 hash of the version you've just downloaded. To do that, type the
certutil -hashfile /path/to/zip_file SHA256
This command should return the sha256 hash of the zip file you've just downloaded. It should return something like this :
Now, compare the hash returned by the previous command with the one from the php download page. If it matchs, everything is good. If it doesn't, be careful because the zip file you've just downloaded may be corrupted.
No that you have downloaded the zip file, you will need to do certain things in order to use the php language.
First, you will have to extract the content of the zip file. You can extract it wherever you want but you need to remember the location.
Set the environment variable
The next step is to create a new environment variable on your computer. This manipulation will allow you to use php anywhere on your computer. This is probably the most important step.
To do that, you will first need to open the environment variable window. You can do that by typing
environment variable on the windows search bar and press
enter. Then you need to locate and click on the
environment variable button on the bottom right corner of this new window.
Then, on the first section called
User variable for <username>, double click on
Path. On the new window, click on
New and then paste the location of the php folder you've previously extracted. What i mean by this is that you should paste the location of the folder that contains the
php.exe file. For instance, if you've extracted the zip file on
C:\Users\<username>\php-8.0.x then you have to paste this location on the environment variable window. You can now close each window.
At this step, you should be able to use php but, in order to use it from top to bottom, you have to make few changes. Thos changes will occure in the
php.ini file located in the php folder you've downloaded previously.
Currently, this file doesn't exist. But if you take a closer look, there are two files that look almost the same :
php.ini-production. In order to develop and create php projects, you'll need to use the development configuration. To do it, you have to rename the
php.ini-development file to
Now you will have to make few changes in this file.
The first thing you'll need to do is to uncomment the following line :
extension_dir = "ext"
Then, in order to fully use php in particular with frameworks such as Symfony or Laravel, you will need to add some extensions. To do that, you simply have to uncomment the following extensions :
Now, it should be fully functional. You should be able to use it as any other languages. But, let's check that everything is working well.
To check if php as been correctly installed, just type the following command.
It should return something like this :
PHP 8.0.7 (cli) (built: Jun 2 2021 00:41:03) ( ZTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
Zend Engine v4.0.7, Copyright (c) Zend Technologies
You can also run a very simple php command like this.
php -r "echo 'Hello World !';"
It should return
Hello World !.
Now that everything is working good, I recommend you to install and create a development environment. To do so, you can take a look at this post that explains how to create a development environment using WSL 2.
You can also install Composer to create better php projects.
Cover by Ben