PHP is an open-source, multi-paradigm, dynamically-typed, and interpreted scripting language designed initially for server-side web development. Use this tag for questions about programming in the PHP language.
PHP is a widely used, open source, general-purpose, multi-paradigm, dynamically typed and interpreted scripting language designed initially for server-side web development.
The original PHP project, as invented by Rasmus Lerdorf, stood for Personal Home Page. Today, it stands for the recursive acronym PHP: Hypertext Preprocessor.
The latest stable release, development changes, and development branches can be found on the PHP website, and the source code, written in C, is available at PHP's GitHub repository.
To create an environment for learning and experimenting with PHP, several application bundles include – among other components – a web server and PHP:
- AMPPS
- XAMPP (for Windows, Mac OS X & Linux)
- DEB.SURY.ORG (PHP For Debian in general & Ubuntu-based Linux distros. package and PPA)
- MAMP (for Mac OS)
- WampServer (for Windows)
- easyPHP (for Windows)
- WPN-XM (for Windows)
- Laragon (for Windows)
- Docker (All platforms)
There are options like Cygwin (Linux on Windows), in which you can install PHP just like any other Linux
- Cygwin (Linux on Windows)
PHP provides a built-in web server for testing and development purposes. It can be started using the following command:
php -S localhost:8000
After executing the above command, the server will listen on port 8000
using the current working directory as its document root. See the PHP manual for more information.
Notice: To make an online demo for your question, you may use codepad, 3v4l, or PHP Sandbox. However, your question or answer should still include all relevant codes.
PHP Versions
It is recommended that the current stable released version be used. All versions below 8.1 are officially unsupported and have been announced end-of-life. A list of supported branches and their maintenance status can be found on php.net website.
For further information about new features and required changes in a new version, see the official migration docs:
Sample PHP script
This script displays Hello World!
on your screen.
<?php
echo 'Hello World!';
To run this script in a console, save it in the current working directory in a file called hello.php
and execute the command: php hello.php
.
Community
PHP has many active community forums, including:
- Stack Overflow PHP chat room
- Linux Fund
- PHP Meetups
- Freenode IRC channel ##php
More information
- Wikipedia on PHP
- PHP Official Page
- Welcome to PHP Resource list for beginners to PHP
Online documentation
The PHP manual is the official documentation for the language syntax featuring function search and URL shortcuts (for example, https://php.net/explode). The API is well documented for bundled and additional extensions. Most additional extensions can be found in PECL. The PEAR repository contains a plethora of community supplied classes. It is also possible to download an offline version of the documentation here.
The PHP Framework Interop Group (PHP-FIG) has also created standards concerning PHP coding styles and standards. These PHP Standard Recommendations (PSRs) can be found here.
PHP Tutorials
PHP security-related information
Free PHP Programming Books
- PHP Essentials
- Symfony: The Fast Track
- Zend Framework: Survive the Deep End
- PHP: The Right Way (a community-driven quick reference for PHP best practices and accepted coding standards)
Database support
PHP supports a wide range of databases, relational and non-relational alike.
PHP is often paired with the MySQL relational database. PHP also includes great database support for PostgreSQL, SQLite, Microsoft SQL Server (API reference), Oracle, IBM DB2 & Cloudscape, Apache Derby, and even ODBC.
All modern versions of PHP include PDO: a built-in data-access abstraction library with comprehensive connectivity options. More recently, PECL extensions that offer "NoSQL" database support have surfaced, including Apache Thrift (for Apache Cassandra), MongoDB, Redis, and others.
Useful Third-party Code and Tools
In addition to the extensive functionality provided in the PHP Core and through PEAR and PECL, there are several noteworthy third-party contributions to the PHP world, some of which are listed below:
Package Management with Composer
Composer is a package management tool for PHP inspired by npm for Node.js and Bundler for Ruby. It allows for per-project dependencies to be specified in a JSON file.
The Composer uses packages from Packagist, rapidly growing to contain many of the most popular PHP libraries.
Composer solves the following problems:
- You have a project that depends on several libraries.
- Some of those libraries depend on other libraries.
- You declare the things you depend on.
- Composer determines which versions of which packages need to be installed and downloads them into a directory (usually
vendor
) in your project.
Nothing comes for free. Software downloaded with Composer may have bugs like any other, including security vulnerabilities. You are responsible for being aware of what you install and updating when necessary to get security fixes.
Quality Assurance Tools
- PHPUnit
- Behat (Test framework for Behavior Driven development)
- PEAR CodeSniffer
- SimpleTest
- Xdebug
- PHPStan
- more …
Coding standards and conventions
Several coding standards have been proposed and accepted by the PHP Framework Interop Group (PHP-FIG). These are known as the PHP Standards Recommendations (PSRs). As of February 13th, 2025, the following recommendations are in effect:
- PSR-1 - Basic Coding Standard
- PSR-3 - Logger interface
- PSR-4 - Autoloading standard (this deprecates PSR-0)
- PSR-6 - Caching interface
- PSR-7 - HTTP message interfaces
- PSR-12 - Extended Coding Style
- PSR-13 - Link definition interfaces
- PSR-16 - Common Interface for Caching Libraries
- PSR-17 - HTTP Factories
- PSR-17 - HTTP Client
- PSR-17 - Clock
A complete list of all recommendations alongside their status can be found on the PHP-FIG Recommendations page