Skip to content

Instantly share code, notes, and snippets.

@Amar-Chaudhari
Last active May 26, 2023 15:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Amar-Chaudhari/d0c9f08d0b9d9d17528fe9805fc6cef3 to your computer and use it in GitHub Desktop.
Save Amar-Chaudhari/d0c9f08d0b9d9d17528fe9805fc6cef3 to your computer and use it in GitHub Desktop.
How To Compile And Install PHP Extensions From Source

If you have already compiled and installed PHP and need to install more extension, I will show you a quick-n-dirty way of installing and compiling your desired extension without re-compiling everything

Download & unzip the PHP5 source code

cd /tmp
wget -O php-5.6.22.tar.gz http://pl1.php.net/get/php-5.6.22.tar.gz/from/this/mirror
tar -zxvf php-5.6.22.tar.gz
cd php-5.6.22

Prepare the extension (phpize)

I will install Imap extension in this example :

cd /tmp/php-5.6.22/ext/imap/
phpize

### if you get autoconf error :
yum install autoconf

./configure --with-libdir=lib64 --with-kerberos --with-imap-ssl
make

Move the extension

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

Copy the extension to that directory.

cp /tmp/php-5.6.22/ext/imap/modules/imap.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

Activate extension in php.ini

# find your .ini file
$ php --ini

# Add to file
extension=imap.so

Restart your php

# In case of Apache
$ /etc/init.d/httpd restart
$ /etc/init.d/apache2 restart

# php-fpm:
$ /etc/init.d/php-fpm restart
@catsAND
Copy link

catsAND commented Nov 30, 2022

Like (y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment