How do i enable php extensions?

It’s not as difficult as it might sound, so here’s the quick-n-dirty way of installing and compiling your very own PHP extensions/libraries, from the PHP source code. With a normal install, not every library is compiled and installed – so it might leave you with several functions that aren’t working.

This guide is building a module for PHP 5.2, but the steps are identical for PHP 5.3, 5.4, 5.5, or 5.6.

In this case, I’ll assume you’re trying to compile the dBase-extension. It’ll probably start with the following error, shown on screen:

Fatal error: Call to undefined function dbase_create[] in ... on line ...

It means the extension wasn’t loaded – and in most cases isn’t present on the server at all. So we’ll have to create it ourselves.

Install the PHP development package

On Ubuntu/debian, you can use apt-get, it’s a piece of cake.

$ apt-get install php5-dev

On CentOS / Red Hat, use yum for your PHP packages.

$ yum install php-devel

[alternatively: check which repositories you’re using and which PHP package you have installed, the package may also be named php55-devel, or similar].

Download & unzip the PHP5 source code

Go the the PHP-download page, and select the complete PHP5 source code.

$ cd /usr/local/src
$ mkdir php_source
$ cd php_source
$ wget //be.php.net/distributions/php-5.2.6.tar.gz

Next, unzip the file you just downloaded [the “.gz”-file extensions means it has been gzipped].

$ gunzip php-5.2.6.tar.gz

And untar it.

$ tar xvf php-5.2.6.tar

Prepare the extension [phpize]

Go to the proper directory. You just untarred the files, so we’ll browse to that specific subdirectory [note; directory-names may vary, depending on the version you just downloaded]. In this case, we go to the “dbase” subfolder, but it could be any of the extensions you want to configure.

$ cd php-5.2.6/ext/dbase/

And use phpizein that directory.

$ cd /usr/local/src/php_source/php-5.2.6/ext/dbase/
$ phpize

Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519

Configure & Make the extension

Configure it

$ ./configure

And make it

$ make

The make command, will render a lot of text [compilation-info], and most likely end with the following snippet.

...
----------------------------------------------------------------------

Build complete.
[It is safe to ignore warnings about tempnam and tmpnam].

Extension is now created in ./.libs/dbase.so

Move it to the extensions directory

Woohoo, we compiled our dbase-extension! Now all we need to do, is activate it.

Move the extension

If you already have an extensions-directory on your server, use that one – if not, you can create a new directory to place the extensions. To find out, check the extension_dir directive.

$ php -i | grep extension_dir
extension_dir => /usr/lib/php/extensions/no-debug-non-zts-20121212

Copy the extension to that directory.

$ cp libs/dbase.so /usr/lib/php/extensions/no-debug-non-zts-20121212/

Edit your PHP.INI

The extension is ready to be included – now we need to change the php.ini file to load that particular extension. First, find out which php.ini your system is using [note: the CLI may load a different config than the php-fpm or the Apache module one, a phpinfo[] in your application would tell you for certain].

$ php -i | grep 'Configuration File'
Configuration File [php.ini] Path => /etc
Loaded Configuration File => /etc/php.ini

In the example above, we use /etc/php.ini as our base php.ini file.

$ vi /etc/php.ini

Add the module you want to load. I usually add these at the very bottom, where my changes are. This is relative to the extension_dir directive you found above.

extension=dbase.so

Restart your php

In case of Apache

$ /etc/init.d/httpd restart
$ /etc/init.d/apache2 restart

or php-fpm:

$ /etc/init.d/php-fpm restart

And it’s as easy as that!

PHP is a general-purpose server scripting language. It is a powerful and important tool for developing dynamic and interactive Web pages. It is widely used, free, fast, flexible, and pragmatic. After installing PHP and a web server on Windows, extensions are also needed because they provide added functionality. PHP with extensions is the best combination for the developers to develop more dynamic and interactive web pages or applications. Extensions can be chosen when PHP starts by modifying your php.ini. 

There are so many extensions are built into the Windows version of PHP. To load more extensions you require .dll files in your system. An extension directive or extra DLL does not require loading these extensions. There are many ways to install extensions, the following is one of the ways to install php extensions on Windows.

Prerequisites: Web server[e.g. Apache, XAMPP].

Verifying the extension is installed or not

To verify the extension is installed or not you have to follow the following step:

Step 1: Create a new file in the root directory with an extension.php like findingexten.php. In this file write the following code:

Step 2: Run this file in any browser and you will see the given extension is installed or not.

Installing PHP Extensions on Windows

To install PHP extension we need to follow the following steps:

Step 1: Click on the Config button then select the php.ini file for your PHP installation, and open it in a text editor. 

Step 2: Locate the line that specifies the location of the “extension = ” line. 

Step 3: Look for the extension you want to install and remove the semicolon preceding that line. For example, if you want to install an IMAP extension, remove the semicolon of the following line and save the file.

;extension = imap 

extension = imap 

Step 4: Go to ‘php’  folder in the C:\xampp

Step 5: Go to the ext folder and locate the .dll file of the extension you want to install.

Step 6: Now copy the .dll file and paste it into the following folder:

C:\Windows\System32 

Step 7: Now restart XAMPP to see the effects.

How do I enable PHP extensions in Windows?

Here's what you do, from what I understand:.
Put the extension library folder under PHP's install path. On my computer this is C:\xampp\php\ext . Search in your PHP. ini for "extension_dir" to find what yours is..
Edit php. ini to load the extension. Find ; Dynamic Extensions ; . Add line extension=my_lib.dll..

How do I see PHP extensions?

If your server only has a single PHP version installed, you can run this PHP command anywhere, and it will give you the same list of modules. The general command we will be using is php -m. This command will give you the full list of installed PHP modules/extensions.

Where can I download PHP extensions?

The PHP Extension Community Library [PECL] is a repository for PHP Extensions, providing a directory of all known extensions and hosting facilities for downloading and development of PHP extensions.

What are PHP extensions?

A PHP extension is a specially formed library or plug-in that provides a function that can be used by many applications.

Bài mới nhất

Chủ Đề