Installing PHP from Source on Arch Linux: A Step-by-Step Guide

tushartushar
3 min read

PHP (Hypertext Preprocessor) is a popular server-side scripting language used for web development. Installing PHP from source allows you to customize and optimize your PHP installation. This guide will walk you through the process of installing PHP from source on Arch Linux.

Prerequisites

Before starting, make sure you have the necessary tools and libraries installed on your system. These tools help in building and configuring PHP.

Install Essential Packages:

  1. Open your terminal.

  2. Run the following command to install the necessary packages:

sudo pacman -S base-devel autoconf bison re2c libxml2 sqlite
  • base-devel includes essential development tools.

  • autoconf, bison, and re2c are required for generating configuration scripts.

  • libxml2 and sqlite are libraries needed for PHP.

Downloading and Extracting PHP Source

  1. Download the PHP source code:
  • You can obtain the PHP source code from the official PHP website or other sources.

  • Download the .tar.gz file.

2. Extract the downloaded file:

  • Once you have the .tar.gz file, use the following command to extract it:
tar -xzf php-<version>.tar.gz
  • Replace /path/to/extracted_directory with the actual path where you extracted the PHP source code.

  • Replace <version> with the specific version number of PHP you downloaded.

Building and Installing PHP

  1. Navigate to the PHP source directory:
cd /path/to/extracted_directory
  • Replace /path/to/extracted_directory with the actual path where you extracted the PHP source code.

2. Generate Configuration Scripts:

./buildconf
  • This command sets up the necessary configuration files for the build process.

3. Configure the Build:

./configure
  • This command prepares the PHP source code for compilation. For a development build, you can use ./configure --enable-debug.

4. Compile PHP:

make -j4
  • The -j4 option tells make to use 4 parallel jobs to speed up the build process. Adjust this number based on your CPU cores.

5. Test the Build (Optional):

make TEST_PHP_ARGS=-j4 test
  • Running tests ensures that PHP is built correctly. This step is optional but recommended.

6. Install PHP:

sudo make install
  • This command installs PHP on your system. You may need superuser permissions (sudo) for this step.

Verifying the Installation

To ensure PHP is installed correctly, check the PHP version:

php -v

You should see the PHP version and build information displayed.

Congratsss!!! You have successfully installed PHP from source on Arch Linux!

But if the installation didn’t go well, try these troubleshooting methods.

Troubleshooting

  • Missing Dependencies: Ensure all required libraries and tools are installed.

  • Permission Issues: Use sudo for commands that require administrative privileges.

  • Configuration Errors: Review the output of configure and make for any errors or warnings.

Thanks, See ya.

0
Subscribe to my newsletter

Read articles from tushar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

tushar
tushar