Installing the PHP Interpreter

Installing PHP

Installing PHP will look a little different depending on the operating system you're using, but I'll run through the basics for three common environments!

If you'd like to check if you already have PHP installed, try running the following in your terminal:

php --version

If you don't have PHP installed you'll get an error letting you know that your terminal could not understand or find the command: "PHP." If you do have it installed, you'll see the program output the version number and details in your terminal—you'll know you're good-to-go!

Linux (Ubuntu)

Many popular Linux distributions use APT for managing your installed programs. This comes in handy when installing programs to your computer—PHP is no exception!

Open your terminal and type in the following commands:

# Grabs latest package lists apt-get update # Installs the PHP interpretor to your computer apt-get install php

MacOS

To make things as easy on Macintosh as it can be on Linux, it is a good idea to install Brew: a package manager for Macintosh. It helps you quickly install software like PHP.

Not sure if you have Brew installed? We can run the following in the terminal:

brew --version

If the program is not installed, the terminal will let you know that the command "brew" is not found, or available. Otherwise, it will simply print the version into the terminal and you'll know it is ready to roll!

If you don't have Brew installed, you can do so by opening your terminal and entering the following:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once Brew is installed, open your terminal and enter the following command:

brew install php

Windows

There are a number of ways to install and configure PHP on a Windows computer. If you haven't already, you may want to look into Microsoft's WSL in order to take advantage of the Linux workflow!

If you'd like to run PHP directly in Windows, however, here are two popular approaches:

Windows Package Manager

If you want a straightforward, terminal-based approach, like the ones seen above with Linux and MacOS—you're in-luck! There do exist tools for this purpose. An example of a well-supported one for Windows is Chocolatey.

It is best to visit the official installation guide for Chocolatey if you don't already have it installed, as it will always be the most up-to-date place to check. Once you have it installed, open PowerShell as an administrator and enter the following:

choco install php -y

Manual Installation

If you'd rather avoid a package manager and would like to do things the old-fashioned way, the official PHP web sites have pages dedicated to this purpose.

  1. Visit the official Windows PHP download page and download the latest Non Thread Safe version (unless you know you need a more specific version.)
  2. Once the .zip file is downloaded, decide where you would like your PHP interpretor to live. Ensure you place this somewhere you'll remember, and that will be easy to access if you need to change any settings down the road. For example: C:\tools\php or C:\Users\{YOUR_NAME}\php might be directories that make sense to you. Unpack the .zip contents to a new PHP directory, making note of its location.
  3. Press Windows key + S to bring up the "Windows Search" feature, and enter this search: "Edit the system environment variables". Select the option that appears, and it will open a "System Properties" window.
  4. At the bottom of this new window, there should be a button that reads "Environment Variables". Click it! This will open another, more specialized window: "Environment Variables".
  5. There are likely two white boxes in this window, one labeled "User variables for {YOUR_NAME}" and another labeled "System Variables". Scroll through the second one, the System Variables. Find the row that reads "Path". The "Path" variable on your computer is a list of directories and programs that you can run anywhere via your terminal. We want to add PHP to this list. Click "Edit" for the "Path" variable, and another window will open called "Edit environment variable".
  6. In the "Edit environment variable" window there are probably already a few directories. You want to click, at the top right, the "New" button. This will highlight a new field at the bottom of the list, allowing you to add your own entry.
  7. Remember we unzipped the PHP download earlier? That location is important! Write out the full address that you extracted PHP to. Don't go so far as to type out php.exe at the end, only write out the directory. For example, again, yours might be something like C:\tools\php or C:\Users\{YOUR_NAME}\php. If in-doubt, have a look at where you extracted your zip to and come back to this window.
  8. Once done, press "OK" in the windows that are open. Once all are happy with your changes, open up a fresh Command Prompt or PowerShell window and check if PHP can be run in your terminal:
php --version
  1. If the version prints, you're all-set!

Toggle Dark Mode