The open source scripting language PHP can be installed and used on all common operating systems. If you meet all the system re­quire­ments, you can just download your desired PHP version. On Unix and Windows, it takes just three steps to install PHP.

Cheap domain names – buy yours now
  • Free website pro­tec­tion with SSL Wildcard included
  • Free private re­gis­tra­tion for greater privacy
  • Free Domain Connect for easy DNS setup

What you need to run PHP

Your system must meet specific re­quire­ments to run PHP. These may differ depending on your operating system. So before you get started in­stalling PHP, check the system re­quire­ments. Some of them will apply to all operating systems. For example, to run PHP, you need a web server. You can set up the Apache web server for this purpose. In most cases, a database such as MySQL or MariaDB will also be needed.

Tip

With IONOS Web Hosting all PHP versions from version 4+ are supported for your web de­vel­op­ment goals. Register your domain and benefit from an in­teg­rated wildcard SSL cer­ti­fic­ate.

UNIX-based systems

In­stalling PHP on UNIX systems like Linux doesn’t require much ad­di­tion­al work. Linux and the most common Linux dis­tri­bu­tions provide most of the com­pon­ents you need. Only an ANSI C compiler and module-specific com­pon­ents such as PDF libraries may need to be installed manually.

Windows

To install PHP on Windows, first ensure that your Windows version is com­pat­ible with PHP. All versions released after Windows 2008 or Windows Vista provide basic com­pat­ib­il­ity for PHP 7.2.0+.

On Windows you need the option to deal with C code. To set this up, download Visual C Runtime or C Runtime Files (CRT). You also need a suitable Visual Studio version. For most common PHP versions, Microsoft Visual C++ Re­dis­trib­ut­able for Visual Studio 2019 is a suitable choice.

macOS

Provided you own a Mac, you don’t need to do anything else to install PHP. The scripting language is included in modern macOS versions.

Download PHP

If your system meets the re­quire­ments, download the PHP version of your choice. There are several versions available for manual download from the official PHP website. Download is necessary on Windows. On Linux, in­stall­a­tion and download can be performed via the command line. On macOS, PHP is pre-installed.

Be sure to select the right link to download PHP for Windows.

Which PHP version is the correct one?

Unless you’re learning PHP for the first time, it’s re­com­men­ded to download the 'Current Stable' version. That’s the latest PHP version out of beta which runs error-free (as far as is known). Right now, the latest stable version is PHP 8. Although beta versions offer more features, they can be quite buggy. It’s best not to update your PHP version until the end of beta testing.

If you’re in­stalling PHP for a specific purpose, for example, for existing projects or to use the best WordPress plugins 2022. Check which PHP version is re­com­men­ded. Currently, the 'Old stable' version 7.4 is con­sidered most com­pat­ible with WordPress.

Tip

Decided to use PHP 7? Then you can’t go wrong with system-in­de­pend­ent PHP 7 Hosting from IONOS. Older PHP versions are also supported.

Install PHP on Linux step by step

You can install PHP on Linux using the terminal. The process is quick and simple. Knowing the most important Linux terminal commands will come in handy. The following step-by-step in­struc­tions refer to the in­stall­a­tion of PHP under Linux dis­tri­bu­tion Ubuntu.

Step 1: Update system and package

First, ensure that your system and all packages are up to date. To do this, use the following terminal commands:

sudo apt-get update
sudo apt-get upgrade

The terminal will prompt you to enter your password, after which your system will be updated.

Sep 2: Install PHP

Now, PHP needs to be installed. Use the following command to do so:

sudo apt-get install php

In­stall­a­tion must be confirmed manually in the terminal and is then executed auto­mat­ic­ally.

Step 3: Check PHP version

Once you’ve installed PHP, you can easily check which version you’re using:

php -v

An al­tern­at­ive under Ubuntu is to install LAMP stack

Depending on purpose, you may want to download and install a LAMP server. This way you get the PHP, Apache web server and MySQL all in one. Use the following commands:

sudo apt install tasksel
sudo tasksel install lamp-server

After you’ve installed the Tasksel setup tool, the second command installs the LAMP server including PHP in a single step.

Special features of other Linux dis­tri­bu­tions

Generally, in­stall­a­tion of PHP isn’t all that different between the various Linux dis­tri­bu­tions. But there are some small dif­fer­ences.

Debian

The in­stall­a­tion of PHP under Debian will work using the above commands. In addition to the apt-get command, there’s the aptitude command. This is a package manager that provides a menu interface, but doesn’t differ much from apt-get otherwise.

The command to install PHP using aptitude is:

sudo aptitude install php

CentOS

The Linux dis­tri­bu­tion CentOS uses a different package manager, yum, and thus requires slightly different commands to install PHP. But the steps you use to install PHP are otherwise identical.

First, update your system and packages:

sudo yum install epel-release
sudo yum update

In­stalling PHP uses a similar command to Ubuntu:

sudo yum install php

How to install PHP on Windows

You’ve got several options to install PHP on your Windows system. Besides manual con­fig­ur­a­tion with the Internet In­form­a­tion Service (IIS), you can download the Microsoft Web Platform Installer and add PHP via the graphical user interface.

Step 1: Download Microsoft Web Platform Installer

Download Microsoft Web Platform Installer. Follow the steps as prompted in the in­stall­a­tion program.

Step2: Adding PHP to Web Platform Installer

Open the ap­plic­a­tion and click on the ‘Products’ tab. In the search box at the top left, you can search for your favourite PHP version. Select it from the list. To ensure PHP is listed under the ‘Documents to install’ button click ‘Add’.

Step 3: Install PHP

PHP is now shown in the list of your documents to be installed. Clicking 'Install' at the bottom right will begin automatic in­stall­a­tion of the PHP version you’ve selected. Restart your computer to complete in­stall­a­tion.

Al­tern­at­ive under Windows – XAMPP

Like on Linux, PHP can be used on Windows by in­stalling everything you need for the LAMP stack. You can use the XAMPP program to do this.

Tip

Find out what you need for in­stall­a­tion in our XAMPP tutorial.

Install PHP on macOS

Since PHP is pre-installed on macOS, you don’t need step-by-step in­struc­tions. To use PHP on macOS, just remove the comment symbol in two lines of the Apache con­fig­ur­a­tion file that are sig­ni­fic­ant for the setup of PHP.

You can usually find the con­fig­ur­a­tion file via the /private/etc/apache/httpd.conf path. Once you’ve opened the file with an editor of your choice, look for the following two lines:

# LoadModule php7_module libexec/httpd/libphp7.so
# AddModule mod_php7.c

By removing the hashtag, you resolve the comment status of the two lines of code so that they can be read by the in­ter­pret­er. Note that the PHP version number may differ depending on which macOS version you use.

Go to Main Menu