2

I have two php.ini files -

  • /etc/php.ini which loads in case of cli
  • /opt/lampp/etc/php.ini which loads in case of browser.

I am able to use PHP's Mailparse extension after adding the line extension=mailparse.so in the /opt/lampp/etc/php.ini and restarting lampp.

But I am not able to load the same in case of command line -

getting PHP Fatal error: Call to undefined function mailparse_msg_create() in ...

mailparse_msg_create() is a part of the Mailparse extension.

I tried by relogging with the user after making the change and even restarting the system. What needs to be done so that the change takes effect.

Update

I checked that php -i | grep 'Configuration File' gives

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/mailparse.so' - /usr/lib/php/modules/mailparse.so: cannot open shared object file: No such file or directory in Unknown on line 0
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini

Update 2
I copied the mailparse.so from /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626 and put it in /usr/lib/php/modules. I added extension=mailparse.so to /etc/php.ini as well. But it still showed this warning

PHP Warning:  PHP Startup: Unable to load dynamic library ...  

As told by Lekensteyn, I did

ldd /usr/lib/php/modules/mailparse.so

and got

ldd: warning: you do not have execution permission for /usr/lib/php/modules/mailparse.so'

So I gave execute permission. Then

ldd /usr/lib/php/modules/mailparse.so

showed

linux-gate.so.1 => (0x00110000) libc.so.6 => /lib/libc.so.6 (0x0011d000) /lib/ld-linux.so.2 (0x003aa000)

which looks normal. BUt now, running php command says

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/mailparse.so' - /usr/lib/php/modules/mailparse.so: undefined symbol: mbfl_name2no_encoding in Unknown on line 0
Sandeepan Nath
  • 617
  • 6
  • 13
  • 27
  • Is there a reason why you want to use LAMPP instead of PHP, presumably installed from packages? – Lekensteyn Jan 31 '11 at 13:08
  • @Lenkensteyn: I am not sure about that :) As far as I remember I had some problems using PHP without LAMPP earlier. I am not even sure if PHP as such needs to be installed so that LAMPP can work or LAMPP does everything. I know these are very stupid questions but I want to clear my doubts. I did not get sites like serverfault two years back when I started all these and these doubts were never cleared. I always feel weak in these things although I am a very confident programmer now :). Thanks – Sandeepan Nath Jan 31 '11 at 13:14
  • What distro are you running? LAMPP is an all-in-one package, made to be compatible with many systems (and therefore not optimised / easily extensible compared to distribution packages). – Lekensteyn Jan 31 '11 at 13:19
  • Fedora 7. Did you mean that? – Sandeepan Nath Jan 31 '11 at 13:21

2 Answers2

1

Have you installed the extension to where your command line version of PHP expects it to be?

Check extension_dir in your /etc/php.ini to see where it expects to find extensions and install the extension there or point it at your lampp PHP extensions directory (assuming it is a compatible version of PHP).

James Yale
  • 5,042
  • 1
  • 16
  • 20
  • @James Yale: yes that was the reason. The `extension_dir` in `/etc/php.ini` was different. But, my problem is not fixed yet. How do I install the extension there? Here I have a very basic or probably stupid question. Are there two installations of PHP in my system. I remember I installed mailparse using `pecl install mailparse`. Then how did it affect only the browser PHP and not cli PHP. Also, is "browser PHP" the correct term to use? – Sandeepan Nath Jan 31 '11 at 13:05
  • There are almost certainly two installations of PHP on the system. The quickest solution to your problem might be to use the command line version of PHP included with lampp - believe it should be in `/opt/lampp/bin` rather than the other version, then it will use the correct php.ini and associated extensions. – James Yale Jan 31 '11 at 13:10
  • @James Yale - yes there is a command line executable inside `/opt/lampp/bin`. If I go to that location and run `./php` I am able to run that one. But running `php` only runs the other php. So should I get rid of the other PHP? I am using the Lampp installation for everything. How do I make the lampp's cli as default (run it when I execute `php` from anywhere - without having to do `./path/to/php`). – Sandeepan Nath Jan 31 '11 at 13:21
  • You can remove the other installed version of php using your distribution's package manager, eg: `apt-get remove php-cli` (Debian/Ubuntu) or `yum remove php-cli` (RHEL/CentOS). To make the lampp version of php run from anywhere, add it to your path: `PATH=$PATH:/opt/lampp/bin` – James Yale Jan 31 '11 at 14:50
  • I tried `yum remove php-cli` but it failed - gave many `Not Found - Trying other mirror` and then `Error: Cannot retrieve repository metadata (repomd.xml) for repository: livna. Please verify its path and try again...`. Also, I already have `PATH=$PATH:/opt/lampp/bin` in my `/root/.bash_profile` file. I am logged in as root. Still showing the warning. – Sandeepan Nath Feb 01 '11 at 06:40
  • Try `rpm -e php-cli` – James Yale Feb 01 '11 at 09:06
  • @James Yale- Finally worked. `rpm -e php-cli` gave `error: Failed dependencies: php-cli = 5.2.6-2.fc7 is needed by (installed) php-5.2.6-2.fc7.i386`. So, I did `rpm -e php` first and then `rpm -e php-cli` and it worked. Now running `php` command works perfect. Thanks a lot – Sandeepan Nath Feb 02 '11 at 07:03
1

Both php.ini's contains a different extension_dir setting, /etc/php.ini seems to set it to /usr/lib/php/modules and LAMPP sets it to /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626.

To make Mailparse work for LAMPP, you need to copy mailparse.so to /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626 and add extension=mailparse.so to /opt/lampp/etc/php.ini as well. As PHP loads the php.ini file each time run, there is no need to restart your computer.

Lekensteyn
  • 6,111
  • 6
  • 37
  • 55
  • Actually Mailparse is working for LAMPP in my case and not with the other installation of PHP (used by cli). So, I copied the `mailparse.so` from `/opt/lampp/lib/php/extensions/no-debug-non-zts-20090626` and put it in `/usr/lib/php/modules`. I added `extension=mailparse.so` to `/etc/php.ini` as well. But still showing the warning. – Sandeepan Nath Jan 31 '11 at 13:35
  • It looks like mailparse.so has additional dependencies. Can you post the output of `ldd /usr/lib/php/modules/mailparse.so`? If it's a long list, consider putting it in your answer or on http://pastebin.com/ – Lekensteyn Jan 31 '11 at 13:42
  • Ok looks like there was a permission issue. It showed `ldd: warning: you do not have execution permission for `/usr/lib/php/modules/mailparse.so'`. So I gave execute permission. Then `ldd /usr/lib/php/modules/mailparse.so` showed `linux-gate.so.1 => (0x00110000) libc.so.6 => /lib/libc.so.6 (0x0011d000) /lib/ld-linux.so.2 (0x003aa000)` which looks normal. BUt now, running `php` command says `PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/mailparse.so' - /usr/lib/php/modules/mailparse.so: undefined symbol: mbfl_name2no_encoding in Unknown on line 0` – Sandeepan Nath Jan 31 '11 at 14:02
  • Added the same to update 2 section in question. – Sandeepan Nath Jan 31 '11 at 14:23
  • Have you installed the mbstring extension? (it should.) – Lekensteyn Jan 31 '11 at 14:26
  • @Lenkensteyn - the problem is solved. check comments to James Yale's answer – Sandeepan Nath Feb 02 '11 at 07:06