Setting up a server can be a daunting task, especially when installing languages like PHP. If you want to get a WordPress test server up and running, it’s a necessary skill to learn.

Got no idea where to start to get PHP on your server? Depending on your unique setup, there are many ways to do it. Where do you download PHP, which version, what do you need to make it work, and how do you install PHP on various OSes?

We’ll answer them all in this one-stop PHP installation guide.

Let’s begin!

What is PHP?

PHP official logo

PHP logo

PHP is an open source scripting language primarily used for web development and server-side (backend) scripting. In simple terms:

It’s also one of the easiest web scripting languages to learn, making it a popular choice for beginners. But it’s also quite powerful and suitable for advanced website functions.

Many websites and tools use PHP and its many extensions (.NET, Apache, and MySQL may sound familiar). WordPress is built primarily on PHP, and most of its plugins and themes also run on it.

Does Your Server Need PHP?

So you know what PHP is, but why should you install it on your server?

The most notable reason is that it’s a requirement to get WordPress up and running, as it’s built almost exclusively on PHP. PHP also powers most WordPress functions, hooks, themes, and plugins.

You can see all the other WordPress system requirements here:

WordPress requirements

WordPress requirements

So, if you want to run a WordPress test server to play around with or set up a staging site, you’ll need to install PHP.

Besides that, PHP is a great launching point for beginner devs. It’s straightforward to use compared to other web scripting languages, but that doesn’t come at any expense of functionality. You can do all sorts of things with it if you’re skilled enough.

PHP is also quite popular. So, you can find plenty of extensions and resources online.

Besides that, if you want to learn to code WordPress themes and plugins, you’ll need to learn PHP. Setting up a test server is a great way to experiment.

Do note that many web hosting servers (such as Kinsta) come preinstalled with PHP and WordPress. Kinsta even includes the ability to create a WordPress staging site, so that’s easy to get at too.

The only reason you’ll need to do this manually is if you’re setting up a server from scratch, either on your local computer or in an unmanaged hosting environment.

That said, let’s get into the server setup instructions.

PHP Prerequisites

Before installing PHP, you’ll need to make sure your server can handle it. Luckily, the requirements are fairly basic, and a lot of the software is likely already installed on your computer.

If you’ve never created a server before, you should check out this guide to set up a local server on multiple OSes. The exact specifics vary depending on your operating system, but you should know how to work with the command line and be ready to install new software.

Whatever operating system you’re installing PHP on, you’ll need a web server to run it. You’ll also likely need to install a database like MySQL, so keep that in mind.

Here are the PHP prerequisites for each OS, starting with Linux:

You should also be familiar with navigating Unix-like OSes already.

Now the PHP requirements for Windows:

Lastly, there are no prerequisites for macOS because PHP comes bundled with the system. We’ll explain how to enable it below.

Where to Download PHP

If you need to download the PHP files manually, you should get them from the official site’s PHP downloads page.

Avoid installing it from third-party sites unless you know they’re safe, as downloading files from third-party sites can lead to accidentally installing malware.

PHP downloads page

PHP downloads page

If you’re downloading for a Windows machine, look for the “Windows downloads” link in each version of PHP and make sure you’re installing the proper files.

You can also install older versions of PHP, but this is not recommended unless you know what you’re doing, as they expose your server to bugs and major security flaws.

If you’re running a Linux distribution, you usually don’t need to get the files through the website, and you should use the command line. We’ll go over that in detail below.

Which PHP Version Should I Use?

If you’ve clicked that download link above, you’re likely looking at all those files and feeling overwhelmed. Which PHP version is the right one?

Generally speaking, if you’re starting a brand new project where compatibility issues aren’t a problem, you should get the latest stable version of PHP.

It is sometimes possible to download beta versions of PHP, which are even newer, but these are often buggy and only released to help the developers gather feedback. Most of the time, you should stick with the stable releases.

What about older versions? Every PHP version comes with new features, but that means new incompatibilities with older features. If you need to do something specific that{s not supported on the latest PHP version, you can use an older version, but you should stick only with the currently supported versions.

If you’re not sure, then use the latest version of PHP.

Take note that WordPress is only compatible with certain versions of PHP. It technically supports PHP versions starting at 5.6.20+, but these are quite old and thus not recommended. Versions 7.2 to 7.4 are currently the best-supported versions for WordPress.

PHP version 8 is also compatible, but currently, this is very new, and not all plugins work properly. If you’re worried about compatibility issues, stick with PHP version 7.4. You can read our PHP benchmarks post to see how various PHP CMSes and frameworks perform on different PHP versions.

How to Install PHP on Linux

Before starting, you should be familiar with the Terminal and how to operate Unix-like OSes in general. Generally, these command line codes should work on any Linux distribution that uses the normal syntax in the Terminal, but we’ve left some notes below for specific OSes.

First, you should make sure your packages are up to date, so run this command in the Terminal.

sudo apt-get update && sudo apt-get upgrade

Now you’re ready to install PHP. The command to do so is effortless and straightforward.

sudo apt-get install php
Installing PHP via terminal

Installing PHP via terminal

This will install the latest version of PHP along with several extensions. You can use this code to see which version you have.

php –v

What if you want to install a specific version of PHP, such as PHP 7.4? You’ll need to use a PPA, or Personal Package Archive, by Ondřej Surý. This is a safe way to install older supported versions of PHP. Run these three commands one at a time:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Now your system recognizes the archive, and you can install PHP 7.4. Type in the following command:

sudo apt install php7.4

And of course, you can replace this number with whatever PHP version you want.

That covers the basics, but if you need extra help with configuration, the PHP installation documentation for Unix can help.

Installing PHP on Ubuntu

For Ubuntu users, there aren’t many specific concerns as long as you follow the guide above. Ubuntu is one of the most popular distributions, so most Linux guides are practically made for that system.

One alternative option available to you is downloading a LAMP stack. LAMP stands for Linux, Apache, MySQL, and PHP. It’s essentially a bundle of all the software you need to get a server up and running.

While you can manually download each of these tools separately, you could get Taskel, a bundle that will install all these at once. Just run these two commands in succession in the Terminal:

sudo apt install tasksel
sudo tasksel install lamp-server
Installing LAMP stack with Taskel via terminal

Installing LAMP stack with Taskel via terminal

Installing PHP on CentOS 7

This operating system is a little different from other Linux distributions. On CentOS, the apt and apt-get commands are not the ideal ways to install the software. Instead, it uses yum, Yellowdog Updater Modified, a better package manager for RHEL-based operating systems.

Otherwise, the commands you’ll need to use are pretty similar. To update your packages, run this command instead:

sudo yum install epel-release && sudo yum update

As for other commands, you can usually replace apt-get with yum. To install PHP, use this command.

sudo yum install php

PHP commands such as php –v should work the same on CentOS 7, so you don’t need to worry about that.

Need a blazing-fast, secure, and developer-friendly hosting? Kinsta is built with PHP developers in mind and provides plenty of powerful tools and an intuitive dashboard. Check out our plans!

Installing PHP on Debian

Last for Unix-like operating systems is Debian. This time there are just a few minor concerns, but most of the commands listed above should work fine.

For Debian, you can use either apt-get or aptitude in your Terminal commands. The aptitude command is a little more comprehensive and provides a menu interface. It’s up to personal preference which you use, and either will get the job done.

So instead of using the usual apt-get command, you could run this one instead:

sudo aptitude install php

Debian can be finicky. If you find PHP isn’t parsing or extensions aren’t working, make sure you’ve updated your server’s web configuration file and that it’s loading the extension ini files.

Besides a few small things, instructions for Debian are practically identical to those for other Linux distributions.

How to Install PHP on Windows

If you’re using a Windows system, unlike macOS and Linux, you don’t need to install PHP through the command line (though it is an option if you’d prefer).

An easy way to install PHP from here is to enable IIS and then use WebPI to install PHP. After launching WebPI, you can find it under the Products tab. Click Add on the version you want, then click Install.

Enabling IIS on Windows

Enabling IIS on Windows

You can also download PHP for Windows and manually configure it to work with IIS. Make sure to get a non-thread-safe version if you’re using IIS.

If all this is too complicated, you could instead install WampServer or XAMPP, as these come with everything you need to start working with a web server: Apache, a database, and of course PHP.

These instructions will work with most modern Windows OSes such as Windows 10, 7, and Vista. If you’re using an older version of Windows, you should check out the legacy Windows installation documentation.

Windows may need a little extra configuration to get PHP working properly, so make sure to check the recommended Windows configuration documentation. You just have to make a few small ini tweaks.

How to Install PHP on macOS

PHP comes preinstalled on most macOS systems, so you usually don’t need any manual installation.

All you need to do is uncomment a few lines of code in the Apache configuration file httpd.conf, which you can usually find at /private/etc/apache2/httpd.conf. Uncomment these two lines by removing the hashtag symbol:

# LoadModule php5_module libexec/httpd/
# AddModule mod_php5.c

You may need to do extra configuration if you don’t like some file settings’ default values. Otherwise, find the DocumentRoot, then create and load a PHP file with this code:

<?php phpinfo(); ?>

You can always check the PHP version with the php –v command to make sure PHP was installed correctly.

If you do need to download PHP manually, then you should install Homebrew and use this simple command:

brew install php

All About PHP Extensions

Once you’ve got PHP up and running, it’s a good idea to think about extensions. These compiled libraries add all sorts of extra, helpful functionality. Think of them as plugins that add on to what PHP already offers. Some of these are required to run PHP frameworks, such as Laravel and Symfony.

While it’s completely possible to code everything yourself without ever touching an extension, there’s no reason to do it all on your own when widely-used shortcuts exist to make your life easier.

PHP already comes with dozens of built-in extensions, some of which you must enable manually, and others you can start using right away. You can also install PHP extensions through sites like PECL, which hosts hundreds of third-party packages.

The PHP manual offers extension documentation for many of these as well, so you can get the hang of using them.

Not sure where to start? Here are just a handful of a few popular PHP extensions:

Whenever you install an extension, you need to uncomment it. Just open up php.ini and remove the semicolon (;) in front of extension=extensionname.

You should also check out these PHP frameworks if you’d like to standardize your code and build with premade libraries. They’re a great way to get started with developing web applications with PHP.


Whatever operating system you’re using, installing PHP isn’t such a hard process. If you want to make a WordPress test server, you’ll need it. Aspiring PHP programmers will find setting up a web server and installing PHP on it a great exercise.

Make sure you download PHP either through the command line or from its official site. You can either get the latest stable version of PHP or any other version compatible with WordPress.

And if you’d like to get started with developing WordPress sites right away, you can try DevKinsta! It comes with PHP preinstalled. It also lets you hot-swap between different PHP versions so that you can test your site in different server environments.

If you enjoyed this article, then you’ll love Kinsta’s WordPress hosting platform. Turbocharge your website and get 24/7 support from our veteran WordPress team. Our Google Cloud powered infrastructure focuses on auto-scaling, performance, and security. Let us show you the Kinsta difference! Check out our plans