Learn how to install PHP locally to solve Exercism's exercises on your own machine
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.
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.
A web server such as nginx or Apache HTTP server is not required to complete the exercises.
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.
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.
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.
If you prefer containerized solutions, you can download official PHP image from Docker Hub. You will also need Docker.
If you want to use a different OS, see instruction on php.net/manual/en/install.
Install Composer following your devices OS installation instructions. We recommend installing it globally for ease of use.
The easiest way to use PHPUnit for Exercism exercises is downloading a distribution that is packaged as a PHP Archive (PHAR), which is also the recommended way to use PHPUnit.
Store the PHAR where you stored the exercism
CLI to run PHPUnit from wherever you are.
You can download a release of PHPUnit packages as a PHP archive:
wget -O phpunit.phar https://phar.phpunit.de/phpunit-10.phar
Then make the downloaded file executable:
chmod +x phpunit.phar
And move it to the same location as you moved the exercism
CLI, naming the command phpunit
:
mv phpunit.phar ~/bin/phpunit
Now you can run phpunit
from wherever you are, as shown in the PHP track testing docs:
phpunit --version
The output should look like this:
PHPUnit 10.5.45 by Sebastian Bergmann and contributors.
You can also follow the official Installing PHPUnit instructions to install PHPUnit.
PHPUnit version 10 can also 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.