Current Location: Home> Latest Articles> Complete Guide to Installing and Configuring PHP on Linux

Complete Guide to Installing and Configuring PHP on Linux

gitbox 2025-07-17

Complete Process of Installing PHP on Linux

PHP remains a widely used server-side scripting language in modern web development. Especially in Linux environments, knowing how to install and configure PHP is crucial for setting up a robust development or deployment platform.

System Update

Before installing PHP, it is recommended to update your system to avoid compatibility issues. Use the command below to ensure your system is up to date:

sudo apt-get update && sudo apt-get upgrade

Install Dependencies

Some essential libraries are required for PHP to function properly. Install them with the following command:

sudo apt-get install software-properties-common

Add PHP Repository

To install the latest version of PHP, you need to add the official PHP repository:

sudo add-apt-repository ppa:ondrej/php

After adding the repository, update the package list:

sudo apt-get update

Install PHP and Extensions

Now install PHP and some commonly used modules. The following example installs PHP version 8.0:

sudo apt-get install php8.0 php8.0-cli php8.0-fpm php8.0-mysql

Explanation of modules:

  • php8.0-cli: Provides command-line support
  • php8.0-fpm: FastCGI Process Manager for handling PHP with servers like Nginx
  • php8.0-mysql: Enables MySQL database interaction

Verify Installation

After installation, you can confirm PHP is working with the following command:

php -v

If PHP version info is displayed, the installation was successful.

Edit php.ini Configuration

Depending on your project needs, you may want to adjust PHP’s configuration file. Open php.ini to make changes:

sudo nano /etc/php/8.0/fpm/php.ini

Important settings to consider modifying:

  • memory_limit
  • upload_max_filesize
  • post_max_size

Restart PHP Service

After making changes, restart the PHP service to apply the new configuration:

sudo systemctl restart php8.0-fpm

Conclusion

With the steps outlined in this guide, you can install and configure PHP on a Linux system efficiently. Whether you're setting up a local development environment or a live server, mastering this process will boost your productivity in PHP web development.