PHP extension works from browser not from CMD - php

I'm still struggling integrate APC with EasyPHP for testing Doctrine + CI.
Installed APC
configured php.ini
see it in phpinfo()
Added this to my php.ini :
[APC]
apc.shm_segments=1
apc.optimization=0
apc.shm_size=128
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.enable_cli=1
created a test file test.php :
<?php
print_r(apc_sma_info());
?>
accessing with browser (getting result on screen) :
Array ( [num_seg] => 1 [seg_size] => 33554368 [avail_mem] => 33237360 [block_lists] => Array ( [0] => Array ( [0] => Array ( [size] => 33237336 [offset] => 317048 ) ) ) )
running from command prompt : D:\devl\EasyPHP-5.3.5.0\www>php test.php
Fatal error: Call to undefined function apc_sma_info() in D:\devl\EasyPHP-5.3.5.
0\www\test.php on line 2
any ideas why?

I do not know EasyPHP - but there are often different php.ini files for Apache and Cli...
Please check this first for your WAMP stack.

apache and CLI may have different php.ini files, so check which is the loaded php.ini in the cli environment.

Related

How to set custom php.ini location in lighttpd?

By default my php.ini is located at /etc/php.ini and I want to move it to /tmp/ab/etc/php.ini. In /etc/lighttpd/lighttpd.conf I've tried to set the following configuration:
#### CGI module
cgi.assign = ( ".pl" => "/usr/bin/perl", ".cgi" => "/usr/bin/perl", ".py" => "/usr/bin/python", "cgi-bin/luci" => "", ".php" => "/usr/bin/php-cgi -c /tmp/ab/etc/php.ini", "sms_gateway" => "/bin/bash", "cgi-bin/check" => "/bin/sh", "cgi-bin/remove" => "/bin/sh", "cgi-bin/date" => "/bin/sh" )
Please take a look at this part: ".php" => "/usr/bin/php-cgi -c /tmp/ab/etc/php.ini"
But after I do that and restart lighttpd and I try to check the location of php.ini with:
<?php
phpinfo();
?>
I get 500 - Internal Server Error on my browser. How can I do this ?
One solution is to create a wrapper script /tmp/ab/bin/my-php-cgi and put that in lighttpd.conf cgi.assign = ( ".php" => "/tmp/ab/bin/my-php-cgi" )
#!/bin/sh
exec /usr/bin/php-cgi -c /tmp/ab/etc/php.ini
Depending on the PHP version you are using you might also look into having lighttpd.conf setenv.add-environment = ( "PHPRC" => "/tmp/ab/etc/php.ini" ) See also How to change the path to php.ini in PHP CLI version

php windows server 2012 how to show loaded extension

On mac os, i would do this:
php -r "print_r(get_loaded_extensions());"
on the terminal to get the loaded extensions
but in windows server 2012, i am getting error that php is not recognised
what should i do to get the loaded extension on windows server 2012?
i am on xampp
Create a file in htdocs folder with this content, then access it by browser
<?php
echo '<pre>';
print_r(get_loaded_extensions());
or
<?php
phpinfo();
Output:
Array
(
[0] => Core
[1] => bcmath
[2] => calendar
[3] => ctype
[4] => date
[5] => ereg
[6] => filter
[7] => ftp
[8] => hash
[9] => iconv
[10] => json
[11] => mcrypt
[12] => SPL
...
)
Accessing by command line
At keyboard press winkey + break/pause, go on advanced settings, then create a new environment variable with name PHP_HOME value must be the php path, after this edit the variable path, put the cursor at end and add ;%PHP_HOME%; confirm all operations, open a new cmd, try php -v
The procedure is exactly the same in all supported platforms. You are probably getting this error message:
'php' is not recognized as an internal or external command, operable
program or batch file.
This is not related to PHP. You get this message whenever you type a command that doesn't exist or cannot be found.
You can either:
Add the PHP directory to PATH environment variable (just like in Unix and —I guess— MacOS)
Switch to PHP directory first:
cd "C:\Path\To\PHP"
php -r "print_r(get_loaded_extensions());"
Type the full path:
"C:\Path\To\PHP\php" -r "print_r(get_loaded_extensions());"

Array ( [0] => 'java' is not recognized as an internal or external command, [1] => operable program or batch file. )

I am having trouble executing my jar file from my xampp virtual server. I am running xampp v3.2.1 and the jar works fine on the cmd line on my desktop, however not on the xampp server.
The output of my
exec(cmd, output)
is
Array ( [0] => 'java' is not recognized as an internal or external command, [1] => operable program or batch file. )
So I read into the xampp and it has tomcat installed but I still can't work out how to run the jar. Anyone have an idea? Thanks!
EDIT: So I found this https://community.apachefriends.org/f/viewtopic.php?p=129309 however there is no php.ini file in here, maybe it has changed with newer versions

APC for wampserver 2.4

After 3 hours of searches and differents failed tries, I'm asking help here .. .:(
My configuration:
PHP 5.4.12
Compiler MSVC9
OS: W7 Home premium edition service pack 1
Architecture: x64
Apache: 2.4.4
I've tried many php_apc.dll without success. Is someone found the right one to use or any good alternative to APC?
PHP APC extension for PHP 5.3x to PHP 5.4 and PHP APCu extension for PHP 5.5x
APC installation:
Step 1:
Download APC dll file for PHP 5.3x to 5.4
Step 2:
Extract zip and rename with php_apc.dll
Step 3:
Copy and paste in YOUR_DIR:\wamp\bin\php\php_YOUR_PHP_VER_5.3x_OR_5.4\ext
Step 4:
Enable apc from php.ini
Open php.ini file
YOUR_DIR:\wamp\bin\apache\apache_YOUR_APACHE_VER\bin\php.ini
extension=php_apc.dll
Put above line in php.ini file
OR (Base on your configuration)
YOUR_DIR:\wamp\bin\php\php_YOUR_PHP_VER_5.3x_OR_5.4\php.ini
extension=php_apc.dll
Put above line in php.ini file
Step 5:
Restart Apache
APCu installation for PHP 5.5x:
Step 1:
Download APCu dll file for PHP 5.5x
Step 2:
Extract zip and rename with php_apcu.dll
Step 3:
Copy and paste in YOUR_DIR:\wamp\bin\php\php_YOUR_PHP_VER_5.5x\ext
Step 4:
Enable apc from php.ini
Open php.ini file
YOUR_DIR:\wamp\bin\apache\apache_YOUR_APACHE_VER\bin\php.ini
extension=php_apcu.dll
Put above line in php.ini file
OR (Base on your configuration)
YOUR_DIR:\wamp\bin\php\php_YOUR_PHP_VER_5.5x\php.ini
extension=php_apcu.dll
Put above line in php.ini file
Step 5:
Restart Apache
Installing APC seems fairly simple. I just did it in 10 minutes.
This assumes you are using a 32bit WAMP even on a 64bit Windows. It seems rather hard to find a precompiled 64bit version of APC so if you are using the 64bit WAMP maybe installing the 32bit WAMP would be a good idea.
My Environment is WAMPServer 2.4
The version of PHP I tested this with was 5.3.22 which was running under Apache 2.2.26
I got the dll's from HERE
and selected php_apc-3.1.10-5.3-vc9-x86.zip for my PHP5.3 Versions
and selected php_apc-3.1.10-5.4-vc9-x86.zip for my PHP5.4 Versions
These are compiled with VC9 (msvc 2008) and match the compiler used to create PHP and APACHE
Extract the zips somewhere and then copy the php_apc.dll from the ts (thread safe) folder into your php/ext folder
Edit your php.ini ( using the wampmanager menu links so you get the correct file ) and add this line to the existing section of extension parameters.
extension=php_apc.dll
While in the php.ini add these parameters for apc at the bottom of the ini file
[apc]
; default memory allocation = 32M
apc.shm_size = "32M"
; for dev check for changed code every time so set to "1". "0" for LIVE site.
apc.stat = "1"
This is not actually changing anything as these are actually the defaults, but its a useful place holder for when you decide you want to start fiddling with APC's parameters.
Now to test that the new extension has been loaded, restart apache again using the wampmanager menu, then launch localhost from the menu and click the phpinfo ilnk on the homepage. APC should be the first extension shown in the list of loaded extensions.
Now create a little script to verify apc is working and place it in the \wamp\www folder
filename = test_apc.php
<?php echo '<pre>' . print_r(apc_sma_info(),TRUE) . '</pre>'; ?>
Now run the script from your browser:
http://localhost/test_apc.php
You should see something like this reported:
Array
(
[num_seg] => 1
[seg_size] => 33554368
[avail_mem] => 7396512
[block_lists] => Array
(
[0] => Array
(
[0] => Array
(
[size] => 608
[offset] => 25985176
)
[1] => Array
(
[size] => 6696
[offset] => 26108536
)
[2] => Array
(
[size] => 11912
[offset] => 26116296
)
[3] => Array
(
[size] => 552
[offset] => 26011544
)
)
)
)

php custom C++ module works from command line, not on webserver

I made a custom PHP module with C++ and Swig. It works from the command line, but not with my webserver:
php index.php
php-cgi index.php
Both of those work fine.
I'm using lighttpd and php. I didn't configure these in any special way. I just installed them using sudo apt-get install.
Unfortunately if I make a webpage I get this:
Fatal error: Call to undefined function minikey_to_wif() in /var/www/index.php on line 6
Calling function_exists("minikey_to_wif") returns False too.
The phpinfo() does not show my module called minikey, and shows the same configuration path as the file I edited (/etc/php5/cgi/php.ini):
extension=/path/to/php-ext/minikey/minikey.so
I also tried copying it to where the other PHP extensions seem to be installed (/usr/lib/php5/20090626+lfs/) but that didn't work either.
I've been stopping, and starting lighttpd countless times. Each time, when I run ps aux | grep php, there are no results. I've also rebooted a few times to no effect. I have no idea what's up.
OK found the answer.
The extension relied on a library which was installed in a non-standard location. Normally I set LD_LIBRARY_PATH in ~/.bashrc. But when the web server ran the extension, it didn't have that environment variable.
Fix was to create a file in /etc/ld.so.conf.d/genjix.conf with /home/genjix/usr/lib and run ldconfig as root.
Try running phpinfo() using lighty. Make sure that its pointing to the correct php.ini.
If you think this is the problem you can launch php using the -c switch from inside lighttpd.conf with "bin-path" => "/path/to/php-cgi -c /path/to/php.ini":
e.g.
fastcgi.server = (
".php" => (
(
"bin-path" => "/path/to/php-cgi -c /path/to/php.ini",
"socket" => "/tmp/php.socket",
"max-procs" => 4,
"idle-timeout" => 30,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "1000"
)
)
)
)

Categories