Warning: `exec()` has been disabled for security reasons [duplicate] - php

This question already has answers here:
Warning: exec() has been disabled for security reasons
(2 answers)
Closed 9 years ago.
I upload a gif to my website. When is upload complete, i can see this error:
Warning: exec() has been disabled for security reasons in /data/web/virtuals/28995/virtual/www/include/functions/main.php on line 306
Fatal error: Call to undefined function execute() in /data/web/virtuals/28995/virtual/www/include/functions/main.php on line 309
And this is part from main.php
$owh = $width_old."x".$height_old;
$nwh = $final_width."x".$final_height;
if(!file_exists($temppic))
{
$runinbg = "convert ".$file." -coalesce ".$temppic;
$runconvert = execute("$runinbg");
}
$runinbg = "convert -size ".$owh." ".$temppic." -resize ".$nwh." ".$output;
$runconvert = execute("$runinbg");
return true;
Thank you for help! :-)

Just as additional information:
There is a php.ini directive called disable_functions. Functions added to this list will be disabled by PHP and when you try to execute those functions, you get this error. As mentioned, in all probability your hosting provider has added exec to the disabled list. This is a common practice in shared hosting. You will need a dedicated server if you really want to run exec (or some hosting provider who provides pseudo-exec functionality). It is a bad idea to trust a shared hosting provider who allows you to run exec unrestrained.

Those errors mean just what they say.
Fatal error: Call to undefined function execute()
You are calling a function that doesn't exist.
Warning: exec() has been disabled for security reasons
Your web host has disabled the exec() method, you won't be able to run background scripts (like it appears you are attempting to do). You'll need to find another way to accomplish your goal, or find another web host.

Related

How to fix intermittent PHP Fatal error: Unknown: Cannot find save handler '/var/lib/php/session' [duplicate]

This question already has an answer here:
Warning : session_start(): Cannot find save handler 's' - session startup failed
(1 answer)
Closed 3 years ago.
Very intermittently and rarely my Centos7 httpd 2.4.41 and php 5.6.40 server will half load a page. The PHP loads, but the CSS and JS includes get the error 'Connection Reset' in chrome and dump this error into the php error log.
PHP Fatal error: Unknown: Cannot find save handler '/var/lib/php/session'
I have checked permissions on the session files, and the server has plenty of space, the fact that it works most of the time makes my scratch my head.
I've tried switching to memcached but same issue.
Can anyone share any light on whats causing this error?
Or perhaps a way to stacktrace the httpd PID after the fatal error?
Thanks in advance guys.
This issue might be related to your session save path. If you are not precious on where to save the sessions.
edit your php.ini and change the following
we are using the /tmp directory here.
session.save_path = /tmp
more information can be found here
http://www.php.net/manual/en/session.configuration.php#ini.session.save-path

simplexml_load_file(): I/O warning : failed to load external entity "/user-bundle/Resources/config/doctrine/model/User.orm.xml

I have some issue with my production deployment of Symfony2,
I've tried many solutions, but none have worked.
I randomly have this error when accessing my symfony application on production environment:
( ! ) Fatal error: Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Warning: simplexml_load_file(): I/O warning : failed to load external entity "/home/user/symfony/vendor/friendsofsymfony/user-bundle/Resources/config/doctrine/model/User.orm.xml"' in /home/user/symfony/app/bootstrap.php.cache on line 2998
( ! ) Symfony\Component\Debug\Exception\ContextErrorException: Warning: simplexml_load_file(): I/O warning : failed to load external entity "/home/user/symfony/vendor/friendsofsymfony/user-bundle/Resources/config/doctrine/model/User.orm.xml" in /home/user/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php on line 736
Call Stack
# Time Memory Function Location
1 0.0000 262880 {main}( ) ../app_dev.php:0
2 0.0015 572736 Symfony\Component\HttpKernel\Kernel->handle( ) ../app_dev.php:79
3 0.1342 4023952 Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle( ) ../bootstrap.php.cache:2376
( ! ) LogicException: Request stack is empty in /home/user/symfony/app/bootstrap.php.cache on line 2998
Call Stack
# Time Memory Function Location
1 0.3330 7110120 Symfony\Component\Debug\ErrorHandler->handleException( ) ../classes.php:0
2 0.3331 7119696 Symfony\Component\Debug\ErrorHandler->handleException( ) ../classes.php:1939
I've tried to upgrade my php version (I was in php 5.4.x and now in 5.6.4),
I've tried to upgrade lixml2 version (i am in 2.8.0 now, but i already tried to upgrade in 2.9.3)
I've constated that the version of libxml used in php is always 2.8.0, but, I haven't found the way to change this ,
I've tried to set the all directory of symfony in chmod 777
My server is a debian 7.5 server.
Maybe someone who knows this error can help me
Here is some links to differents question related to this one:
Random Error, FOSUserBundle Error and Service error
I didn't post in them because they're all outdated
[EDIT]
I found a quick fix, but it's in vendors, so it will be overrided in the first update of the doctrine update:
QuickFix in XmlDriver.php Line 737
$xmlElement = #simplexml_load_file($file);
if(!$xmlElement){
$xmlData = file_get_contents($file);
$xmlElement = simplexml_load_string($xmlData);
}
We got this error after we started using libxml_disable_entity_loader(true); in our code. That code is vital in preventing XXE -attacks(more info of that in here). If you don't have that in your code, it could be that you have installed/updated a bundle which has that line of code in use. Note that libxml_disable_entity_loader() is not thread safe, so if there is one piece of code on one thread that executes that line, everything on that server now has that enabled throughout the process.
The FOS-bundle seems to use xml-definitions, that in return have external entities in them. Nothing major though, but that code prevents the FOS-bundles methods from using those files correctly.
Luckily, our service got that error only in one place, and the fix was obvious:
Add a libxml_disable_entity_loader(false); before executing that piece of code where the error comes from, and add libxml_disable_entity_loader(true); right after that piece of code.
This way the user bundle could load the xml:s it needed, but security is not compromised.
Example:
libxml_disable_entity_loader(false);
$user = $query->getOneOrNullResult(); // This generates an error if entity loader is disabled
libxml_disable_entity_loader(true);
The error mentioned usually happens when the xml file does not exists.
You can try check if the file really exists after try to load:
if (file_exists($file)) {
$xmlElement = #simplexml_load_file($file);
}
I tried to simulate the error locally running php interactively, the results are in down:
php > simplexml_load_file('test.xml');
PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "test.xml" in php shell code on line 1
php >
Note, the error above is the same that you mentioned on the question. So, the first try is use the file_exists() function to check if the file really exists after try to load it. The next step is check if the current path - using getcwd() - and the path of the file are pointing correctly to the file.
I created a file called test.xml on /tmp folder:
<test>
<worked>
</worked>
</test>
Called the interactive mode on php:
$ php -a
Interactive mode enabled
So, checked my local directory:
php > echo getcwd();
/tmp
And, tried to load the file:
php > $data = simplexml_load_file('test.xml');
php > var_dump($data);
object(SimpleXMLElement)#1 (1) {
["worked"]=>
object(SimpleXMLElement)#2 (1) {
[0]=>
string(2) "
"
}
}
Note: that worked correctly. So, probably, your file does not exists or the path are incorrect. The path considers the current path /tmp plus, the file indicated on the function call test.txt, or equals to call the /tmp/test.txt file.
In my case, the problem on new hosting was:
allow_url_fopen
was disabled (any simplexml_load_file() or file_get_contents() returned false).
Solution: enable allow_url_fopen.
There are some solutions given:
https://github.com/FriendsOfSymfony/FOSUserBundle/issues/1062
https://github.com/symfony/symfony/issues/7291

PHP escapeshellarg() Issue, with CodeIgniter [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
escapeshellarg() has been disabled for security reasons
I've created an image upload system with PHP and it all works but I still get a warning:
A PHP Error was encountered
Severity: Warning
Message: escapeshellarg() has been disabled for security reasons
Filename: libraries/Upload.php
Line Number: 1066
Does anyone know how to get rid of this without contacting Hosting provider?
You can't. You will have to contact your sys admin to enable that function for you, or use something else (that does not involve executing shell commands) for what you are trying to accomplish.
Try replacing escapeshellarg with #escapeshellarg.
Because, then you'd be suppressing any warning that function call gives.
Since
it all works
Doing that shouldn't be a problem to your working code.
Note: using # to suppress warnings or errors is not recommended.

Getting strange error in PHP script running on unix

I'm running a php in a unix shell and I'm getting the following error.
The script is a web scraper and it work fine on my host if I access it. But I want to run it as a cron job, What shoul I do?
Warning: file_get_contents(http://www.lomamatkat.fi/iframes/last-minute-offers/?lastminute_next=50): failed to open stream: no suitable wrapper could be found in /var/www/customers/lentovertailufi/public_html/matkat/script/lomamatkat.php on line 30
PHP Warning: file_get_contents(): URL file-access is disabled in the server configuration in /var/www/customers/lentovertailufi/public_html/matkat/script/lomamatkat.php on line 30
Update your php.ini file, and set the 'allow_url_fopen' option to 'On'.
If you are unable to change allow_url_fopen consider using use curl (if must be php) or Wget
go to the php.ini and enable that or use curl or one of the other http get functions. file_get_contents is considered a dangerous system call for urls because people can slip files into it as well.

Call to undefined function domxml_new_doc() [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to solve “call to undefined function domxml_new_doc()…”
I'm using php5, when I try initializing a domxml_new_doc() it gives following error
Call to undefined function domxml_new_doc()
I checked phpinfo and found that DOM/XML is enabled...
Here is the code line which gives me the error
$doc = domxml_new_doc("1.0");
As suggested by KingCrunch, you're likely to be using PHP5. In that case, just use DomDocument instead.
However if you're still using PHP4, then the following test will tell you whether the extension is loaded:
var_dump(extension_loaded('domxml'));
If it returns false, then you have to enable the domxml library.
If you can modify php.ini, then locate a line extension=domxml.so (unix) or extension=domxml.dll (windows), uncomment it, then restart the web server.
If you cannot find this line, then you may have to install this library, which is outside the scope of this question :)

Categories