Installing the Build PHP environment

Source: Internet
Author: User
Tags php and php source code switches versions win32 automake

Installing the Build Environment

Now you may have at least one installed PHP and have used it to develop web-based applications. You may have downloaded a Win32 from Php.net to build and run on IIS or Windows version of Apache, or a package management system that uses your *nix (Linux, BSD, or other POSIX-compliant releases) to install a third-party-created binary.

Building PHP

Unless you are compiling the download source package yourself, you will definitely miss out on some knowledge points.

*nix Tools

The first tool that is essential to the C developer Tool Set is the compiler for C. Your distribution may default to include a, if lucky, it is gcc (GNU Compiler Collection). You can check if the compiler is installed by performing GCC version or CC version, and it will respond to installed compiler version information if it is already installed.

If you have not yet installed the compiler, you can download and install GCC in the way that you use the distribution officially specified. Usually this means downloading an. rpm or. deb file and executing a command to install it. Depending on the release version you use, you can simply use the following command to try the installation: Urpmi gcc, apt-get install gcc, pkg-add-r gcc, emerge gcc.

In addition to compilers, you will need the following programs and tools: Make, autoconf, Automake, Libtool. These tools can also be installed with the release package management system you are using, just as you would install GCC, or directly from the gnu.org download source package.

The recommended versions are: Libtool 1.4.3, autoconf 2.13, Automake 1.4 or 1.5. Newer versions of these software may also work well, but these versions are validated over the long term.

If you plan to use CVS to check out the latest PHP development version code, you need bison and flex to construct the language interpreter. Like other packages, these two packages can be installed using your Release Pack management system or compiled from the gnu.org download source.

If you choose CVS, you will also need to install a CVS client. Again, it may have been installed on your distribution, or you can download the compilation yourself. Unlike other packages, this package you need to download in cvshome.org.

WIN32 Tools

The translator is unfamiliar with the Windows environment, so skip over.

Get PHP Source code

When you download PHP, you have a centralized selection. First of all, if your release support, you can use the Apt-get source php5 such commands to download. The point of this approach is that there may be some problems with the distribution you use, and you need to modify the PHP source code, download from here, and be sure that these issues have been patched to make your build less problematic. The disadvantage is that most distributions are delayed for weeks than the official PHP release.

Another option is the preferences, which are downloaded in the Www.php.net php-x.y.z.tar.gz (x.y.z is the current release). These PHP releases are tested by countless PHP users around the world and are up to date.

You can also download the snapshot package from the Snaps.php.net. At this site, the latest version of all source code in the PHP version library will be packaged every few hours. Some submissions from PHP kernel developers may cause it to be temporarily unavailable, but if you need the latest PHP 6.0 features before the official release, This is the easiest place to get.

Finally, you can use CVS to get directly to the development version that the PHP kernel development team uses. If you're just developing extensions and embedded programs, there's no obvious benefit compared to using an official release package and getting a snapshot. But if you plan to release your extensions or other applications to the CVS library, it is useful to be familiar with the checkout process.

PHP has now used git to manage the code base, for CVS checkout no longer repeat, please visit https://github.com/php/php-src to get the latest source. If you want to contribute code for PHP, you can view the introduction of the project home page.

Configure PHP for development

In the first chapter we discuss whether you plan to develop extensions or dive into PHP's other applications, there are two special in building developer-friendly PHP./configure switches you need to use these two switches should be used with the other switches you use to build PHP.

Enable-debug

Debug on some key functions in PHP and the Zend source tree. First, it enables the memory leak report at the end of each request.

Recalling chapter three, "Memory management," ZENDMM implicitly releases the memory allocated for each request, but is not freed until the end of the script. By running a series of regression test cases on newly developed code, the leak point can be easily exposed so that it can be patched between releases. Let's take a look at the following code fragment:

void Show_value (int n)  
{  
    char *message = emalloc (1024);  
      
    sprintf (Message, "The value of N is%d\n", n);  
    php_printf ("%s", message);  
}

If this stupid code is executed during PHP request execution, it will leak 1024 bytes of memory. Typically, ZENDMM releases the script after it finishes executing.

When Enable-debug is turned on, the developer is provided with an error message to locate the problem:

/CVS/PHP5/EXT/SAMPLE/SAMPLE.C ():  freeing 0x084504b8 (1024 bytes), script=-=  
= Total 1 memory leaks detected = ==

This short but complete message tells you that ZENDMM cleaned the memory after you soiled it, and gave you a place where the leaked chunks of memory were allocated. With this information, it is easy to locate the problem, open the file, find the corresponding row, and add efree (message) to the appropriate position before the end of the function.

Of course, a memory leak is not the only problem you will find difficult to trace. Sometimes the problem is latent and rarely appears. For example, you work all night long, modify a lot of code and source files, when everything is done, you confidently execute make, test a simple script, and then see the following output:

$ Sapi/cli/php-r ' myext_samplefunc (); '
Segmentation Fault

It's just a symptom, what's the problem? See your Myext_samplefunc () implementation, and do not show any obvious clues, using GDB to run only display a string of unknown symbols.

Again, Enable-debug will help you. By adding this switch at./configure, the result of PHP binaries will contain all the debug symbols needed by all GDB and other core file inspectors to show where the problem is.

Using this option to rebuild with GDB triggers a crash, you can now see the following output:

#0 0x1234567 php_myext_find_delimiter (str=0x1234567 "foo@# (FHVN) @\x98\xe0 ...",  
                                      strlen=3, tsrm_ls=0x1234567)  
    p = strchr (str, ', ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.