compile and install PHP on Linux


Answers ( 1 )


    Here's a detailed answer to your question:

    Steps to Compile and Install PHP on Linux

    1. Install Required Dependencies: Before compiling PHP, you need to install several dependencies. The exact packages may vary based on your Linux distribution, but here are some common ones for Ubuntu/Debian-based systems:

      sudo apt-get update
      sudo apt-get install build-essential libxml2-dev libbz2-dev libcurl4-openssl-dev libmcrypt-dev libjpeg-dev libpng-dev libfreetype6-dev libmysqlclient-dev
    2. Download PHP Source Code: You can download the PHP source code from the official PHP website. Make sure to choose the version you want to install.

      tar -xvf php-8.1.0.tar.gz
      cd php-8.1.0

      Replace php-8.1.0.tar.gz and php-8.1.0 with the version you are downloading.

    3. Configure the Build: You can customize your PHP installation using the ./configure script. There are many options available, but here's a basic example:

      ./configure --prefix=/usr/local/php --with-curl --with-pdo-mysql --with-openssl --with-zlib

      This script configures PHP to be installed in /usr/local/php and includes support for Curl, PDO MySQL, OpenSSL, and zlib.

    4. Compile PHP: This step will compile the PHP source code. It might take some time depending on your system's capabilities.

    5. Install PHP: After compilation, you can install PHP onto your system:

      sudo make install
    6. Verify the Installation: To verify PHP is installed correctly, you can check its version:

      /usr/local/php/bin/php -v


    • The ./configure script offers many options to customize your PHP build. You can view all options by running ./configure --help.
    • Ensure that the PHP binary is added to your system's PATH variable for easy access.
    • You may need additional dependencies or configuration steps depending on the specific requirements of your PHP application and the Linux distribution you are using.
    • This process is for a standard installation. Some use cases might require additional extensions or configurations.


    Compiling and installing PHP on Linux gives you flexibility and control over the configuration and version of PHP on your system. However, it requires more steps and understanding of Linux and PHP internals compared to using pre-built packages. Remember to consult the PHP documentation and your Linux distribution's guides for specific details and updates.

Leave an answer