PHP -> python seems to not work on web server - php

I have a few pages (one html, one php, and one python script) that takes a user input, and then outputs a pdf file (using reportlab) for the user. When I test on apache (localhost), it works perfectly.
However, online on a real web host it is not working. The version of PHP on the web server is 5.2.17 and python is installed.
Could the version be an issue? I am very lost because I'm not very experienced and it works perfectly on Apache and not at all on the internet.
Last thing, the command I use to call the python function from php is this:
$ed = exec("python pdfgeneration2.py $name $age");
I also thought maybe there is a better command for this?
My question may be vague and unclear but if anyone has any ideas it would be greatly appreciated.

Look at /var/logs/httpd/error_log, or wherever your distro's apache stores logs. Odds are you'll find an error message there from PHP.
In addition to checking the path like sberry recommended, double check perms, too. Apache will need execute permissions on the python script: chown apache:apache pdfgeneration2.py

Related

Running PowerShell from IIS Server does not work (OK on EasyPHP install, though!)

I have searched for answers to this question, but the answers I've found do not seem to apply to my case. Or at least I was not able to understand them?
I'm working on an internal Web, so security is not the main issue.
I'm trying to launch scripts from the server.
I know that Web Servers are not really intended to do that, but again, security is not the issue, and scripts are intended to run on server side.
So far I'm able to launch batch scripts and even call some kind of ksh commands: OK.
For instance, if the PHP contains:
exec ('Test_ExecCmd.bat', $out);
and Test_ExecCmd.bat content is:
echo "Hello World" ;
whoami
Then $out array will contain "Hello World" and MyServerHost\MyAnonimousUser
Please note that "whoami" is a "ksh like" command, and it works fine here.
BUT when I try to put in a batch script the line:
powershell ls c:\
for instance, to list the content of c:\ the PHP script freezes and ends up with an error: "500 - Internal Server Error"
I have tried the same PHP + BAT sample on a locally installed EasyPHP, and it runs OK!!!!
So there it seems there is a specific tuning to be done on IIS, perhaps on its settings, authentication method or whatever.
Has anyone faced this kind of issue, please?
All suggestions are welcomed, thanks in advance!
Best regards,
Jorge

mbstowcs from apache not getting executed

I am calling a perl script from one php page. This perl script calls some other scripts inturn and a C binary file. The C binary uses mbstowcs function inside. This is not getting executed correctly.
But the same thing If I call from terminal(the perl script) everything works fine.
I have given proper permissions to all the files before executing(Even gave 777 permission).
Is apache uses some other terminal session/ something else to run the scripts.
I am using ubuntu 14.04 and apache webserver.
Without given any further information, I suspect you may have run across the following situation:
Use of non standard mbstowcs feature
This information is dated I realize but it's all I can offer at this time unless you can provide some more information like an error message from your Apache log file.
Sorry I could not be of more help.

Can't write log file in Linux using PHP

I'm running CentOS 6.5 on a Google Compute Engine instance which I use for an ejabberd XMPP server. I also have php 5 installed and ejabberd is configured to use a php script to authenticate users.
So far so good - ejabberd executes the script and recieves the correct result from it. The problem is: I want the PHP script to write a log file. So far I've tried:
Writing a file using file_put_contents to /var/log/mlog.log - this didn't work. so I've tried manually creating the file and giving it chmod 777 (for testing). No result - the file remains empty. But - when I execute the script manually using php from terminal the log is written.
Writing to syslog - I've configured php.ini to use syslog and then tried logging. Same result: nothing when ejabberd runs the script, but when I manually run it it works.
Configuring error_log file and using error_log($message). Again, it didn't work.
I came to realize it must be something wrong with the write permissions of the ejabberd user (which runs the php scripts), but even when I set chmod 777 to every file in every option of the above, the log remains empty.
Any hints? What am I missing? (as you can probably tell, I don't have much knowledge in Linux and this is the first time I'm using it in a project)
This may not be the answer you are seeking. I am not much familiar with Linux. There is a KeyLogging php class know as KLogger. You can create logs using this class. It is very easy to use, You have to download php file and use it. You can find it in github. Hope this might solve your problem.

Python to POST data to local PHP on linux

This may sound a bit strange but I need this to happen like this for a reason.
I need python to be able to post data to a local PHP file on a linux server and then get a response from the PHP.
I have tried this:
p = subprocess.Popen("curl --data 'param1=value1&param2=value2' /home/hbmukwm/temp/receive.php", shell=True, stdout=subprocess.PIPE)
reply = p.stdout.read()
But when I do this, as it's a local file I get this curl error: curl: (3) malformed
I also tried it this way (found on a stackoverflow answer)
mydata=[('one','1'),('two','2')]
mydata=urllib.urlencode(mydata)
path='file:/home/hbmukwm/temp/receive.php'
req=urllib2.Request(path, mydata)
req.add_header("Content-type", "application/x-www-form-urlencoded")
reply=urllib2.urlopen(req).read()
But in this case I get the php response as plain text like I'm just trying to read the PHP file, again I think this is happening because the PHP file is local, like this:
<?php echo "test"; ?>
Rather than just
test
Hope this is making sense so far. All I need to do is POST the data to the local PHP file, and then get the PHP response back to python... Is this possible...
Any response is highly appreciated, sorry for my ignorance!
Thanks everyone for your responses, I have learnt something at least! The reason I wanted to have it as a local file is because I didn't want the PHP files to be publicly accessible, though data needed to be sent to them from any location the application was run. So my idea was to create a small python application that runs on a port on the linux server that takes commands and passes them to the PHP files local to the server.
Anyway, the way I have got this working is by using a command line (Like my first example) except using:
p = subprocess.Popen("php /path/to/file 'data=this'", shell=True, stdout=subprocess.PIPE)
And then in the PHP files grabbing the argument like this
$data = $argv[1];
This isn't posting the data to the PHP files like I initially was asking for but I guess I mis-understood what I needed to do. So thank you for all your help guys! I can't really figure out which one of your answers was the definitive answer because you were all correct in what you said, but the answer I am posting now is how I overcome the problem.
Thanks again guys, Stack Overflow is the best :)
You need a web server to run PHP code. You can't just refer to it as a filesystem location. I recommend that you install [WML]AMP web server bundle on your machine which will install Apache, PHP, MySQL and it's easy to setup and configure for beginners. Here are the links for the AMP family. Use the one that
Windows : WAMP
Linux: LAMP
MacOSX: MAMP
You will need a web server to actually parse and interpret the PHP scripts. However, in case you want to do it via the command line this page should give you some details:PHP Command line usage. You have not mentioned which version of PHP you are using, however this appears to be supported since PHP 4.3.0
I guess it is a matter of taste, but I am using "xammp" from www.apachefriends.org
You can easily setup a webserver from there with php5, sql and so on. Wit BitNami you are also able to easily install joomla and other stuff.

Shell_exec with git pull?

I am setting up a github account, to work on a small project with some friends.
I would like to have my home machine able to do a git pull via php, so that we just have to call this small php file for the machine to be up to date.
As of right now :
<?php
$output = shell_exec('git help');
echo "<pre>$output</pre>";
?>
This works perfectly and I get the output, I am in the right directory, so git pull should work just as well, but I get a hanging page, no error, nothing.
Any idea ?
EDIT : A few precisions, the repo is pretty small, around 300K, it takes only a few seconds from the command line. I also tried shell_exec("dir"), and I am in the right directory. I am running the default installation of xampp on Windows 7 x64, if I can be precise enough :)
I suggest exploring set_time_limit() , as well as making sure your git pull does not stop if the user disconnects via ignore_user_abort(). Even running from a gigabit connected server, some repositories just take a while to clone.
Also, check PHP's working directory, and ensure the user running PHP has privileges to write to the repo. If you ran this via CLI and it 'just works', its a good chance that PHP was running without appropriate privileges when accessed via whatever web server you are using.
If you chmod the destionation directory as 777 and it works, there's a very good chance that you need to recompile apache/php for suexec support. Please, don't just leave it as 777 if that is the case :)
Either way, time out and user aborts are still valid considerations, even after you get it working.
So, to answer my own question.
It was in fact a permission problem (thanks tim), from the PHP CLI, the script was working.
The problem was that the service php installation is using some strange permissions.
So you/I need to start the PHP server via the command line (or in this case the Xampp control panel).
Now it's working, giving me the "Already up-to-date." answer I was waiting for :)

Categories