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
| Version | State in November 2026 |
|---|---|
| 8.6 | Released this month. Good for trying out; wait for plugins to catch up |
| 8.5 | Fully supported until the end of 2027 |
| 8.4 | Bug fixes until the end of 2026, security fixes until the end of 2028 |
| 8.3 | Security fixes only, until the end of 2027 |
| 8.2 | Security fixes end this December |
| 8.1 and older | No 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 -vIf 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-zipYou 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-fpmAlmaLinux, Rocky Linux and Red Hat
sudo dnf install php-cli php-fpm php-mysqlnd php-gd php-intl php-mbstring php-xml
php -vIf 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-fpmOn 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 phpThat 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.4Windows
With winget
Open Terminal and write:
winget install PHP.PHP.8.5Close the window, open a new one and try php -v.
By hand
- 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.
- Unzip it into
C:\php. - Copy
php.ini-developmentasphp.ini. - Add
C:\phpto the Path environment variable. - 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:8000The 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 apache2Check 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:8000It is only for development.
Settings worth changing
Edit the php.ini that phpinfo() showed and restart PHP-FPM.
| Setting | Reasonable value | What for |
|---|---|---|
memory_limit | 256M | Page builders and stores |
upload_max_filesize | 64M | Large images and imports |
post_max_size | 64M or more | Must not be smaller than the previous one |
max_execution_time | 120 | Imports and backups |
display_errors | Off | Never show errors to visitors |
opcache.enable | 1 | Big speed gain at no cost |
How to change version without breaking a site
- Make a backup and a staging copy.
- Update WordPress, plugins and theme first.
- Change the version on the copy and turn on the error log.
- Use the site: forms, search, checkout, dashboard.
- 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.