Installing PHP locally

Learn how to install PHP locally to solve Exercism's exercises on your own machine


Which version to chose?

We encourage to use a stable PHP release with active support. Currently this is PHP 8.1, 8.2 and 8.3. Details on current releases and their timelines can be found in the official PHP documentation.

Install PHP

Most package managers for Linux / macOS provide pre-built packages. PHP can be downloaded and built from source, available at php.net/downloads.php or windows.php.net/download.

Note

A web server such as nginx or Apache HTTP server is not required to complete the exercises.

Linux

Different distributions have different methods. You should be able to

yum install php

or

apt-get install php

depending on your package manager.

For further instructions, read the PHP manual on Installation on Unix systems.

macOS

While PHP is often bundled with macOS, it is often outdated. We recommended installing PHP through Homebrew. You can install Homebrew following the instructions here.

To confirm its installation try the following command, it should output Homebrew 4.2.x at the time of this writing.

brew --version 

Install PHP via homebrew

brew install php@8.3

This should display the now installed version of PHP, at least version 8.1.0.

php -v

For further instructions, read the manual on Installation on macOS.

Windows

Official PHP binaries for Windows can be downloaded from windows.php.net/download.

There are pre-built stacks including WAMP - (Windows, Apache, MySQL, PHP) and XAMPP.

For further instructions, read the manual on Installation on Windows systems.

Docker

If you prefer containerized solutions, you can download official PHP image from Docker Hub. You will also need Docker.

Other

If you want to use a different OS, see instruction on php.net/manual/en/install.

Install Composer

Install Composer following your devices OS installation instructions. We recommend installing it globally for ease of use.

Install PHPUnit

Via Composer

PHPUnit version 10 can be installed globally via Composer, using the following command:

composer global require phpunit/phpunit ^10.5

Please make sure you install version 10.5 or later.

Manual installation

If you are not using Composer package manager, follow the official Installing PHPUnit instructions.