I have this PHP code running in two different environments: an on-prem server running PHP 5.6 and an EC2 instance running PHP 7.2.
$filepath = 's3://'.$this->s3Bucket.'/'.$key;
$this->s3Client->registerStreamWrapper();
echo "file exists ".file_exists($filepath);
The file functions (e.g., file_exists and readfile) don't appear to work the same way in both environments. In the on-prem server, they work as expected: that is, file_exists returns true for known file, as expected. But on the EC2 instance, file_exists returns false.
The $filepath var looks like s3://my-bucket/a-prefix/another-prefix/LlPIpMvDdmX6i38.pdf. The S3 client and stream wrapper all appear to be correct with var_dump. The only thing I can find is that the PHP file functions simply don't work as expected.
I also tried this line in the EC2 instance:
filesize($filepath);
And go this warning: filesize(): stat failed for s3://...LlPIpMvDdmX6i38.pdf
Is there something I missing in the EC2 set-up that is preventing Streamwrapper from working?
I finally found the error in the error logs with the help of a colleague.
PHP Warning: readfile(): s3:// wrapper is disabled in the server configuration by allow_url_fopen=0
Setting allow_url_fopen=1 fixed the problem.
Related
i AM USING A aws lightsail instance with a Bitnami Apache2 Lampstack setup on it.
My issue is I am unable to get php curl enabled. I seem to have a bunch of php.ini files all over the server in diffiferent locations. So I edited all of them removing the ; from the line that read extension=curl. I then restarted the instance. However my php file is still giving me the error saying
caught Exception: Shippo needs the CURL PHP extension.
When I run a phpinfo() I see my path to the ini file is /etc/php/8.0/apache2/php.ini
However when I do a which php command I am giving a path like this /opt/bitnami/php/bin/php
when I do a php -v I am also seeing it say PHP 7.4.27 so my php info file seems to say I am using php7.8 and my CLI feels i am using php7.4 which could be part of my issue.
Any suggestions on how to fix this? my other issue is I am having a hard time getting to the path /etc/php/8.0/apache2/php.ini I simply can not find a folder with 8.0 in it
Why ftp_connect () fails for networksolution hosting using PHP? and produce following error as:
500: Internal server error This error is generated when a script
running on the server could not be implemented or permissions are
incorrectly assigned for files or directories
Troubleshooting suggestions:
Temporarily disable any rewrite rules by renaming your .htaccess file
if it exists.
Ensure that any CGI or Perl scripts have at least .755. permissions.
If trying to run PHP and you get this error, you may have an invalid
php.ini in your /cgi-bin, or may be missing your php.dat file in this
folder.
The error 500 indicates a fatal error in the PHP code.
The only reason I can imagine, why the ftp_connect can fail fatally, is that the function actually does not exist. Meaning, your PHP installation was built without an FTP support.
See https://www.php.net/manual/en/ftp.installation.php
What does function_exists("ftp_connect") return?
When I try to use the sample code:
$fp = fopen("gs://my_bucket/some_file.txt", "w");
fwrite($fp, "Hello");
fclose($fp);
I get this error:
Warning: fopen(): Unable to find the wrapper "gs" - did you forget to enable it when you configured PHP?
UPDATE
Switching to running the app server from the command line made the original error go away but I now get this error:
'google\appengine\runtime\RPCFailedError' with message 'Remote implementation for urlfetch.Fetch failed'
Does anyone know how I can resolve it?
Where are you seeing this error? On the production server, testing locally using our SDK or are you not using the SDK?
We install this handler as part of our setup script, so you need to be running in the dev appserver if your testing locally.
You have to use dev_appserver.py (from GAE PHP SDK) to check your code locally. Do not run it through your local webserver, since it will not provide additional plugins (for example gs: stream support) and won't emulate "whole" GAE environment (Datastore, Memcache, Tasks etc.).
On Debian following should work:
sudo apt-get install php5-cgi
/path/to/google_appengine/dev_appserver.py --php_executable_path=/usr/bin/php-cgi .
assuming that:
you have downloaded and installed GAE PHP SDK
you're in your GAE test application directory
You will have to enter localhost website on port 8080 to check if you have your app working. On localhost port 8000 you have admin server in which you can check data in your local Datastore.
After that you can place phpinfo() in your .php file to check if you have 'gs' supported in "Registered PHP Streams" row.
Using "file_put_contents" instead of "fopen" fixed the problem for me.
Thanks
As the error suggests, the wrapper i.e. 'gs' is undefined.
Their are some build-in wrappers by php that can be used in fopen php function; for the custom wrappers i.e. 'gs' in your case, stream_wrapper_register php function can be used.
Reference links:
http://www.php.net/manual/en/wrappers.php
http://www.php.net/manual/en/function.stream-wrapper-register.php
I am currently moving my web app to amazon ec2. Since it's only for testing, I use the free version called ec2 free tier with windows server 2008 instance. However, Although I have done all I know and read this thread ( How to enable cURL in PHP / XAMPP ). I just couldn't use curl on my php script. it always creates the error
Call to undefined function curl_init() in C:\xampp\htdocs\index.php on line 2
Here are all thing I have tried
Install Wamp ( I tried it on XAMPP to)
Uncomment out php_curl in php.ini file ( and restart apache)
Copy two dll files to both system32 and syswow64
Could it have to do with the fact that I am using free vps?
Update:
Also, when I started the apache server in XAMPP , this error appeared
'PHP Startup: unable to load dynamic library curl.dll'
However, I have double checked the ext directory and the php_curl.dll was in there.
i think curl need to access remote sever from our web server. so i opened all traffic in my server outbound rule and it works. i think this is not good solution. still look for better way.
nope.
be sure, that you have the files in the right place, usually its in the plugins folder for php! maybe you cann add a absolute path to your php.ini!
be sure, you edit the correct ini file!
php completly independent to your operatingsystem!
just be sure to doublecheck everything. because its not saying, it has trouble loading your extention, its just saying, the function your trying to call, is not there. so i assume your extention ist not loading at all! :)
One reason I did notice for this cURL plugin to malfunction was the availability of copies of libeay32.dll and ssleay32.dll files. Please check whether your system32 folder has such copies and if so, please rename them to some other names and copy the ones found with the php installation. Sometimes you may need to restart your machine. This was documented here some time ago.
I had a similar problem, but it occours just with requests under https. I tried to create a curl request directly from the ec2 machine and got a error: "curl: (77) error setting certificate verify locations".
It looks like some kind of ssl validation fail because of a certificate not found. So I used a parameter -k (or --insicure) in my curl command, to ignore this validation and after that my curls request did directly from ec2 machine worked.
So I tried to apply a similar ideia in my curl command in php, (I suppoused that the curl php extension forward this requests to the operation system) and I found this curl opt:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
After that it works to me.
Probably this isn't the best way to solve the problem, but solved my problem temporarelly.
I am currently using an image manipulation script to do some work on uploaded images and I'm running into a problem in my dev environment. This same code works on my production server.
The error is:
PHP Warning: imagecreatefromjpeg(): php_network_getaddresses:
getaddrinfo failed: Name or service not known in /path/to/script.php
on line 75
The line of code on 75 is:
$this->img = imagecreatefromjpeg(PHPTHUMB."?src=/".$this->image_path);
which creates an image that is loaded from another made by phpThumb, which is used for further manipulation.
Any ideas on how to solve this? Can anyone shed some light on what the error means?
Thank you,
Edit:
Just as a further bit of insight, if i visit PHPTHUMB . "?src=/" . $this->image_path in my browser, the image loads fine
User agent in php.ini did not solve the problem as indicated here
EDIT (SOLUTION): I had to add the INTERNAL 192.168.204.XXX IP into the hosts file, so that http://dev.mysite.com resolved correctly. Trying both 127.0.0.1 and the external IP yielded no result, but the internal works perfectly. Thanks for everyone's efforts,
I'm totally not sure about the cause of that error, but this is my best guess.
There is a particular PHP Setting which enables you to treat URLs as files. Normally imagecreatefromjpeg accepts a filename, I think. Since you are passing a URL, you need to make sure the particular setting is enabled. I believe you can find more info about it here: http://us2.php.net/file
filename
Path to the file.
Tip
A URL can be used as a filename with this function if the fopen
wrappers have been enabled. See
fopen() for more details on how to
specify the filename and List of
Supported Protocols/Wrappers for a
list of supported URL protocols.
Fopen wrappers: http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
Your dev environment may not be setup with this, but your production environment could be.
Edit
This page lists your error:
http://bugs.php.net/bug.php?id=11058
and mentions that a possible fix is by modifying your hosts file to explicitly include the ip/dns of the server you're accessing.
i tryed to reconfigure my named
configuration, without any result, to
fix this. the problem was solved by
adding the following line to my
/etc/hosts:
194.97.55.147 mx.freenet.de
Maybe you can try this?
did you also check that allow_url_fopen is set to On in php.ini?
I saw that they did mention that in the article you referred to in your post.
EDIT: Also, what OS and what PHP version are you running?
Just read this on php.net: "On Windows versions prior to PHP 4.3.0, the following functions do not support remote file accessing: include(), include_once(), require(), require_once() and the imagecreatefromXXX functions in the GD Functions extension."
EDIT2:
I just read what was written in the comments, your allow_url_fopen is set to On, sorry about that.
But OS, PHP version and phpinfo() would help in finding the problem.
The error message suggests something is wrong at a networking level. Thus, if possible, bypass that. Try using the path to the thumbnail generator, instead of a network address.
If that's not an option, try something that will give you more granular error messages. I suggest CURL. At the very least, it should yield a more informative error message.
The simple fact that this is failing is because on your webserver, your DNS resolution is broken.
If you have SSH access to your server, try the following command
dig hostname
where hostname is the host name from PHPTHUMB
This will probably fail.
Assuming that you're using Linux, my suggestion would be to edit your /etc/resolv.conf (as root)
and add the following line before any other lines beginning with "nameserver"
nameserver 4.2.2.2
This should hopefully fix things, though you may have to restart apache (or whatever webserver you're using)!
The issue here is that php fails to resolve the url that you provide as PHPTHUMB as stated in this bug report on php.net. This possibly means that it's the fault of the operating system/web server, in which case you can enter the ip address of the server you are connecting to into your hosts file manually.