PHP

PHP TutorialCompile PHP ExtensionsContributing to the PHP CoreContributing to the PHP ManualCreate PDF files in PHPInstalling a PHP environment on WindowsPHP Alternative Syntax for Control StructuresPHP APCuPHP Array iterationPHP ArraysPHP Asynchronous programmingPHP Autoloading PrimerPHP BC Math (Binary Calculator)PHP Built in serverPHP CachePHP Classes and ObjectsPHP ClosurePHP Coding ConventionsPHP Command Line Interface (CLI)PHP CommentsPHP Common ErrorsPHP Compilation of Errors and WarningsPHP Composer Dependency ManagerPHP ConstantsPHP Control StructuresPHP CookiesPHP CryptographyPHP DateTime ClassPHP DebuggingPHP Dependency InjectionPHP Design PatternsPHP Docker deploymentPHP Exception Handling and Error ReportingPHP Executing Upon an ArrayPHP File handlingPHP Filters & Filter FunctionsPHP Functional ProgrammingPHP FunctionsPHP GeneratorsPHP Headers ManipulationPHP How to break down an URLPHP How to Detect Client IP AddressPHP HTTP AuthenticationPHP Image Processing with GDPHP ImagickPHP IMAPPHP Installing on Linux/Unix EnvironmentsPHP JSONPHP LocalizationPHP LoopsPHP Machine learningPHP Magic ConstantsPHP Magic MethodsPHP Manipulating an ArrayPHP mongo-phpPHP Multi Threading ExtensionPHP MultiprocessingPHP MySQLiPHP MySQLi affected rows returns 0 when it should return a positive integerPHP NamespacesPHP Object SerializationPHP OperatorsPHP Output BufferingPHP Outputting the Value of a VariablePHP Parsing HTMLPHP Password Hashing FunctionsPHP PDOPHP PerformancePHP PHPDocPHP Processing Multiple Arrays TogetherPHP PSRPHP Reading Request DataPHP RecipesPHP ReferencesPHP ReflectionPHP Regular Expressions (regexp/PCRE)PHP Secure Remeber MePHP SecurityPHP Sending EmailPHP SerializationPHP SessionsPHP SimpleXMLPHP SOAP ClientPHP SOAP ServerPHP SocketsPHP SPL data structuresPHP SQLite3PHP StreamsPHP String formattingPHP String Parsing



Compile PHP Extensions

From WikiOD

Compiling on Linux[edit | edit source]

To compile a PHP extension in a typical Linux environment, there are a few pre-requisites:

  • Basic Unix skills (being able to operate "make" and a C compiler)
  • An ANSI C compiler
  • The source code for the PHP extension you want to compile

Generally there are two ways to compile a PHP extension. You can statically compile the extension into the PHP binary, or compile it as a shared module loaded by your PHP binary at startup. Shared modules are more likely since they allow you to add or remove extensions without rebuilding the entire PHP binary. This example focuses on the shared option.

If you installed PHP via your package manager (apt-get install, yum install, etc..) you will need to install the -dev package for PHP, which will include the necessary PHP header files and phpize script for the build environment to work. The package might be named something like php5-dev or php7-dev, but be sure to use your package manager to search for the appropriate name using your distro's repositories. They can differ.

If you built PHP from source the header files most likely already exist on your system (usually in /usr/include or /usr/local/include).

Steps to compile[edit | edit source]

After you check to make sure you have all the prerequisites, necessary to compile, in place you can head over to pecl.php.net, select an extension you wish to compile, and download the tar ball.

  1. Unpack the tar ball (e.g. tar xfvz yaml-2.0.0RC8.tgz)
  2. Enter the directory where the archive was unpacked and run phpize
  3. You should now see a newly created .configure script if all went well, run that ./configure
  4. Now you will need to run make, which will compile the extension
  5. Finally, make install will copy the compiled extension binary to your extension directory

The make install step will typically provide the installation path for you where the extension was copied. This is usually in /usr/lib/, for example it might be something like /usr/lib/php5/20131226/yaml.so. But this depends on your configuration of PHP (i.e. --with-prefix) and specific API version. The API number is included in the path to keep extensions built for different API versions in separate locations.

Loading the Extension in PHP[edit | edit source]

To load the extension in PHP, find your loaded php.ini file for the appropriate SAPI, and add the line extension=yaml.so then restart PHP. Change yaml.so to the name of the actual extension you installed, of course.

For a Zend extension you do need to provide the full path to the shared object file. However, for normal PHP extensions this path derived from the extension_dir directive in your loaded configuration, or from the $PATH environment during initial setup.

Credit:Stack_Overflow_Documentation