Getting "permission denied" for executing python script from PHP - apache

I have apache server installed on redhat linux.
I have a PHP script that needs to call a python wrapper script that calls another python script which has a function to execute some database queries.
So, my php script is in location /var/www/html: If I execute the python script from this location command line the script works fine. However, If I run the exact same command through exec inside PHP, I get "permission denied".
The whoami at /var/www/html gives my linux user id.
Inside php script
exec("whoami")
returns apache.
and
echo get_current_user();
returns my linux user id. Which is understandable since get_current_user returns the owner of the php script. How should I fix this problem? Is the problem because user "apache" does not have access to the script? User "smeeta" does have access to execute the script.
Any guidance here is highly appreciated.

Related

Run script when start the asterisk using service

I am facing some strange issue to execute script when started the asterisk using "service asterisk start".
I can run script within dialplan using system() app when I started the asterisk using asterisk -vvvvvvvvc but when I start the asterisk using service (service asterisk start), asterisk can not execute the script, getting error like "Can not execute the command".
I have installed the asterisk as asterisk user. setup is done with freepbx installation.
I tried with various option, like changing the script with chown (chown asterisk:asterisk script), chmod 777 script but does not work.
Which OS version are you using?
If it is RHEL / CentOS 7, then you should use "systemctl start asterisk" instead.
If it is RHEL / CentOS 6, then you run the command correctly. Note that this startup script launches an intermediate script safe_asterisk, and the latter, in turn, launches the asterisk itself.
Check /var/log/messages and /var/log/asterisk/full - does anything interesting appear there at the moment of unsuccessful startup?
Could you also share the list of processes (ps -ef | grep asterisk) after you execute this startup script?

Plesk 12 scheduled task error

I am trying to set a cron job where it will run php script and mail the results to user. However I am getting a permission denied error when the script is run.
/bin/sh: /var/www/vhosts/domain.com/httpdocs/bdmail.php: Permission denied
This is the code I am using in the command line:
/var/www/vhosts/domain.com/httpdocs/bdmail.php
I would be grateful if someone could highlight my error. I have setup a new task in plesk and it looks correct to me. Thanks
OS: CentOS 6 with Parallels Plesk Panel 12 (64-bit)
You should create scheduled task that calls the script interpreter with the path to the script as an option. For example:
/usr/bin/php /var/www/vhosts/domain.com/httpdocs/bdmail.php
instead of just
/var/www/vhosts/domain.com/httpdocs/bdmail.php

Windows Server Permissions: What permission changes are needed to run 'sqlcmd' through IUSR?

A little background: I need to invoke sqlcmd to remotely run .sql files via PHP. I am trying to use this function call: exec("sqlcmd -?", $second); There is zero output after running this command. Running this command under my current user works fine.
PHP runs under IUSR according to PHP's get_current_user(); function so it would be logical to change the permissions on sqlcmd to allow PHP to run sqlcmd (I give full permissions temporarily just for testing):
Then I retest the PHP script and again no output. I decide to restart IIS. Still no output.
What permissions are needed to run sqlcmd under IUSR?

Serving lua pages in apache windows

I have been using php for CGI scripting for some time now and recently got interested in lua.
I installed the latest version of luarocks(2.1.2) and the bundled version of lua(5.1.4). I wanted to start from the basics and hence installed cgilua(5.1.4-2) and all its dependencies using "luarocks install cgilua".
I am able to run simple lua scripts using the shebang line to point to my lua interpreter but when i use it to point to the cgi launcher "cgilua.cgi.exe" to run .lp files it just won't work. I edited my httpd configuration file to allow cgi execution in my htdocs and cgi-bin directory and used the cgi-script handler for .lp pages. I am trying to run the login.lp example in the cgilua examples directory. I even added the line "Content-type:text/html" to no avail. Executing the cgilua.cgi.exe file from the command line without arguments just closes the application with the message "cgilua.cgi.exe" stopped working".
Could anyone tell me what am I missing? Maybe the launcher is supposed to be used in a different way?
I don't suppose permissions have a part to play in this as in windows all users have at least read and execute permissions.
The url I'm trying to access is http://localhost/login.lp. My apache error log shows "Premature end of script headers: login.lp" with a 500 internal server error and the same thing if I access http://localhost/cgilua.cgi.exe
I don't know what your requirements are, but perhaps it will be easier to simply use apache's mod_lua.
http://httpd.apache.org/docs/trunk/mod/mod_lua.html

Is there a better way than this to run an SQL script through puppet?

Take a look at Get puppet build to fail when the contained SQL script fails execution
I was attempting to run a vagrant build which installs Oracle XE in an Ubuntu Virtualbox VM and then runs a an SQL script to initialize the Oracle Schema. The vagrant build is here : https://github.com/ajorpheus/vagrant-ubuntu-oracle-xe. The setup.sql is run as a part of the oracle module's init.pp (right at the bottom or search for 'oracle-script').
When running the SQL script as a part of the vagrant build, I see the following error:
notice: /Stage[main]/Oracle::Xe/Exec[oracle-script]/returns: Error 6 initializing SQL*Plus
notice: /Stage[main]/Oracle::Xe/Exec[oracle-script]/returns: SP2-0667: Message file sp1<lang>.msb not found
notice: /Stage[main]/Oracle::Xe/Exec[oracle-script]/returns: SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
There were two things that were instrumental in me finding a workaround for the problem:
As suggested in this answer, setting the logoutput attribute to true for the exec block under question immediately showed me the error, whereas before the exec was just failing silently.
It seemed strange that I was able to run the command (sqlplus system/manager#xe < /tmp/setup.sql) after manually logging in as the 'vagrant' user. That suggested that there was something missing in the environment. Therefore, I copied all ORACLE env. vars into the exec as seen on Line 211 here
That worked, however, setting up the env vars manually seems a bit brittle. Is there a better way to setup the ORACLE environment for the vagrant user? Or, is there a way to get puppet to setup the environment for the vagrant user similar to an interactive shell?
If some profile has been set up to give the user a working interactive shell, you should be able to pass your action through such a shell
command => 'bash -i -c "<actual command>"'
As an aside about logoutput, since you mentioned that - the documentation advises that "on_failure" is a sane default, as it will only bloat your output when there are actual errors to analyze. It is the actual default in the latests versions of Puppet.