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.
You can see all the options the
configure script offers with
$ ./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.
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 --version
You can list the loaded extensions with
$ sapi/cli/php -m
- PHP Internals Book: Building PHP
- PHP source on GitHub
- Take part in PHP TestFest 2017
- I'll be giving talks about writing tests for PHP source at NEPHP 2017 and ZendCon 2017. Join me! :)
All posts in this series
- 01: Compiling PHP from source
- 02: Running the test suite
03: All about
- 04: Debugging failed tests
- 05: Finding untested code
- 06: Submitting a PR to php-src