PHP is a widely used, high-level, dynamic, object-oriented, and interpreted scripting language primarily designed 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.
To get started with PHP, you may use one of these applications that include, among other components, a web server and PHP:
- 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)
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 which 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 which act like jsfiddle, but for PHP. However, all relevant code should still be included in your question or answer.
Current Stable Version (7.4.x): 7.4.3 // Release Date: 20 Feb 2020Old Stable Version (7.3.x): 7.3.15 // Release Date: 20 Feb 2020Old Stable Version (7.2.x): 7.2.28 // Release Date: 20 Feb 2020
It is recommended to use the current stable released version. All versions below 7.2 are officially unsupported and have been announced end-of-life. A list of supported branches and their maintenance status can be found here.
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 simply execute the command:
In case you don't have PHP installed on your machine - you can try this simple script with docker, just run:
docker run -it --rm --name php-test php:7.1-cli php -r 'echo "Hello World!";'
PHP has many active community forums, including:
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.
Additionally, the PHP Framework Interop Group (PHP-FIG) has created sets of standards with regards to PHP coding styles and standards. These PHP Standard Recommendations (PSRs) can be found here.
PHP security related information
Free PHP Programming Books
- PHP Essentials
- Practical PHP Programming (wiki containing O'Reilly's PHP In a Nutshell)
- Zend Framework: Survive the Deep End
- PHP: The Right Way (a community-driven quick reference for PHP best practices and accepted coding standards)
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 vast functionality provided in the PHP Core and through PEAR and PECL, there are a number of 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.
Composer uses packages from Packagist which is rapidly growing to contain many of the most popular PHP libraries.
Composer solves the following problems:
- You have a project that depends on a number of 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, just like any other, including security vulnerabilities. It is your responsibility to be aware of what you install and to update when necessary in order to get security fixes.
Quality Assurance Tools
In recent years, there has been a steady increase of quality assurance tools in the PHP world. As PHP moved into the professional mainstream, tools to assert certain quality features and metrics were needed and provided by the PHP community. These tools include frameworks for debugging, unit-testing, code analysis and coverage, continuous integration, and other aspects of professional development. Some of these tools are listed below:
Coding standards and conventions
There are a number of coding standards that have been proposed and accepted by the PHP Framework Interop Group (PHP-FIG). These are known as the PHP Standards Recommendations (PSRs). As of July 2nd, 2017, 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
A complete list of all recommendations alongside their status can be found at the PHP-FIG Recommendations page
php-oop php-date php5 php-frameworks hypertext-preprocessor php.ini php-cli php-errors php-mail php-cgi php-functions php-readfile php-session php-fpm phtml php-include php-namespaces