Configuring a server can be a daunting task, especially when installing languages like PHP. “Hypertext Pre-Processor”. If you want to have a WordPress test server up and running, it is a necessary skill to learn.

Try a free demo
Have 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 operating systems?

We will answer them all in this comprehensive PHP installation guide.

Let’s get started!

What is PHP?

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

  • PHP can be installed on a server to run scripts (for example, code snippets to add forms to your site).
  • It runs on the server side instead of the client side, so it works in the backend instead of in the browser.
  • It integrates well with HTML, making it very suitable for web development.

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

Many websites and tools use PHP and its many extensions (.NET, Apache, and MySQL may be familiar). WordPress is mainly based 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 is a requirement for WordPress to be up and running, as it is built almost exclusively in PHP. PHP also powers most of WordPress’ features, hooks, themes, and plugins.

You can see all the other WordPress system requirements here:

Therefore, if you want to run a WordPress test server to play around with or set up a test site, you will need to install PHP.

In addition to that, PHP is a great starting point for beginner developers. It is easy to use compared to other web scripting languages, but that does not come at any cost in terms of functionality. You can do all kinds of things with it if you are skilled enough.

PHP is also quite popular. Therefore, you can find many extensions and resources online.

In addition to that, if you want to learn how to code WordPress themes and plugins, you will need to learn PHP. Setting up a test server is a great way to experiment.

Keep in mind that many web hosting servers come pre-installed with PHP and WordPress. Kinsta even includes the ability to create a WordPress test site, so it is also easy to access.

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

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

PHP Prerequisites

Before installing PHP, you will need to make sure that your server can handle it. Fortunately, the requirements are quite basic, and much of the software is likely already installed on your computer.

If you have never created a server before, you should check out this guide to setting up a local server on various operating systems. The exact details vary depending on your operating system, but you should know how to work with the command line and be ready to install new software.

Regardless of the operating system on which you are installing PHP, you will need a web server to run it. You will also likely need to install a database like MySQL, so keep that in mind.

These are the PHP prerequisites for each operating system, starting with Linux:

  • An ANSI C compiler.
  • Module-specific components such as GD graphics libraries or PDF libraries.
  • Optional: Autoconf 2.59+ (for PHP versions < 7.0), Autoconf 2.64+ (for PHP versions > 7.2), Automake 1.4+, Libtool 1.4+, re2c 0.13.4+ and Bison.

You should also be familiar with navigating Unix-like operating systems.

Now the PHP requirements for Windows:

  • Several Windows operating systems are supported in PHP 5.5+, but users of 7.2.0+ cannot use Windows 2008 or Windows Vista.
  • Visual C Runtime (CRT).
  • Visual Studio 2012, 2015, 2017, or Microsoft Visual C ++ Redistributable for Visual Studio 2019, depending on your version of PHP.

Finally, there are no prerequisites for Mac OS because PHP comes included with the system. We will 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 PHP downloads page.

Avoid installing it from third-party sites unless you know they are safe, as downloading files from third-party sites can lead to the accidental installation of malware.

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

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

If you are running a Linux distribution, you generally do not need to get the files through the website and should use the command line. We will go over it in detail below.

What version of PHP should I use?

If you have clicked on the download link above, you are likely looking at all those files and feeling overwhelmed. Which version of PHP is the right one?

Generally speaking, if you are starting a new project where compatibility issues are not a problem, you should get the latest stable version of PHP.

Sometimes it is possible to download beta versions of PHP, which are even newer, but they often have bugs and are only released to help developers collect feedback. Most of the time, you should stick with the stable versions.

What about older versions? Each version of PHP comes with new features, but that means new incompatibilities with older features. If you need to do something specific that is not compatible with the latest version of PHP, you can use an older version, but you should only stick with the current supported versions.

If you are not sure, use the latest version of PHP.

Keep in mind that WordPress is only compatible with certain versions of PHP. Technically, it is compatible with PHP versions starting from 5.6.20+, but these are quite old and therefore not recommended. Versions 7.2 to 7.4 are currently the best-supported versions for WordPress.

PHP version 8 is also supported, but this is currently very new, and not all plugins work correctly. If you are concerned about compatibility issues, stick with PHP version 7.4. You can read our PHP performance testing post to see how various PHP CMSs and frameworks perform on different PHP versions.

How to install PHP on Linux

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

First, you need to 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 are ready to install PHP. The command to do so is simple and effortless.

sudo apt-get install php

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 will need to use a PPA, or personal package archive, before 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 file, and you can install PHP 7.4. Type the following command:

sudo apt install php7.4

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

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

Installing PHP on Ubuntu

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

An alternative option available to you is to download a LAMP stack. LAMP stands for Linux, Apache, MySQL, and PHP. Basically, it is a package of all the software you need to get a server up and running.

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

sudo apt install tasksel
sudo tasksel install lamp-server

Installing PHP on CentOS 7

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

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

sudo yum install epel-release && sudo yum update

As for other commands, you can generally replaceapt-get with yum. To install PHP, use this command.

sudo yum install php

PHP commands likephp –v should work the same on CentOS 7, so you do not need to worry about that.

Installing PHP on Debian

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

For Debian, you can useapt-get oraptitude in your Terminal commands. Theaptitude command is a bit more complete and provides a menu interface. It depends on personal preference which one you use, and either will do the job.

So, instead of using the usualapt-get command, you can run this one instead:

sudo aptitude install php

Debian can be picky. If you find that PHP is not parsing or that extensions are not working, make sure you have updated your server’s web configuration file and that it is loading the extension. ini files.

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

How to install PHP on Windows

If you are using a Windows system, unlike macOS and Linux, you do not need to install PHP through the command line (although it is an option if you prefer).

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

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

If all this is too complicated, you can install WampServer or XAMPP, as they 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 operating systems, such as Windows 10, 7, and Vista. If you are using an older version of Windows, you should consult the legacy Windows installation documentation.

Windows may need a little extra configuration for PHP to work properly, so be sure to check the recommended Windows configuration documentation. You only have to do a few small ini tweaks.

How to install PHP on macOS

PHP comes pre-installed on most Mac OS systems, so you usually do not 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 in/private/etc/apache2/httpd.conf. Uncomment these two lines by removing the hashtag symbol:

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

You may have to do additional configuration if you do not like the defaults of some file settings. Otherwise, find DocumentRoot, then create and upload a PHP file with this code:

<?php phpinfo(); ?>

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

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

brew install php

All about PHP extensions

Once you have PHP up and running, it is a good idea to think about extensions. These compiled libraries add all kinds of useful and extra functions. Think of them as plugins that add to what PHP already offers. Some of these are necessary to run PHP frameworks, such as Laravel and Symfony.

While it is entirely possible to code everything yourself without touching an extension, there is no reason to do everything on your own when there are widely used shortcuts 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 used to using them.

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

  • Apache: Apache is a widely used web server software recommended by WordPress due to its high compatibility with it and PHP. Apache comes included with PHP, so you do not need to install it manually.
  • .NET: .NET is a popular software framework that you can use to create web applications and more. It works with several languages, including PHP. You might also be interested in Peachpie, which allows you to run PHP code on .NET.
  • MySQLi: a better version of the old MySQL extension, MySQLi allows you to work with MySQL database software. This is a must to help you set up your database.

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

You should also check out these PHP frameworks if you want to standardize your code and compile with pre-built libraries. They are a great way to start developing web applications with PHP.

Summary

Regardless of the operating system you are using, installing PHP is not such a difficult process. If you want to create a WordPress test server, you will need it. Aspiring PHP programmers will find that setting up a web server and installing PHP on it is a great exercise.

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