php7 Development With Vagrant
php7 Development With Vagrant
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
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
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 /
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.
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 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 ”
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 ”
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 $ makephp 7
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
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
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 /
Add the name of the database you want to be created in the databases section of the php7dev.yaml
configuration file.
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.
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
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
15. Changelog
doc.istidy.com
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
Try to fix vagrant ssh issue by adding new insecure vagrant key