Home » Php » Installing PHP extensions on shared hosting

Installing PHP extensions on shared hosting

Posted by: admin July 12, 2020 Leave a comment

Questions:

I need to enable the mcrypt functions on my website, except I’m on a shared host (running linux) and obviously don’t have access to the php.ini file. There does seem to be options for installing PEAR modules but a search told me mcrypt wasn’t available. Is there any way I can do this, short of begging technical support to help me?


Update: Looking around a bit more, it looks like I might be able to use the dl() function to dynamically load a library at run time. Since I’m only using the mcrypt functions in one spot, I could probably get away with doing this since the performance hit (I assume there is a hit) should be minimal. The only problem now is how to get the libmcrypt.so file?


Another update: I’ve downloaded the libmcrypt.tar.bz2 file from Sourceforge and run ./configure, make, and then copied the libmcrypt.so.4.4.8 file into my home directory (as libmcrypt.so), but now I can’t find where to put it so that the dl() function will find it.

How to&Answers:

The MCrypt Sourceforge page should have it
http://mcrypt.sourceforge.net/
To compile it just:

wget http://superb-east.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz
tar -xzvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
sudo make install

EDIT:
Can you reference it with a direct path?
What have you tried?

Edit2: It seems that you can only load moduals from the extensions directory set in the php.ini and you cannot override extensions_dir with ini_set so you will either have to convince your host to install it or if they allow you to have your own php.ini (many do usually in [username]/php.ini) then you could set the extensions_dir in there and load the modual with that.

Answer:

Really the best way is to tell your ISP to include mcrypt support. Even if you bundle your own PHP extension and load it with dl(), there is no guarantee it is going to work after a PHP upgrade, as PHP is sometimes very version-number picky.

Answer:

dl() will not help you either, since it only loads libraries from certain paths, and those paths are usually only writable by the system administrators for security reasons.

I very much doubt that there is a way to use binary libraries without the consent of the hoster.

Answer:

PHP in versions before 5.2.5 allowed you to use a path in the dl() function so that you could easily load libraries in a shared environment.

This changed for ‘security’ reasons with 5.2.5 and as far as I am aware your only option is to get your system administrator to add the module to the extensions_dir.

This issue is described at bugs.PHP.net