Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Documentation for the php7dev Vagrant box image

1. Summary
php7dev is a Debian 8 Vagrant image1 which is preconfigured for testing PHP apps and developing
extensions across many versions of PHP. See the Changelog2 .

2. Installation
doc.istidy.com

Download and install Virtualbox3


Download and install Vagrant4
If you are on Windows, download and install Git5
Make sure you are at least at Vagrant version 1.5 or the steps below may not work for you.
If you are on Windows use the Manual Install6 instructions or use git-bash.
Otherwise for UNIX and UNIX-like users just clone and go. Like this:

1 $ g i t c l o n e h t t p s : // g i t h u b . com/ r l e r d o r f / php7dev . g i t
2 ...
3 $ cd php7dev
4 ...
5 $ v a g r a n t up
6 ...
7 $ vagrant ssh

Add this to your hosts file:

1 1 9 2 . 1 6 8 . 7 . 7 php7dev

There are also various vagrant plugins that can help you update your dns. See local-domain-resolution7 .
At this point you should be able to point your browser at:

1 h t t p : // php7dev /

and it should show the PHP7 phpinfo() page.


The box will also fetch an ip via DHCP so it will be on your local network like any other machine. This
also means you don’t need to use vagrant ssh anymore.
1 https://atlas.hashicorp.com/rasmus/boxes/php7dev
2 #changelog
3 https://www.virtualbox.org/wiki/Downloads
4 https://www.vagrantup.com/downloads.html
5 https://git-scm.com/download/win
6 #manual-install
7 https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins#local-domain-resolution

1
3. Manual Install
You don’t really need the helpers in the Github repo. I doubt they work well on Windows. You can get
up and running using just Vagrant.

1 $ vagrant box add rasmus / php7dev


2 ...
3 $ vagrant i n i t rasmus / php7dev
4 ...
5 $ vagrant up
6 ...
7 $ vagrant ssh

If you have vagrant version <1.5, you may run into “command was not invoked properly” error with
vagrant box add rasmus/php7dev, then you can run it with the following explicit url:
doc.istidy.com

1 $ v a g r a n t box add ” rasmus / php7dev ” h t t p s : // v a g r a n t c l o u d . com/ rasmus / b o x e s / php7dev / v e r s i o n s


/ 0 . 0 . 7 / p r o v i d e r s / v i r t u a l b o x . box

For DHCP add:

1 c o n f i g . vm . network ” p u b l i c n e t w o r k ” , t y p e : ” dhcp ”

To your Vagrantfile. For a static IP, add:

1 c o n f i g . vm . network ” p r i v a t e n e t w o r k ” , i p : ” 1 9 2 . 1 6 8 . 7 . 7 ”

Full docs on this is at https://docs.vagrantup.com/v2/networking/private network.html8 .

4. Updating your php7dev image

1 $ v a g r a n t box o u t d a t e d
2 Checking i f box ' rasmus / php7dev ' i s up t o d a t e . . .
3 A newer v e r s i o n o f t h e box ' rasmus / php7dev ' i s a v a i l a b l e ! You c u r r e n t l y
4 have v e r s i o n ' 0 . 0 . 3 ' . The l a t e s t i s v e r s i o n ' 0 . 0 . 4 ' . Run
5 ` v a g r a n t box update ` t o update .
6
7 $ v a g r a n t box update
8 ...
9
10 $ v a g r a n t box l i s t
11 rasmus / php7dev ( v i r t u a l b o x , 0 . 0 . 3 )
12 rasmus / php7dev ( v i r t u a l b o x , 0 . 0 . 4 )

At this point you have two versions of the box. It won’t automatically destroy your current one since you
could have added some important data to it. To use this new version, make sure anything you need from
your current one is saved elsewhere and do:

8 https://docs.vagrantup.com/v2/networking/private_network.html

2
1 $ vagrant destroy
2 d e f a u l t : Are you s u r e you want t o d e s t r o y t h e ' d e f a u l t ' VM? [ y/N] y
3 ==> d e f a u l t : F o r c i n g shutdown o f VM. . .
4 ==> d e f a u l t : D e s t r o y i n g VM and a s s o c i a t e d d r i v e s . . .
5
6 $ v a g r a n t up
7 ...

If virtualbox complains about an unsupported provider, make sure to have a working virtualbox and prefix
the command with “VAGRANT DEFAULT PROVIDER=virtualbox“:

1 $ VAGRANT DEFAULT PROVIDER=v i r t u a l b o x v a g r a n t up


2 ...
doc.istidy.com

5. Compiling the latest PHP 7


There is a script called makephp which does unattended builds. To build and install the latest PHP 7.0
and PHP 7.0-debug just do:

1 $ makephp 7

Or you can build it manually like this:

1 $ cd php−s r c
2 $ g i t p u l l −r
3 $ make d i s t c l e a n
4 $ . / b u i l d c o n f −f
5 $ . / cn
6 $ make
7 $ sudo make i n s t a l l
8 $ newphp 7 debug

Note the ./cn script. The –prefix setting specifies where to install to. Make sure the path matches your
debug/zts setting. You can change that script to build the non-debug version by changing –enable-debug
to –disable-debug and removing -debug from the --prefix. In that case you would just do: newphp 7

6. Web Server
The default web server is nginx. Switching to Apache is as simple as:

1 $ sudo s e r v i c e n g i n x s t o p
2 $ sudo a p a c h e c t l s t a r t

Running newphp will correctly enable the specified PHP version and restart Apache for you.
There are a couple of other convenience scripts. makeext in an extension’s directory will build and install
that extension for the specified version of PHP. For example:

3
1 vagrant@php7dev : ˜ $ cd s r c
2 vagrant@php7dev : ˜ / s r c $ g i t c l o n e h t t p s : // g i t h u b . com/ p h p r e d i s / p h p r e d i s . g i t
3 Cloning i n t o ' phpredis ' . . .
4 vagrant@php7dev : ˜ / s r c $ cd p h p r e d i s /
5 vagrant@php7dev : ˜ / s r c / p h p r e d i s $ g i t c h e c k o u t php7
6 Branch php7 s e t up t o t r a c k remote branch php7 from o r i g i n .
7 S w i t c h e d t o a new branch ' php7 '
8 vagrant@php7dev : ˜ / s r c / p h p r e d i s $ makeext 7
9 B u i l d l o g i n /tmp/ b u i l d . l o g
10 B u i l d i n g e x t e n s i o n f o r PHP 7
11 configuring . . .
12 compiling . . .
13 installing . . .
14 done
15 B u i l d i n g PHP 7−debug
16 configuring . . .
17 compiling . . .
18 installing . . .
19 done
20 vagrant@php7dev : ˜ / s r c / p h p r e d i s $ makeext 71
doc.istidy.com

21 B u i l d l o g i n /tmp/ b u i l d . l o g
22 B u i l d i n g e x t e n s i o n f o r PHP 71
23 configuring . . .
24 compiling . . .
25 installing . . .
26 done
27 B u i l d i n g PHP 71−debug
28 configuring . . .
29 compiling . . .
30 installing . . .
31 done

And a second helper script, phpext enables or disables an extension for the current version of PHP. eg.

1 vagrant@php7dev : ˜ / s r c / p h p r e d i s $ newphp 70
2 A c t i v a t i n g PHP 7 . 0 . 1 2 − dev ( c l i ) ( b u i l t : Sep 6 2016 0 4 : 4 7 : 0 5 ) ( NTS ) and r e s t a r t i n g php−fpm
3 vagrant@php7dev : ˜ / s r c / p h p r e d i s $ phpext e n a b l e r e d i s
4 R e s t a r t i n g php−fpm . . .
5 vagrant@php7dev : ˜ / s r c / p h p r e d i s $ php −m | g r e p r e d i s
6 redis

or

1 vagrant@php7dev : ˜ $ newphp 71
2 A c t i v a t i n g PHP 7 . 1 . 0 − dev ( c l i ) ( b u i l t : Sep 6 2016 0 4 : 3 8 : 1 3 ) ( NTS ) and r e s t a r t i n g php−fpm
3 vagrant@php7dev : ˜ $ phpext l i s t
4 A v a i l a b l e e x t e n s i o n s f o r PHP 7 . 1 . 0 − dev :
5 ast ( enabled )
6 http ( enabled )
7 mailparse
8 memcached ( e n a b l e d )
9 mysql ( e n a b l e d )
10 r e d i s ( enabled )
11 ssh2
12 xdebug ( e n a b l e d )
13 vagrant@php7dev : ˜ $ phpext d i s a b l e xdebug
14 R e s t a r t i n g php−fpm . . .
15 xdebug d i s a b l e d

4
7. Installing phpBB
Now you can install something. The sites live in /var/www.
For example, to install phpBB:

1 $ cd / v a r /www
2 $ wget h t t p s : //www. phpbb . com/ f i l e s / r e l e a s e /phpBB − 3 . 1 . 2 . z i p
3 ...
4 $ u n z i p phpBB − 3 . 1 . 2 . z i p
5 ...
6 $ sudo chown −R www−data phpBB3

Create /etc/nginx/conf.d/phpbb.conf with this config:

1 server {
2 l i s t e n 80;
s e r v e r n a m e phpbb ;
doc.istidy.com

3
4 root / v a r /www/phpBB3 ;
5 index i n d e x . php i n d e x . html i n d e x . htm ;
6 a c c e s s l o g / v a r / l o g / n g i n x /phpbb−a c c e s s . l o g ;
7 e r r o r l o g / v a r / l o g / n g i n x /phpbb−e r r o r . l o g ;
8
9 l o c a t i o n ˜ / ( c o n f i g \ . php | common \ . php | c a c h e | f i l e s | images / a v a t a r s / u pl oa d | i n c l u d e s | s t o r e ) {
10 deny a l l ;
11 return 403;
12 }
13
14 l o c a t i o n ˜∗ \ . ( g i f | j p e ? g | png | c s s ) $ {
15 expires 30d ;
16 }
17
18 i n c l u d e php . c o n f ;
19 }

You will need to sudo to do it. It shouldn’t ask you for a password, but every password, sudo, root, mysql
is set to: vagrant in case you need it.
Then do:

1 $ sudo s e r v i c e n g i n x r e l o a d

On the machine where you are running your web browser, add an entry to your /etc/hosts file with:

1 1 9 2 . 1 6 8 . x . x phpbb

Substitute your ip there, of course.


Now you can go to http://phpbb/ and you should be redirected to the phpBB installer.
Before you start, you need to create the database:

1 $ mysqladmin c r e a t e phpbb

Now go through the steps. Your Database host is localhost and the user is vagrant, password vagrant.
Database name is phpbb. You can leave the port empty. Click through the rest and you should be done.
Then remove the install directory to get rid of the annoying warning:

5
1 $ sudo rm − r f / v a r /www/phpBB3/ i n s t a l l /

8. Adding Shared Folders


Add shared folders by adding them to the folders section in the php7dev.yaml configuration file.

9. Toggle Public Network


By default the vagrant machine will use DHCP to be accessible over the local network. This can be
disabled in the php7dev.yaml configuration file.

10. Add MySQL databases


doc.istidy.com

Add the name of the database you want to be created in the databases section of the php7dev.yaml
configuration file.

11. Installing other apps


For the most part installing almost anything follows the same pattern. Download the tarball or zip file to
/var/www. Extract, make it owned by www-data and find the nginx server config. Usually a quick Google
search will turn it up. If it doesn’t, something like:

1 server {
2 l i s t e n 80;
3 server name mysite ;
4 r o o t / v a r /www/ m y s i t e ;
5 a c c e s s l o g / v a r / l o g / n g i n x / mysite −a c c e s s . l o g ;
6 e r r o r l o g / v a r / l o g / n g i n x / mysite −e r r o r . l o g ;
7
8 i n d e x i n d e x . php i n d e x . html ;
9
10 location / {
11 t r y f i l e s $uri $uri / @rewrite ;
12 }
13 l o c a t i o n @rewrite {
14 r e w r i t e ˆ ( . ∗ ) $ / i n d e x . php ;
15 }
16
17 i n c l u d e php . c o n f ;
18 }

Usually does the trick. You will also find composer9 already installed in /usr/local/bin.

12. Switching PHP versions


New in version 0.0.3 of the image is the ability to switch the entire PHP environment quickly. Every
version of PHP since 5.3 is precompiled and installed in /usr/local/php. There are actually 4 builds for each
version. debug, zts, debug-zts and the standard non-debug, non-zts. To switch versions do:

9 https://getcomposer.org/

6
1 $ newphp 55 debug z t s
2 A c t i v a t i n g PHP 5 . 5 . 2 2 − dev and r e s t a r t i n g php−fpm

If you reload http://php7dev/ you will see the PHP 5.5 info page, but much more importanly, if you run
phpize in an extension directory it will now build the extension for PHP 5.5-debug-zts and install it in the
correct place. You can quickly switch between versions like this and build your extension for 24 different
combinations of PHP versions (this was requested by @auroraeosrose so if it is useful to you, she is partly
to blame - if it isn’t, blame me).
For quick testing there are symlinks in /usr/local/bin to the various versions, so you can quickly check
php56 -a without activating it. Similarly, you can do:

1 $ s e r v i c e php−fpm s t o p
2 $ s e r v i c e php56−fpm s t a r t
doc.istidy.com

13. Debugging Tools


For debugging, you have many options. Valgrind is installed and the suppressions file is up to date. I
have included a helper script I use called memcheck. Try it:

1 $ memcheck php −v
2 ==3788== Memcheck , a memory e r r o r d e t e c t o r
3 ==3788== C o p y r i g h t (C) 2002 −2011 , and GNU GPL ' d , by J u l i a n Seward e t a l .
4 ==3788== Using V a l g r i n d − 3 . 7 . 0 and LibVEX ; r e r u n with −h f o r c o p y r i g h t i n f o
5 ==3788== Command : php −v
6 ==3788==
7 PHP 7 . 0 . 0 − dev ( c l i ) ( b u i l t : Jan 28 2015 1 5 : 5 3 : 1 2 ) (DEBUG)
8 C o p y r i g h t ( c ) 1997 −2015 The PHP Group
9 Zend Engine v3 . 0 . 0 − dev , C o p y r i g h t ( c ) 1998 −2015 Zend T e c h n o l o g i e s
10 with Zend OPcache v7 . 0 . 4 − dev , C o p y r i g h t ( c ) 1999 −2015 , by Zend T e c h n o l o g i e s
11 ==3788==
12 ==3788== HEAP SUMMARY:
13 ==3788== i n u s e a t e x i t : 1 9 , 1 1 2 b y t e s i n 17 b l o c k s
14 ==3788== t o t a l heap u s a g e : 2 9 , 4 5 9 a l l o c s , 2 9 , 4 4 2 f r e e s , 3 , 0 3 3 , 3 0 3 b y t e s a l l o c a t e d
15 ==3788==
16 ==3788== LEAK SUMMARY:
17 ==3788== d e f i n i t e l y l o s t : 0 bytes in 0 blocks
18 ==3788== i n d i r e c t l y l o s t : 0 bytes in 0 blocks
19 ==3788== possibly l o s t : 0 bytes in 0 blocks
20 ==3788== s t i l l reachable : 0 bytes in 0 blocks
21 ==3788== s u p p r e s s e d : 1 9 , 1 1 2 b y t e s i n 17 b l o c k s
22 ==3788==
23 ==3788== For c o u n t s o f d e t e c t e d and s u p p r e s s e d e r r o r s , r e r u n with : −v
24 ==3788== ERROR SUMMARY: 0 e r r o r s from 0 c o n t e x t s ( s u p p r e s s e d : 28 from 6 )

Also, sometimes it is easier to track down issues with a single standalone process instead of using php-fpm.
You can do this like this:

1 $ sudo s e r v i c e php−fpm s t o p
2 $ sudo php−c g i −b / v a r / run /php−fpm . s o c k

The debug build will report memory leaks and you can of course run it under gdb or valgrind as well.
See the /usr/local/bin/memcheck script for how to run Valgrind.
You will also find a .gdbinit symlink in vagrant which provides a number of useful gdb macros. The
symlink into php-src should ensure you have the right set for the current checked out version of the code.

7
14. APT
And a tiny apt primer:
update pkg list: sudo apt-get update

search for stuff: apt-cache search stuff


install stuff: sudo apt-get install stuff
list installed: dpkg -l

upgrade installed: apt-get upgrade


If something isn’t working or you have suggestions, please let me know here.

15. Changelog
doc.istidy.com

16. Changes in 1.0.0


Upgrade to Vagrant 1.8.5
Updated all PHP builds to the latest

Updated all Debian packages


Added phpext script to enable/disable extensions
Added xdebug, yaml, stats and redis extensions

Big Phan update

17. Changes in 0.1.0


Updated all PHP builds to the latest

Updated all Debian packages


Added PHP 7.1 builds bringing the total builds included to 24
Added php-fpm systemd support
Included pear and pecl tools

Enabled the PHP 7 file-based opcache cache


Fully supported Apache in newphp version switching
Added AST extension to PHP 7 builds

Added Phan static analyzer


Added memcached extension to all versions
Added raphf, propro and http extensions to all versions

8
18. Changes in 0.0.9
Upgraded the base image OS from Debian 7.8 to 8.0 and recompiled all 20 PHP builds
Added PosgreSQL support to all builds

newphp will now switch the Apache module between PHP 5 and PHP 7 (default is still nginx)
Added ack
Updated virtualbox guest-additions

19. Changes in 0.0.8


Fix double-entry in /etc/network/interfaces

20. Changes in 0.0.7


doc.istidy.com

Try to fix vagrant ssh issue by adding new insecure vagrant key

21. Changes in 0.0.6


Default PHP version is 7 again
Use -j2 in makephp since the vm is configured for 2 CPUs
Updated composer
Put image version in /etc/motd

22. Changes in 0.0.5


dist-upgraded all Debian packages

Updated newphp script - no longer need to sudo


Added makephp script
Added src/mysql checkout from pecl
Rebuilt all PHP versions

Added phpdbg to PHP 7.0 builds


Updated Valgrind .suppressions file
Re-installed headers as per https://github.com/rlerdorf/php7dev/issues/4
Installed strace

You might also like