What is PHP?

Author: Published

In brief: PHP is a programming language used primarily to build server-side websites and web applications. It processes data, executes application rules and prepares the response received by the browser. WordPress and many online stores use it, among others, but you do not need to install PHP on your computer simply to browse these sites.

How does PHP work when you open a page?

PHP is a scripting language: its code is executed by the PHP runtime installed on the server. Its name is a recursive acronym for “PHP: Hypertext Preprocessor”. For users, its role matters more than what the name stands for: PHP can prepare different content at the same address, depending on the data and circumstances.

When you open a page, your browser sends a request to the server. If an application written in PHP handles it, its code can check whether you are logged in, retrieve data from a database and generate a response. This is often HTML, the language that describes a page’s structure, but PHP can also return data in JSON format, an image or a downloadable file.

The browser receives the program’s output, not its PHP code. With the server configured correctly, viewing the page source will show the generated HTML, but not the instructions that retrieve a password from the configuration or calculate a discount. However, an incorrect configuration can expose files, so using PHP alone does not guarantee data confidentiality.

What is PHP used for in practice?

PHP handles the backend, the part of an application responsible for processing data and applying its operating rules on the server. It can work with a database, such as MySQL or PostgreSQL, but not every program needs one. A simple script can work solely with supplied data or files.

Typical PHP tasks include:

Imagine an online store. JavaScript in the browser can immediately display a change in the cart total, but the server should recheck prices, discounts and availability before saving the order. In a PHP-based store, PHP code can perform these checks. You should not rely solely on calculations in the browser, because users can modify the data they send.

PHP, HTML, CSS and JavaScript

These technologies are not interchangeable. HTML describes a document’s structure, CSS determines its appearance, and JavaScript can handle interactions in the browser. PHP runs on the server and can generate HTML that is then displayed to the user.

TechnologyExample task
HTMLCreating a heading and form fields
CSSGiving a form its colours and layout
JavaScriptDisplaying a message without reloading the page
PHPValidating form data and saving it on the server

JavaScript can also run on the server, for example in the Node.js environment. In that case, choosing between it and PHP is a choice of backend technology, not a decision about whether the site should be interactive. PHP alone does not replace the browser mechanisms needed to change the interface without fetching a new page.

What does PHP mean for WordPress site owners and hosting?

WordPress is a content management system written largely in PHP. When you publish a post through the dashboard, you do not have to write the code yourself: the system performs the necessary operations. Knowledge of PHP is useful, however, when creating plugins, developing themes or diagnosing problems that require code analysis.

Hosting for this kind of site must support the appropriate PHP version and the required extensions, which are additional runtime modules. The phrase “hosting with PHP” alone is not enough to assess compatibility. Before buying, check the application’s requirements and the available versions in the hosting provider’s documentation.

The PHP version matters for security and compatibility. Versions that have reached the end of their support period no longer receive fixes from the PHP project. Confirm the current support status on the official PHP website, and check the compatibility of WordPress, themes and plugins in their documentation. Before changing versions, back up your files and database, and test the update on a copy of the site.

How do you start learning PHP?

For your first exercises, all you need is a text editor and an installed PHP runtime. If you know the basics of HTML and how forms are submitted, it will be easier to see what the language adds to a page. A minimal program looks like this:

<?php
echo "Hello! This is a response generated by PHP.";

The echo statement outputs text. Save the code in a file named index.php, then run the command php -S localhost:8000 in its directory and open localhost:8000 in your browser. The command requires PHP to be available in the terminal. The built-in server is intended for practice and testing, not for making a production site publicly available.

Your next exercise could be a form that accepts a first name and displays a greeting. From the outset, learn to validate input and safely display user-provided text, for example by using htmlspecialchars in HTML content. If your only goal is to manage a WordPress site, start instead by checking the PHP version on your hosting account and preparing a working backup.

See also: What is 2FA?

Read also

Learn how PHP-FPM handles PHP requests, how it differs from a web server, and how to tune processes for traffic and hosting resources.
Learn how BIND, open-source DNS server software, handles domains, how its two roles differ and when running it yourself makes sense.
Learn what Poland’s REGON register and identification number mean, how they differ from NIP and KRS, and how to check a business’s details.