Use the PHP installation wizard to get the installation instructions for your system.
Make sure to use the latest stable version PHP 8.0. Versions on some online production servers can be few versions behind the latest PHP releases because of hosting policies and backwards compatibility. Don’t let this stop you from using the latest PHP with all its shiny new features.
You can download and use PHP binaries and sources for Windows and other systems from the official site. Building PHP from source on your own has its benefits in that you can configure your build according to your specific requirements. Refer to the PHP manual for learning how to build PHP from source.
PHP has a useful built-in web server for local development. Inside your project folder you can run it from the command line:
php -S localhost:8000
http://localhost:8000/index.php in your browser to access it.
To successfully develop and run PHP applications you will eventually need a more advanced web server such as Apache or Nginx, a database such as MySQL or MariaDB, and other useful tools such as Xdebug, Adminer, phpMyAdmin, etc. Whether you’re using Windows, OS X or Linux, you can simplify installation by using one of these all-in-one packages:
Aside from the above, on Windows, you can also use one of the following useful all-in-one packages:
By default, macOS includes a slightly outdated PHP. To install and use the latest PHP on macOS, aside from by using one of the aforementioned packages, you can also use one of the following solutions:
Linux and Unix based operating systems are a bit more complex and diverse.
Learning to use these environments is recommended for developers. After all,
there’s a high chance that your web application will be hosted on such servers.
PHP installation can be done with package managers, that distribution uses
yum, with its successor
A simplified example of
apt usage for Debian based distributions (Debian, Ubuntu…):
sudo apt-get install php
and yum (or newer dnf) for Fedora based distributions (Fedora, RHEL, CentOS…):
sudo dnf install php
Keep in mind that there are many other packages such as
php-mysql and others, to be explored with your distribution.
Most of the time the default PHP version provided by the distribution will be a few versions behind the latest stable release from PHP.net. This is where some useful third-party repositories can come in handy:
A more advanced and recommended way of professional PHP development nowadays is by using virtualization software such as Virtual Box, Vagrant, and Docker. These help you reduce friction between development and production environments. With virtual environments, you can make your development (software versions, configuration…) the same as what your production is.
Docker chapter includes more information how to use PHP with Docker.
After you successfully install PHP, proceed to the PHP editors and IDEs chapter.