3

Hi im trying to execute php file from bash script

#!/bin/sh

php ./func.php

and func.php file looks like

<?php

echo "php file";

And as output PHP Warning: Module 'apc' already loaded in Unknown on line 0

EDIT: And maybe U can also tell me how to pass parameter to php file ??

kskaradzinski
  • 4,954
  • 10
  • 48
  • 70
  • 2
    Have you tried checking the cli configuration file (on a Ubuntu system it would e.g. be located in `/etc/php5/cli/php.ini`) for references to module `apc`? And is this your complete `func.php` file? Looks incomplete to me (at least closing `?>` is missing) – codeling Jan 02 '12 at 11:51
  • 3
    @nyarlathotep Leaving out the closing `?>` [is a best practice](http://stackoverflow.com/a/4453835/35070). – phihag Jan 02 '12 at 11:52
  • @phihag: thanks for the hint! been writing php code for a long time but didn't know that - seems I should read up on best practices :) – codeling Jan 02 '12 at 11:54
  • I thought that `?>` its not so important as it is in PHP. Thanks – kskaradzinski Jan 02 '12 at 11:55
  • 1
    @skowron-line Please ask a second question on how to get parameters. That way, this question remains uncluttered, and future seekers will have an easier time reading questions and answers. – phihag Jan 02 '12 at 12:11
  • unrelated to your error but you must use `#!/bin/bash` if you really want bash, otherwise your script will run in compatibility mode (POSIX) – Samus_ Jan 02 '12 at 21:35

5 Answers5

8

An error in Unknown on line 0 means that your configuration is defective (this has nothing to do with bash - directly running the program should yield the same message).

In your case, you have two instances of extension=apc.so in your php configuration. Use grep apc.so /etc/php5/cli/ -r to find these.

phihag
  • 278,196
  • 72
  • 453
  • 469
  • Thanks +1 ! Do you have any idea where this duplicate line comes from ? I also had an ...active=1 line duplicated in the ini file. – Benj Jan 22 '13 at 11:06
3

This error is related to your PHP configuration, not to your code.

This can be fixed in your php.ini, check this thread: http://blog.ciuly.com/my-server/php-warning-module-apc-already-loaded-in-unknown-on-line-0/.

jjmontes
  • 24,679
  • 4
  • 39
  • 51
2

Find out which php.ini is being used in CLI mode:

php --info

and check the content of that php.ini for a double declaration of extension=apc.so

konsolenfreddy
  • 9,551
  • 1
  • 25
  • 36
1

All of the answers above hinted at what was going on, but it was the fact that there was a separate apc file that was being loaded, so simply grepping for "extension=apc.so" didn't uncover the issue.

php --info | grep -i apc
PHP Warning:  Module 'apc' already loaded in Unknown on line 0
Additional .ini files parsed => /etc/php5/cli/conf.d/apc.ini

So since the module was being loaded, you just simply need to remove the "extension=apc.so" from both your apache and cli php.ini configs.

jsuggs
  • 2,632
  • 3
  • 19
  • 17
0

In my case (on Ubuntu, a Debian based Linux variant), I had two copies of apc.ini in /etc/php5/conf.d/. I had one that I had put there when I first installed apc. I also found a symlink from /etc/php5/conf.d/20-apc.ini to ../mods-available/apc.ini.

It appears that some upgrade of php, enabled this module the "Debian way" (with a symlink). I deleted my copy of apc.ini and I am now just using the one that is symlinked to mods-available.

Digging further, there are command line programs that should be used to enable and disable PHP modules under Ubuntu and Debian. Here are the commands to enable and disable APC:

sudo /usr/sbin/php5enmod apc # Creates the symlink in /etc/php5/conf.d that enables APC
sudo /usr/sbin/php5dismod apc # Deletes the symlink in /etc/php5/conf.d that disables APC
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109