Today we will see how to install the latest version of PHP that is php 8.0.9 in the windows 10 operating system and macOS.
PHP stands for Hypertext Preprocessor and it’s an open-source scripting language. It was originally built by Rasmus Lerdorf in 1994. You can make dynamic and interactive websites with this language. It is a great alternative to competitors such as Microsoft’s ASP (Active Server Page) and is widely used.
So let’s begin now on how to install the latest version of PHP.
Install PHP on Windows
To install PHP on Windows 10 operating system, you have to download it from the official website. You will get a zip folder and then move this folder to your drive.
Steps to Install PHP on Windows
- Goto official website (https://www.php.net)
- Download the latest version of PHP as a zip folder
- Extract it and place in C drive
- Set up the environment variables for PHP
- And create a simple .php file and run the script in command using this command
Let’s explain each step and see how you can do this.
You need to first download it. So for that just simply go to your favorite browser and in here just simply type ‘php download‘ then enter. Then you’ll be seeing this first result is from www.php.net.
So just click on ‘Download PHP‘ and this will going to redirect you to this official site of PHP. You will see this is the download page of all versions of PHP but in this tutorial, we will download and install the latest version of PHP.
So just simply click on the ‘Windows downloads‘ and this will going to redirect you to windows.php.net.
Here you will see the Thread Safe option. So just simply click on the zip version option and it will start downloading php 8.0.10 version for you.
After downloading, you will see your download zip file in your download location, so open that folder. Here you need to just simply right-click on the zip folder and extract it.
You can rename this extracted folder as short ‘php-8.0.10‘ if you want. So now simply copy this folder and move it into your C drive.
After moving it, copy the location of this folder by clicking on the address bar and you will get like this C:\php-8.0.10.
Now if you just simply go to your windows search icon and type ‘environment variables‘. You will be getting the Edit the system environment variables, so just simply click on that.
Note: If you have not found this option then follow this path ‘Control Panel\All Control Panel Items\System‘. Here you will see the Advanced system settings option and click on it.
Now you will see a dialog box. So under the Advanced tab simply click on the ‘Environment Variables‘ button at the bottom.
It will open another dialog box and here you will see all the System variables. So from here find the Path variable and then click on the Edit button.
It will again give you another dialog box and here you will add your php folder location path. So simply click on the New button and paste the php-8.0.10 folder path and then click on the OK button. So close all the dialog boxes by clicking on the OK button to save our environment variable for PHP.
Let’s check now our PHP is installed correctly or not. So again simply click on the search icon and type cmd and open the command prompt.
In the command prompt simply type
php --version then enter. You can clearly see our latest version of PHP that is php 8.0.10 has been rightly installed.
So, now if you want to run the PHP file then that is also very easy. Simply create a php file called hello.php and add the following code to it.
Save this file and open your command prompt. Make sure you open the command prompt in the same location of the file, if this is not the same location then you can move into that folder by
cd command ( cd your_file_folder ).
To run the php program in the command prompt, type the php and then your file name like
php hello.php. You will see the output hello world has been shown in console.
So in this way, you can easily install PHP on your Windows 10 operating system and can run and execute a simple PHP code snippet in your windows 10 operating system.
So that’s all.
Install PHP on MacOS
The latest version of macOS comes with an in-built installed PHP 5.6 or a lower version. But now, you know PHP 8 version is available to download and work with that. So the following step will help you upgrade your PHP version in macOS.
Further to install PHP, you must know how to use Terminal and Homebrew. The terminal is the command interface where you will type commands and Homebrew is a package manager for Mac operating system. With this, you can install open-source applications like PHP, Node, etc.
Steps to Install PHP on macOS
Follow the below steps to install PHP on Mac operating system using the Homebrew package manager.
- Upgrade the brew package manager
- Upgrade the PHP version
- brew upgrade php
- Wait for finish the upgrade you will see successfull message
- Check the latest PHP version
- Done! you will see your PHP version is updated
Let’s explain each step and see how you can do this.
As I said, your system has Homebrew installed on it and you are familiar with a terminal to use the command-line interface. If you don’t have brew installed on it then first install it. If you don’t know how to install Homebrew then let me know in the comment, I’ll help you with installation.
OK, the first thing you need to make is sure your brew is up-to-date (If it is already installed on your system). Use the following command to check it.
Now check the first version of PHP before upgrading it. So after an upgrade, we can be sure it is updated to the latest version of PHP.
Now you can update your PHP old version to the latest version using the brew command. The brew command is the following.
This command is very interesting and important to update the PHP version. Make sure the spelling is correct for the command.
It will start the downloading of a new version of PHP and its dependencies. After successfully upgrading the PHP version, you will see the result something like the below in your terminal.
You need to restart your Nginx server or Apache server to check the latest version of PHP. So use the following command to restart the server respectively.
After restarting the server, check again PHP version using the following command to make sure your Mac operating system has the latest version of PHP now.
and you will see the result like below:
Hope you understand and see how you can install PHP on Windows and macOS. If you face any problem while installing please let me know in the comment I’ll help you with that.