PHP (Hypertext Preprocessor) is a widely used open-source server-side scripting language primarily designed for web development. PHP code can be embedded directly into HTML pages, allowing developers to create dynamic web pages with ease. PHP code is enclosed within <?php ?> or <? ?> tags, making it easy to distinguish from HTML. PHP runs on various platforms, including Windows, Linux, macOS, and Unix, making it highly versatile and widely adopted across different operating systems.
PHP is open-source software, which means it’s free to use, modify, and distribute. Its open nature encourages collaboration and innovation within the development community. PHP offers support for various database management systems, including MySQL, MariaDB, PostgreSQL, SQLite, and more.
To install PHP on Linux follow these general steps.
Prerequisites
- Apache HTTP Server
Update Package Lists
First, update the package lists to ensure you’re getting the latest versions of the software.
sudo apt update
Install PHP and necessary modules
sudo apt install php libapache2-mod-php php-mysql
Verify installation
After installation, you can verify that PHP is installed correctly.
php -v
Output:
PHP 8.1.2-1ubuntu2.17 (cli) (built: May 1 2024 10:10:07) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2-1ubuntu2.17, Copyright (c), by Zend Technologies
with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans
If Apache is already running, you’ll need to restart it to make sure it picks up the changes and loads the PHP module.
sudo service apache2 restart
PHP should now be installed and running on your Linux system.
Test PHP
Create a test PHP file in your document root (/var/www/html
) to verify that PHP is working correctly. Create a file named info.php
with the following contents:
<?php
phpinfo();
?>
Show PHP info page (info.php
file). Open your web browser and enter the following text into the address bar.
http://localhost/info.php
Conclusion
Following these instructions should get PHP up and running on your Linux distribution, allowing you to start developing PHP applications. If you encounter any issues, read the following article.