Subscribe to PHP Freaks RSS

01: Compiling PHP from source

syndicated from planet-php.net on July 12, 2017


If you've ever wanted to get involved with PHP internals, writing tests is a great way to get your foot into the door. The tests are written in PHP so you don't even need to know C to get started.

The first step to writing tests for PHP source is downloading and compiling the PHP source code.

Install the dependencies

Before you can comple the source code, you'll need to install a few dependencies. This command will install all the dependencies in the screencast.

Note: These instructions assume you are running Ubuntu.

$ sudo apt-get update
$ sudo apt-get install git build-essential \
autoconf re2c bison libxml2-dev -y

Clone the `php-src` repo

We'll be cloning the code to /usr/src, but you can put it anywhere you like on your computer.

$ cd /usr/src
$ git clone https://github.com/php/php-src.git

Configure & make

Since the repo doesn't contain a configure script, we'll need to build it first.

$ ./buildconf

You can see all the options the configure script offers with --help

$ ./configure --help

In the video we configured with the following flags:

$ ./configure --enable-maintainer-zts \
--enable-debug \
--enable-cli

Compile the source code with make. This should take a little while.

$ make

You can speed up how fast make compiles by using the -j flag. You want to set it to the number of cores you have +1. On Ubuntu nproc will show you the number of cores you have.

$ nproc
> 4
$ make -j5

After make is done, you should have an executable PHP binary at sapi/cli/php.

$ sapi/cli/php --version

You can list the loaded extensions with -m.

$ sapi/cli/php -m

Resources


All posts in this series