How to Install PHP on Linux, macOS and Windows

How to Install PHP on Linux, macOS and Windows

Installing PHP takes one or two commands on almost any system. What takes longer is choosing the right version and connecting it to the web server, so this guide covers all three.

If you only want to run WordPress on hosting that somebody else manages, you don't need any of this: PHP is already there and you pick the version in a panel.

Which version to choose

VersionState in November 2026
8.6Released this month. Good for trying out; wait for plugins to catch up
8.5Fully supported until the end of 2027
8.4Bug fixes until the end of 2026, security fixes until the end of 2028
8.3Security fixes only, until the end of 2027
8.2Security fixes end this December
8.1 and olderNo fixes at all. Upgrade

WordPress recommends PHP 8.3 or later. For a new project in 2026, 8.4 or 8.5 is the sensible choice. The dates come from the official list.

First, check whether you already have it

php -v

If you see a version number, PHP is installed for the command line. The web server may use a different one, as we will see below.

Linux

Ubuntu and Debian

sudo apt update
sudo apt install php-cli php-fpm php-mysql php-curl php-gd php-intl php-mbstring php-xml php-zip

You get the version of your system: 8.3 on Ubuntu 24.04, 8.5 on Ubuntu 26.04 and 8.4 on Debian 13. We install php-fpm because it is what Nginx and modern Apache use to talk to PHP.

Do you need another version? The usual source is the repository of Ondřej Surý, who also maintains PHP in Debian. On Ubuntu:

sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.5-cli php8.5-fpm

AlmaLinux, Rocky Linux and Red Hat

sudo dnf install php-cli php-fpm php-mysqlnd php-gd php-intl php-mbstring php-xml
php -v

If the version offered is old, the Remi repository provides recent ones, and its site has a wizard that writes the exact commands for your system.

Start the service

sudo systemctl enable --now php8.5-fpm
systemctl status php8.5-fpm

On Red Hat and its relatives the service is simply called php-fpm.

macOS

macOS has not included PHP since version 12. The simplest way is Homebrew:

brew install php
brew services start php

That installs the newest version, 8.6 at the moment. For another one, use its name and put it first in your path:

brew install php@8.4
brew link --overwrite --force php@8.4

Windows

With winget

Open Terminal and write:

winget install PHP.PHP.8.5

Close the window, open a new one and try php -v.

By hand

  1. Download the ZIP from windows.php.net. Choose Non Thread Safe for the command line and for FastCGI, and Thread Safe only for Apache's module.
  2. Unzip it into C:\php.
  3. Copy php.ini-development as php.ini.
  4. Add C:\php to the Path environment variable.
  5. If it complains about a missing file, install Microsoft's Visual C++ Redistributable.

For developing WordPress on Windows, an environment such as Laragon, XAMPP or WordPress Studio saves time, since it brings the web server and the database too.

Docker, on any system

docker run --rm php:8.5-cli php -v
docker run --rm -p 8000:8000 -v "$PWD":/app -w /app php:8.5-cli php -S 0.0.0.0:8000

The second line serves the current folder at http://localhost:8000. It is a comfortable way to try a version without installing anything.

Connect PHP to the web server

Nginx

Inside the server block of your site:

location ~ \.php$ {
  include snippets/fastcgi-php.conf;
  fastcgi_pass unix:/run/php/php8.5-fpm.sock;
}

Check and reload with sudo nginx -t && sudo systemctl reload nginx.

Apache

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.5-fpm
sudo systemctl reload apache2

Check that it works

Create a file named info.php in your site's folder with one line:

<?php phpinfo();

Open it in the browser, note the version and the path of the configuration file, and delete it. That page tells an attacker more than you want. If the browser downloads the file instead of running it, the server isn't connected to PHP yet.

For quick tests there is no need for a server at all:

php -S localhost:8000

It is only for development.

Settings worth changing

Edit the php.ini that phpinfo() showed and restart PHP-FPM.

SettingReasonable valueWhat for
memory_limit256MPage builders and stores
upload_max_filesize64MLarge images and imports
post_max_size64M or moreMust not be smaller than the previous one
max_execution_time120Imports and backups
display_errorsOffNever show errors to visitors
opcache.enable1Big speed gain at no cost

How to change version without breaking a site

  1. Make a backup and a staging copy.
  2. Update WordPress, plugins and theme first.
  3. Change the version on the copy and turn on the error log.
  4. Use the site: forms, search, checkout, dashboard.
  5. Change the real site and watch the log for a day.

Both versions can live together on the same server, each with its own FPM service, so going back is a matter of changing one line.

Common problems

  • The terminal shows one version and the site another. They are separate. Look at the socket or port in the server's configuration.
  • "Call to undefined function". An extension is missing. For example, sudo apt install php8.5-mysql.
  • Error 502. PHP-FPM is stopped or the path of the socket is wrong.
  • Blank page. Read the error log instead of guessing.

If you would rather have a server with your own choices, our Managed VMs give you root access in about a minute. And if all you want is WordPress, with managed hosting you choose the PHP version for each site, from 8.0 to 8.5, without touching the server.

Related Articles

The Domain Lifecycle Explained: From Registration to Release Starting a Website

The Domain Lifecycle Explained: From Registration to Release

Every domain moves through a predictable series of stages. The domain lifecycle explained — from registration and the active period to expiration, grace, redemption, pending delete, and release.

Jul 12, 2026
Guide to Domain Management: DNS, Renewals, and Transfers Starting a Website

Guide to Domain Management: DNS, Renewals, and Transfers

Take full control of your domains. A complete guide to domain management — DNS setup, renewals and the domain lifecycle, security, transfers, and day-to-day administration.

Jul 12, 2026
How to Choose a Domain Name: The Complete 2026 Guide Starting a Website

How to Choose a Domain Name: The Complete 2026 Guide

Your domain name is your brand's first impression. Learn how to choose a memorable, brandable domain — naming strategies, the right extension, mistakes to avoid, and a step-by-step checklist.

Jul 12, 2026