xref: /web-php/build-setup.php (revision 00342c40)
1<?php
2$_SERVER['BASE_PAGE'] = 'build-setup.php';
3include_once __DIR__ . '/include/prepend.inc';
4
5$SIDEBAR_DATA = '
6<div class="panel">
7  <div class="body">
8    <p>
9      This page is intended to help setup a development environment for PHP, if mistakes are found
10      please <a href="http://bugs.php.net">report</a> them.
11    </p>
12  </div>
13</div>
14';
15
16site_header("Operating System Preparation", ["current" => "community"]);
17
18?>
19<h2 id="os-prep" class="content-header">Operating System Preparation</h2>
20<div class="content-box">
21<p>
22    Improving PHP requires a working build environment to test changes, the following section deals with setting up a working build environment.
23</p>
24<p>
25    Your build environment should have an appropriate toolchain that includes a working C compiler,
26        for those not working in Microsoft Windows, you will need a working, compatible autotools installation, and at the very least a shared copy of zlib.
27</p>
28<p>
29    For most *nix like operating systems, some external dependencies may be required to bring a build to completion;
30        if a build fails because of missing headers or libraries, issuing a variant of the following command should resolve those dependencies, allowing the build to continue:
31    <ul>
32        <li><pre class="small">[sudo] yum|apt-get|ports install package[-dev[el]]</pre></li>
33    </ul>
34</p>
35<p>
36    For those working in <i>Ubuntu Linux</i>, you can run the following command to automate the installation of dependencies:
37    <ul>
38        <li><pre class="small">sudo apt-get build-dep php5</pre></li>
39    </ul>
40    If the compilation of <i>an extension</i> should fail because of missing dependencies, <i>Ubuntu Linux</i> can attempt to automate the resolution of those dependencies by issuing:
41    <ul>
42        <li><pre class="small">sudo apt-get build-dep php5-<i>extname</i></pre></li>
43    </ul>
44</p>
45<p>
46    The following table shows what is required for Microsoft Windows users to build PHP:
47</p>
48<table>
49<tr>
50    <th>PHP</th>
51    <th>Visual C++</th>
52    <th>MS SDK</th>
53    <th>DEPS</th>
54    <th>PHP SDK</th>
55</tr>
56<tr>
57    <td align="center">5.3</td>
58    <td align="center">Visual Studio 2008</td>
59    <td align="center">6.1</td>
60    <td align="center"><a href="http://windows.php.net/downloads/php-sdk/deps-5.3-vc9-x86.7z">x86</a></td>
61    <td align="center"><a href="http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110512.zip">here</a></td>
62</tr>
63<tr>
64    <td align="center">5.4</td>
65    <td align="center">Visual Studio 2008</td>
66    <td align="center">6.1</td>
67    <td align="center"><a href="http://windows.php.net/downloads/php-sdk/deps-5.4-vc9-x86.7z">x86</a></td>
68    <td align="center"><a href="http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip">here</a></td>
69</tr>
70<tr>
71    <td align="center">5.5</td>
72    <td align="center">Visual Studio 2008</td>
73    <td align="center">6.1</td>
74    <td align="center"><a href="http://windows.php.net/downloads/php-sdk/deps-5.5-vc9-x86.7z">x86</a></td>
75    <td align="center"><a href="http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip">here</a></td>
76</tr>
77<tr>
78    <td align="center">5.5</td>
79    <td align="center">Visual Studio 2012</td>
80    <td align="center">N/A</td>
81    <td align="center">
82        <a href="http://windows.php.net/downloads/php-sdk/deps-5.5-vc11-x86.7z">x86</a>,
83        <a href="http://windows.php.net/downloads/php-sdk/deps-5.5-vc11-x64.7z">x64</a>
84    </td>
85    <td align="center"><a href="http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip">here</a></td>
86</tr>
87</table>
88<p><b>Note:</b>&nbsp;If a Windows SDK is required, it is advised to install the SDK <i>before</i> Visual Studio.</p>
89</div>
90
91<h2 id="workspace-prep" class="content-header">Workspace Preparation</h2>
92<div class="content-box">
93<p>
94    Windows users should now download and unzip the PHP SDK to their workspace and execute the following commands in an appropriate Visual Studio Console:
95</p>
96<p>
97    Visual Studio 2008:
98    <ul>
99        <li><pre>setenv /xp /Release /x86</pre></li>
100    </ul>
101    Visual Studio 2008 and 2012:
102    <ul>
103        <li><pre class="small">cd C:\path-to-workspace</pre></li>
104        <li><pre class="small">bin\phpsdk_setvars.bat</pre></li>
105        <li><pre class="small">bin\phpsdk_buildtree.bat phpdev</pre></li>
106    </ul>
107    Windows should now change to the directory C:\path-to-workspace\phpdev\<i>VCXX</i>\<i>XARCH</i>, and consider it the root of the workspace for the current build.
108</p>
109<p>
110    The next step for everyone is to obtain the versioned PHP sources via git:
111    <ul>
112        <li><pre class="small">git clone -b BRANCH https://github.com/php/php-src .</pre></li>
113    </ul>
114    BRANCH should be replaced with an appropriate branch name, for example <i>PHP-5.5</i>.
115</p>
116<p>
117    At this point you have a working build environment and the vanilla sources for your chosen branch of PHP, it is a good idea, before you change anything at all, to create a new branch and switch to it, in preparation for your awesome changes to come:
118    <ul>
119        <li><pre class="small">git checkout -b my-awesome-changes</pre></li>
120    </ul>
121</p>
122</div>
123
124
125<h2 id="build-dev" class="content-header">Building Your Development PHP</h2>
126<div class="content-box">
127<p>
128    All operating systems now converge on (near as makes no difference) the same solutions for the rest of the build process:
129    <ul class="listed">
130        <li><pre class="small">buildconf: generates the configure script for PHP</pre></li>
131        <li><pre class="small">configure: configures the build of PHP and creates Makefile</pre></li>
132        <li><pre class="small">make: builds PHP</pre></li>
133        <li><pre class="small">make test: runs testsuite</pre></li>
134        <li><pre class="small">make install: installs PHP</pre></li>
135    </ul>
136</p>
137<p>
138    For Microsoft Windows operating systems, those commands looks like this:
139    <ul class="listed">
140        <li><pre class="small">buildconf</pre></li>
141        <li><pre class="small">configure --with-prefix=C:\my-awesome-php</pre></li>
142        <li><pre class="small">nmake</pre></li>
143        <li><pre class="small">nmake test</pre></li>
144        <li><pre class="small">nmake install</pre></li>
145    </ul>
146</p>
147<p>
148    While for the rest of us, those commands look like this:
149    <ul class="listed">
150        <li><pre class="small">./buildconf</pre></li>
151        <li><pre class="small">./configure --prefix=/opt/my-awesome-php</pre></li>
152        <li><pre class="small">make</pre></li>
153        <li><pre class="small">make test</pre></li>
154        <li><pre class="small">make install</pre></li>
155    </ul>
156</p>
157<p>
158    The <i>configure</i> script has the ability to customize almost every aspect of PHP, to elicit help at the console pass <i>--help</i>
159 as the only argument to <i>configure</i></p>
160<p>
161    When <i>configure</i> executes, it saves the options passed in to a re-usable <i>config.nice</i> which executes <i>configure</i> when invoked.
162</p>
163<p>
164    Upon successful completion of a build, it is recommended to run the test suite, this will help you to identify regression problems in your work,
165        running the test suite can take a while; go out for a run, or a burger.
166</p>
167<p>
168    It is also possible to run a set (directory) of tests in the following way:
169    <ul>
170        <li><pre class="small">[n]make test TESTS=sapi/cli</pre></li>
171    </ul>
172</p>
173</div>
174<?php
175site_footer(['sidebar' => $SIDEBAR_DATA]);
176