Setting up a server can be a daunting task, especially when installing languages like PHP. 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?
i’ll answer them all in this one-stop PHP installation guide.
Let’s begin!
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 (e.g. pieces of code to add forms to your site).
It is run server-side rather than client-side, so it works in the backend rather than in the browser.
It integrates well with HTML, making it highly 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’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).
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:
An ANSI C compiler.
Module-specific components like 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 OSes already.
Now the PHP requirements for Windows:
Multiple Windows OSes are supported on PHP 5.5+, but 7.2.0+ users 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 PHP version.
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.
Which PHP Version Should I Use?
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.
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.
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 i’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
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
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
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.
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.
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.
Not sure where to start? Here are just a handful of a few popular PHP extensions:
Apache: Apache is a widely used web server software recommended due to its great compatibility with it and PHP. Apache comes bundled with PHP, so you don’t 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 multiple languages, including PHP. You may also be interested in PeachPie, which allows you to run PHP code in .NET.
MySQLi: A better version of the old MySQL extension, MySQLi enables you to work with MySQL database software. This one is a must-have to help you set up your database.