php mail() working on terminal but not in browser - php

I have a small php test script with the following code:
if (mail("test#test.com", "Subject", "Message", "From:test#test.com")) {
echo 'OK';
} else {
echo 'failur';
}
When I run the script in the terminal like this:
php test.php
It prints 'OK' but when I open it on my lokal apache via localhost/test.php is says 'failur'.
I also hava a file with phpinfo() in it and the browser and terminal are using the same php version and the same php.ini file.
I can't think of a apache configuration that would prevent mail from working.
Apache 2.4.18 (Mac)
PHP 5.6.23 (installed via homebrew)

Related

How do I use php in sublimetext3?

I can't seem to use php on sublimetext3
I've tried this:
{
"cmd": ["PHP", "$file"]
}
Saving this under C:\Users\ \AppData\Roaming\Sublime Text 3\Packages\User
But when i try to execute this:
<?php
echo"It worked"
?>
I get this error:
[WinError 2] The system cannot find the file specified
You need to run a server. This can be done with Apache or NGINX or even IIS, or with a built-in server, but recommend xampp:
http://learningcn.com/SublimeServer/
https://www.apachefriends.org/

I am unable to run the project in local environment after running the service httpd restart

After running the httpd by using the command service httpd restart, but I am unable to run the project locally. While running the project, it displayed the PHP code. Can you please help me to solve the issue? This is the PHP code:
<?php// allow testing from the upgrade page before the site is upgraded.if (isset($_GET['__testing_rewrite'])) {
if (isset($_GET['__elgg_uri']) && false !== strpos($_GET['__elgg_uri'], '__testing_rewrite')) {
echo "success";
}
exit;}require_once(dirname(__FILE__) . "/engine/start.php");$router = _elgg_services()->router;$request = _elgg_services()->request;if (!$router->route($request)) {
forward('', '404');}
Check the HTTP config and error log. The PHP module is not loaded any longer, or the .php extension (or whatever extension you've used) isn't associated with the PHP module any longer.
Until you give us more details, that's all we can answer with.

Running Powershell commands from PHP

I am trying to run a PowerShell command from inside a php file on my webserver.
Here is my php code:
<?php
$query = shell_exec('C:\\Windows\\syswow64\\WindowsPowerShell\\v1.0\\powershell.exe -command Get-Host');
echo $query;
?>
The result I get is HTTP Error 500 - C:\PHP\php-cgi.exe - The FastCGI process exceeded configured activity timeout - Error Code 0x80070102
To perform a test to verify shell_exec and php were functioning (that I hadn't screwed something up when setting up the environment). I also tried this php:
<?php
$query = shell_exec('dir c:\\');
echo $query;
?>
This worked, the page source looked exactly like you'd expect if you had run the dir c:\ command from a command prompt in windows.
I've looked at several other articles here on stackoverflow, as well as on technet, and can't seem to identify what is causing this to time out. When I run the same command from the command prompt the result is very quick.
Here are the results from executing the same command manually at the command prompt (again what you'd expect):
C:\>C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -command Get-Host
Name : ConsoleHost
Version : 2.0
InstanceId : 9a24a372-f0a3-4a79-b9fd-1e180e9a8069
UI : System.Management.Automation.Internal.Host.InternalHostUserI
nterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
A little about my environment:
I'm running IIS 7.5 on a Windows 2008 R2 SP1 Standard Server.
The server is standalone (not part of a domain).
I have PHP 5.5.9 installed, and working. phpinfo() returns the expected page without any noticeable errors.
Any help in getting me on track with executing powershell commands from php is much appreciated!
Try this :
$query = shell_exec('C:\\Windows\\syswow64\\WindowsPowerShell\\v1.0\\powershell.exe -command Get-Host < NUL');

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

How can I check whether the server is able to handle SOAP requests

How can I check whether the server is able to handle SOAP requests at run time ?
I need to verify it before my script is executing.
You can use:
if (extension_loaded('soap')) {
// Do things
}
http://php.net/manual/en/function.extension-loaded.php
From SSH you can run:
php -i | grep Soap
that will return something like:
Soap Client => enabled
Soap Server => enabled
In PHP to check whether SOAP enabled or not use built in function class_exists():
var_dump(class_exists("SOAPClient"));
It also could be user to check any of modules classes.
in the command line type the following:
>> php -r 'echo (extension_loaded("soap")?"LOADED\n":"not loaded\n");'
Hmm... I'm new and I'm bad :
I tried this in a "test.php" file.
<?php
if (extension_loaded('soap'))
{
echo phpinfo();
}
else //will redirect to sth else so you know it doesn't work
{
header("Location: http://localhost/index.html");
die();
}
?>
And I saw myself looking at a "phpinfo()" page with a paragraph called : "soap".
Sorry for the misinterpretation.
To install SOAP :
Check your "php.ini" file, look for "extension".
You should find a line :
extension=php_soap.dll or ;extension=php_soap.dll
";" means it's commented.
Uncomment it.
If you didn't find the line, then put it there.
extension=php_soap.dll
Make sure the dll file actually is in the default folder php/ext.
If it isn't, check on phpinfo() is your version is VC6, VC9 of VC11, go to the php download page : http://windows.php.net/download#php-5.6 and get the correspondant version of php zip file.
Steal their "php_soap.dll" from their /ext folder and put it in yours.
You're all set!
Restart your servers, then go to your phpinfo() test page to check if it works.
Good luck.
Note :
phpinfo() simple test.php file :
<php
echo phpinfo();
?>
in a php file :
<?php
echo phpinfo();
?>
and then look for SOAP and you will see if SOAP is installed and enabled
EDIT : be careful with other solutions using php CLI (Command Line Interface), because you don't have the same php.ini used for the CLI and for your web server (for example apache). Thus it may differ.
Then if you use apache and you want to see if soap is enabled, it's better to indicate the apache php.ini file in the command line, for instance :
php -c /etc/php/apache2/php.ini -i | grep Soap
PEAR packages are not listed in phpinfo(), so if "soap" doesn't appear on your "test.php" page, it's normal !
You can use the phpinfo script to see is SOAP is installed.
http://[your-domain.com]/phpinfo.php

Categories