Setting up a server can be a daunting task, especially when installing languages like PHP. “Hypertext Pre-Processor”. If you want to get a WordPress test server up and running, it’s a necessary skill to learn.
Try a free demo
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, what version, what do you need to make it work, and how do you install PHP on various operating systems?
We’ll answer them all in this comprehensive PHP installation guide.
What is PHP?
PHP is an open source scripting language primarily used for web development and server-side (backend) scripting. In simple terms:
- 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 on the backend instead of the browser.
- It integrates well with HTML, which makes it very suitable for web development.
It’s 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 features.
Many websites and tools use PHP and its many extensions (.NET, Apache, and MySQL may look familiar). WordPress is primarily based on PHP, and most of its plugins and themes run on it as well.
Does your server need PHP?
So now 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 on PHP. PHP also powers most WordPress functions, hooks, themes, and plugins.
You can see all the other WordPress System Requirements here:
So if you want to run a WordPress staging server to play around or set up a staging site, you’ll need to install PHP.
On top of that, PHP is a great starting point for beginning developers. It’s easy to use compared to other web scripting languages, but that comes at no cost in terms of functionality. You can do all sorts of things with it if you’re skilled enough.
PHP is also quite popular. Therefore, you can find many extensions and resources online.
On top of 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.
Note that many web hosts come pre-installed with PHP and WordPress. Kinsta even includes the ability to create a WordPress test site, so that’s easy to access as well.
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.
With that said, let’s jump into the server setup instructions.
Before you install PHP, you’ll need to make sure your server can handle it. Fortunately, the requirements are pretty basic, and much of the software is likely already installed on your computer.
If you have never created a server before, you should refer to 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 you are installing PHP on, you will 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 operating system, starting with Linux :
- An ANSI C compiler.
- Module specific components like GD chart 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 :
- Various Windows operating systems are supported on 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.
Lastly, there are no prerequisites for Mac OS because PHP is 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 download page .
Avoid installing it from third party sites unless you know they are safe, as downloading files from third party sites can lead to accidental installation of malware.
If you are downloading for a Windows machine, look for the “Windows Downloads” link under each version of PHP and make sure you are installing the correct 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 generally don’t need to get the files through the website and must use the command line. We will review it in detail below.
What version of PHP should I use?
If you’ve clicked the download link above, you’re probably looking at all those files and feeling overwhelmed. Which version of PHP is correct?
Generally speaking, if you’re starting a new project where compatibility issues aren’t an issue, you should get the latest stable version of PHP.
It is sometimes possible to download beta versions of PHP, which are even newer, but they often have bugs and are only released to help developers gather feedback. Most of the time, you should stick with the stable releases.
What about previous 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 supported by the latest version of PHP, you can use an older version, but you should stick to the current version only. compatible versions .
If you’re not sure, use the latest version of PHP.
Please note that WordPress only supports certain versions of PHP . Technically it supports PHP versions 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 tests post to see how various PHP CMS and frameworks perform on different versions of PHP.
Professional Business Presentation
Do you need a redesign or a new website for your business?
Complete solution for small, medium or corporate business presentation. Great UX/UI designers, experienced programmers and high emphasis on testing. If you are looking for a professional partner for your business in the online world, contact us!
How to install PHP on Linux
Before you begin, 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 Terminal syntax, but here are some notes for specific operating systems.
First, you need to make sure your packages are up to date, so run this command in Terminal.
sudo apt-get update && sudo apt-get upgrade
You are now 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 various extensions. You can use this code to see what version you have.
What if you want to install a specific version of PHP, like 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 compatible PHP versions. 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 whatever version of PHP you want.
That covers the basics, but if you need additional help with configuration, the PHP Installation Documentation for Unix can help.
Installing PHP on Ubuntu
For Ubuntu users, there are not many specific concerns as long as you follow the above guide. Ubuntu is one of the most popular distributions, so most of the 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’s 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. Just run these two commands in succession in 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 software. Instead, use mmm , 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 like
php –v it should work the same on CentOS 7, so you don’t need to worry about that.
Installing PHP on Debian
The ultimate 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 use
aptitude in your Terminal commands. the
aptitude The command is a bit more comprehensive and provides a menu interface. It depends on the personal preference you use, and either will do the job.
So instead of using the usual
apt-get command, you can run this instead:
sudo aptitude install php
Debian can be finicky. If you find that PHP is not parsing or the extensions are not working, make sure you have updated your server’s web config file and that you are loading the extension. ini files.
Other than a few small things, the instructions for Debian are pretty much 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 via the command line (although it’s 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 launching WebPI, you can find it in the Products tab. Click Add on the version you want, then click Install on PC .
If all this is too complicated, you can install WampServer or XAMPP, as they come with everything you need to get started 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 earlier version of Windows, you should refer to the Windows Legacy Installation documentation.
Windows may need a little additional configuration for PHP to work properly, so be sure to check the recommended Windows configuration documentation. You just have to do some small ini tweaks.
How to install PHP on macOS
PHP comes pre-installed on most Mac OS systems, so you don’t normally 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/libphp5.so # AddModule mod_php5.c
You may have to do additional configuration if you don’t like the default values of some file settings. If not, find 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 that 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’s a good idea to think about extensions. These compiled libraries add all sorts of useful and extra features. Think of them as plugins that add to what PHP already offers. Some of these are required to run PHP frameworks, such as Laravel and Symfony.
While it’s entirely possible to code everything yourself without touching an extension, there’s no reason to do it all 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 need to manually enable and some of which 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.
You’re not sure where to start? These are just a few of some popular PHP extensions:
- Apache – Apache is a widely used web server software recommended by WordPress due to its great compatibility with it and PHP. Apache comes bundled with PHP, so there is no need to install it manually.
- .NET – .NET is a popular software framework that you can use to build web applications and more. It works with several languages, including PHP. You might also be interested in Peach , which allows you to run PHP code in .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 of
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.
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 setting up a web server and installing PHP on it a great exercise.