allow_url_fopen is on, still can't fetch data - php

What can I do if I turn on the access but still get php errors?
Warning: file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in ------------- on line 40
Warning: file_get_contents(http://finance.google.co.uk/finance/info?client=ig&q=NASDAQ:MSFT) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in --------------- on line 40

try
ini_set("allow_url_fopen", 1);
if (ini_get("allow_url_fopen") == 1) {
echo "allow_url_fopen is ON";
} else {
echo "allow_url_fopen is OFF";
}
print ini_get("allow_url_fopen");
or you can try a different method
function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$return = curl_exec($ch);
curl_close ($ch);
return $return;
}
$string = curl('http://www.example.org/myfile.php');
Try to add this code to your .htaccess file:
php_value allow_url_fopen On
if using wamp php.ini are two folders C:\wamp\bin\apache\apacheVersion\bin and C:\wamp\bin\php\phpVersion so make setting allow_url_fopen=on in both files

it took me 3 days to figure it out.
Decided to post this in case you have a similar situation like me.
In my case, I am using a shared hosting setup and I was trying to install composer and then slim framework.
From CPanel I had Php 7.2 selected and phar and json enabled.
But from SSH shell when I would run composer commands it would say phar and json extensions are not installed. Moreover the php version was 5.6.
php --ini
or
php -v
then I checked all aliases on SSH to see which PHP was binded
alias
So I learnt that SSH shell PHP version has nothing to do with front-end cpanel php.
bothe are completely separate setups.
now to update my php version for shell I aliased php to php72 folder via shell command.
Then the problem was how to enable phar and json libraries. So I passed them in my command to use those libraries when executing my composer.phar scripts.
$ php -d extension=phar.so -d extension=json.so composer.phar require slim/slim:4.0.0
You can also change the default PHP for your SSH by updating the .bash_profile and define the alias in their for php as;
alias php='your php folder path'
the .bash_profile file will be in the root directory of your user folder if you FTP it. CPanel file explorer doesn't show hidden or other types of files. It only shows certain extension files.
And it finally worked and installed my slim framework.
I hope this helps those who are struggling.
Peace!
Proud Pakistani

Related

PHP SNMP Warning: SNMP::get(): No response from 127.0.0.1

I'm trying to get PHP SNMP to work on XAMPP PHP 7.1.9
I'm always getting this result: Warning: SNMP::get(): No response from 127.0.0.1
Here's what I did:
Enabled php_snmp.dll on php.ini
Installed net-snmp-5.5.0-2.x64
Added windows environment variable MIBDIRS with value C:\usr\share\snmp\mibs
Code I'm running to test:
<?php
$session = new SNMP(SNMP::VERSION_1, "127.0.0.1", "public");
$sysdescr = $session->get("sysDescr.0");
echo "$sysdescr\n";
$session->close();
I'm new to this so I'm not sure what I'm missing.
The problem was with the MIBDIRS path.
I followed php docs and it says:
The Windows distribution of Net-SNMP contains support files for SNMP in the mibs directory. This directory should added to Windows' environment variables, as MIBDIRS, with the value being the full path to the mibs directory: e.g. c:\usr\mibs.
Problem was I couldn't find c:\usr\mibs on my net-snmp installation so I used C:\usr\share\snmp\mibs instead.
Solution:
I tried using a device with snmp support instead of 127.0.0.1 and ran snmpget on cli and confirmed net-snmp installation actually works. I figured the problem must be with the path php is using to run snmp.
So I used where snmpget to check the command path then changed MIBDIRS environment value with the result which is C:\usr\bin\snmpget.exe

PHP 7 copied php_http.dll into php/ext/ not working?

NOTE:
I should add that I'm not fishing for a cURL solution. I already know and do cURL. I want to see what happens in my experiment with an http function.
I'm running PHP 7 from a XAMPP installation at:
C:xampp\php
I downloaded a Windows pecl-5.2.6-Win32.zip, which was full of .dll files, then I copied the php_http.dll file into my php\ext folder, where all the other .dlls were found.
I edited my php.ini and added the line extension=php_http.dll in the alphabetical order of all the other extensions (as if that makes any difference).
Then I restarted Apache, and tried to perform a $response = http_get($url); but get the error "Call to undefined function http_get()".
Seems like I'm doing all the steps right, but the http functions just aren't working. Also, I looked at my phpinfo() and I don't see any reference to any PECL extension.
UPDATE:
I read in another forum a similar problem, where this line was found in the Apache error.log:
C:\xampp\php\ext\php_http.dll' - The specified module could not be found.
The individual said he downgraded his php version, then repeated the steps and it worked.
Last night I downgraded from PHP 7 to PHP 5.6. I repeated the .dll copy to /ext, enabled php_http.dll in php.ini, and then got a different error:
HP Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_http.dll' - %1 is not a valid Win32 application.\r\n in Unknown on line 0
I found these Windows http extensions, again copied the .dll file, restarted Apache, but now I'm back to
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_http.dll' - The specified module could not be found.\r\n in Unknown on line 0
Instead of doing so many changes you could have simply used curl and get the same result. Reference to PECL on http_get has been removed. That version of PECL is for PHP 5.2.x . Which version of php you are using? instead you can use this function
function url_get($url)
{
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // times out after 10s
$urlcontent = curl_exec($ch);
curl_close($ch);
return($urlcontent);
}
$url = "example.com";
url_get($url);

How to load php_redis.dll when running post deployment script in Kudu Console

I have a webapp running on Azure App Service. I am trying to test a Post deployment script in Kudu Debug CMD console.
php -d extension=php_redis.dll -f postdeploy.php
Here is my postdeploy.php file
<?php
ini_set('error_reporting', -1);
ini_set("display_errors", 1);
function exception_handler($exception) {
echo "Uncaught exception: " , $exception->getMessage(), "\n";
}
set_exception_handler('exception_handler');
$redis = new Redis();
...
?>
I get the following error
Fatal error: Class 'Redis' not found in D:\home\site\deployments\tools\PostDeploymentActions\postdeploy.php on line 13
PHP Warning: PHP Startup: Unable to load dynamic library 'D:\Program Files (x86)\PHP\v5.6\ext\php_redis.dll' - The specified module could not be found.
in Unknown on line 0
I uploaded the proper version of php_redis.dll to the PostDeploymentActions folder. This is the same binary that the webapp is using via the app setting in portal PHP_EXTENSIONS = bin\php_redis.dll. However, I am not sure how to load this for this script.
Is there a way that I can load the php_redis.dll in Kudu post deployment script?
I tried php -d extension=./php_redis.dll -f postdeploy.php, php -d extension=%~dp0php_redis.dll -f postdeploy.php and other weird combinations with no luck.
Please try to add the PHP extension via ini settings, refer to https://azure.microsoft.com/en-us/documentation/articles/web-sites-php-configure/#how-to-enable-extensions-in-the-default-php-runtime at the Configure via ini settings section.
Generally:
Add an App Setting to your Web App with the key PHP_INI_SCAN_DIR and value d:\home\site\ini
Create an configuration file in d:\home\site\ini called extensions.ini
Add configuration settings to the extensions.ini file using the same
syntax you would use in a php.ini file. For example: extension =
php_redis.dll.
Restart Web Apps service.
Via this approach, you can configure the PHP extension into Kudu console site's PHP runtime. And configure via the App Settings will only configure the extension into IIS.
Any further concern, please feel free to let me know.

How to enable cURL extension on Amazon EC2 free tier

I am currently trying to enable cURL on my EC2 server (free tier).
I have installed php5_curl and I am able to run curl through php via SSH.
I am using the following file to see whether cURL has been installed correctly.
testCurl.php
<?php
function _iscurlsupported() {
if (in_array ('curl', get_loaded_extensions())) {
return true;
}
else {
return false;
}
}
if (_iscurlsupported()) {
echo "cURL is supported\n";
}
else {
echo "cURL isn't supported\n";
}
?>
The command via ssh: php testCurl.php displays that curl is supported.
The command when I access it through a brower displays that curl ISN'T supported.
I have checked the php.ini file located in php5/apache2 (the php.ini file that the browser loads (tested through another script)) and the extension is no where to be found.
I have checked the "extensions_dir" directory located on my server and the curl.so file is located there.
I am unsure why I am unable to run curl when accessing my script via the browser.
Any help would be greatly appreciated.
Cheers,
jt234
Note: If you require any more information please ask.
My problem is similar (if not the same as) Unable to use PHP curl on amazon ec2 free tier but the issue hasn't been resolved.
In the end of your php.ini file add the line:
extension=curl.so
if you want to find where it is located you can run over SSH:
$ locate curl.so
it should be in something close to: /usr/lib/php5/20090626+lfs/curl.so

PHP Extension (memcache|memcached) not showing in phpinfo() but showing in php -m and php -i?

I am getting both modules listed as installed / configured when I use:
php -m
or if I use:
php -i
but when I use:
$m = new Memcache;
// or
$m = new Memcache();
// or
$m = new Memcached();
//or
$m = new Memcached;
I get the following error:
Fatal error: Class 'Memcached' not found
I am running on a Mac - OS X (10.5.7) with default install of apache & php. Additionally, I have memcached running as a daemon on 127.0.0.1:11211 and libmemcache as required by the php-memcached library. I have restarted apache tons of times and even done a machine restart.
Does anyone know why the modules/extensions show up in the command line but not in my phpinfo()? I am literally stumped, after 3 hours of googling, I am just about ready to give up.
Also, please note, my phpinfo() outputs my ini files as follows AND they are both the exact same file:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /private/etc/php.ini
UPDATE:
Apache is failing to load the extension.
[Fri May 14 04:22:26 2010] [warn]
Init: Session Cache is not configured
[hint: SSLSessionCache] PHP Warning:
PHP Startup: Unable to load dynamic
library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcached.so'
- (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load
dynamic library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcache.so'
- (null) in Unknown on line 0
Does anyone know why or how this would happen? Both of the files referenced above DEFINITELY ARE there. Should I move this question to server fault?
Your webserver is probably using mod_php, which is a seperate bit of code from the standalone (CLI) interpreter. If they are both using the same ini file, and the memcache extension is configured in the ini file, then it sounds like for some reason, the mod_php is failing to load the extension - check your webserver error_log for startup errors.
It may be that the mod_php was compiled without memcache support (most extensions need to have a stub file linked into the php code, even though the bulk of the code is not linked until run time). Or it may be a permissions problem on the shared object file. Or your webserver may be running chroot, and unable to find the extension (which would also mean that although the ini files appear to have the same path, this is relative to different roots).
HTH
C.
because both versions use different php.ini
place your php.ini into location noted in the phpinfo() outout
I would suspect that the issue revolves around permissions. When you run php from comand line, it runs as the user invoking it. When run as an apache module, it runs as "nobody".
I would assume that the memcached.so file, or the directory it's in does not have proper permissions.
I stumpled upon this post and was having the exact same problem with an extension in my php -i but not in phpinfo(). Mine was a permissions problem because of selinux on a CentOS machine. I had to change ownership and permissions and now it is working as expected.
Set php path in environment variables as given below.
Right-click on "My Computer"
Properties
Advanced Tab > Environment Variables
Under System variables, scroll down to find "Path", select and click on Edit.
Add path to your php install on the end (make sure to precede with semi-colon ";"). Example: ";C:\php7"
Click Ok.

Categories