Php pages on /var/www/mypage say system("foo.sh"). foo.sh is located on /one/dir and contains command bar.sh that is in /other/dir. For a user using ssh connection and having /one/dir and /other/dir in PATH everything works.
Now, if I put
<Directory /var/www/mypage>
SetEnv PATH . . . :/one/dir:/other/dir
to Apache config, then print getenv("PATH"); on /var/www/mypage/mytest.php shows that /one/dir and /other/dir are in the path. But system() still does not found foo.sh. What's wrong? And after this also foo.sh should see the same PATH so that it will find bar.sh.
I am setting this on Ubuntu 20.04, PHP 7.4.3.
Most likely because just executing > foo.sh would show command not found: foo.sh.
You should specify full/relative path: system('./foo.sh');
Related
I am running Laravel on Homestead, and whenever I run any php artisan XXX command, the file named -1 is created in the root directory of the app.
Contents of the file are similar to these ones:
Log opened at 2017-12-22 13:54:00
I: Connecting to configured address/port: 10.0.2.2:9000.
E: Time-out connecting to client. :-(
Log closed at 2017-12-22 13:54:00
I am 99% sure it is related some changes I made in my failed attempts to make XDebug breakpoints work with artisan commands. I have exported some shell variables, as recommended in this answer, but when I run export -p I don't see any of them.
Did anyone have a similar issue? What setting can be causing such behavior?
Following the suggestion of LazyOne, I found the answer:
It seems that paths in .ini file have to be absolute. So instead of:
xdebug.remote_log=~/code/xdebug.log
I had to set it to:
xdebug.remote_log=/home/vagrant/code/xdebug.log
and now it works as supposed to.
Reproduceable problem description:
When installing HipHop / HHVM via the official way [1][2], and then running the built-in server [3] from /var/www via
cd /var/www
sudo hhvm -m server
it will render a custom "404 File Not Found" message to the browser, regardless of /var/www's contents when moving to the server's root:
http://111.111.111.111/
However, HipHop will run perfectly when a filename is given, like
http://111.111.111.111/index.php
Filling the index.php with phpinfo() will also show "hiphop" as feedback, indicating that this PHP file is correctly parsed by HipHop.
Question:
How to let HipHop's server run index.php (etc.) by default when navigating to the server's root, like Nginx and Apache do ?
Update:
Seems to be a common issue: [4], [5]
According to the documentation, the config.hdf file has a DefaultDocument directive. Set that.
For HHVM 3.0 you specify it in a ini config file with this:
hhvm.server.default_document = index.php
I made a php script to start Tomcat Server (catalina.sh start) thats works well from command line in Linux. It was run as ROOT with a different set of ENV.
However, I would like to do the same from the Web, Please note due to security issues, this script would only be accesible via localhost (for administration only), so we ironed out the security issue.
Problem is, Tomcat is not starting (we could confirm that from the logs, nothing was initiated). We coded lots of Echo around catalina.sh and its providing the right echo output.
Im sure theres an easier way to do this. Any Ideas?
The PHP script does the following:
Changes Dir to th Tomcat Bin
Starts Catalina.sh Script vis startup.sh
OUTPUT FROM COMMAND LINE PRINT ENV:
ORBIT_SOCKETDIR=/tmp/orbit-root
HOSTNAME=localhost.localdomain
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
XDG_SESSION_COOKIE=c111d8f81ff89709b78252c50000000d-1338310776.433586-1797694621
GTK_RC_FILES=/etc/gtk/gtkrc:/root/.gtkrc-1.2-gnome2
WINDOWID=73400323
QTDIR=/usr/lib/qt-3.3
QTINC=/usr/lib/qt-3.3/include
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
SSH_AUTH_SOCK=/tmp/keyring-bsFAQz/socket.ssh
GNOME_KEYRING_SOCKET=/tmp/keyring-bsFAQz/socket
USERNAME=root
SESSION_MANAGER=local/unix:#/tmp/.ICE-unix/1788,unix/unix:/tmp/.ICE-unix/1788
PATH=/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
MAIL=/var/spool/mail/root
DESKTOP_SESSION=gnome
PWD=/programs/tomcat/bin
GDM_KEYBOARD_LAYOUT=us
GNOME_KEYRING_PID=1779
LANG=en_US.UTF-8
GDM_LANG=en_US.UTF-8
GDMSESSION=gnome
HISTCONTROL=ignoredups
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SHLVL=3
HOME=/root
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
LOGNAME=root
QTLIB=/usr/lib/qt-3.3/lib
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-9HtQtRhCr9,guid=e1755bf07ea8a916f0a4e3f70000001c
LESSOPEN=|/usr/bin/lesspipe.sh %s
WINDOWPATH=1
DISPLAY=:0.0
G_BROKEN_FILENAMES=1
COLORTERM=gnome-terminal
XAUTHORITY=/var/run/gdm/auth-for-root-IT2DiY/database
_=/usr/bin/printenv
OUTPUT FROM APACHE PRINT ENV:
TERM=xterm
PATH=/sbin:/usr/sbin:/bin:/usr/bin
PWD=/programs/tomcat/bin
LANG=C
SHLVL=4
_=/usr/bin/printenv
try using exec()
exec('full path to your script')
I am trying to get apache/php to recognize the path to my git. I have been researching and looking in all corners of the web and cannot find how to do this. Basically, no matter what I try, when I run echo phpinfo(); the Apache Environment path does not change from /usr/bin:/bin:/usr/sbin:/sbin. And when I run system('echo $PATH'); in PHP, it reads the same.
System Information:
Mac OSX (Lion)
Apache 2 (running as _www)
PHP 5.3.6
Here is what I have tried editing so far:
/etc/profile
~/.bash_profile
~/.profile
/etc/path
/etc/path.d/{NEW_FILE}
Nothing I have tried so far has changed the $PATH variable. Any ideas?
SOLUTION
So here is the final solution. I edited the
/System/Library/LaunchDaemons/org.apache.httpd.plist
and added
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin</string>
</dict>
You can set the PATH environment variable in /System/Library/LaunchDaemons/org.apache.httpd.plist.
More in the docs.
Did you update the PATH environment variable of user '_www'? Apache will read environment variables from the user runs itself. Or, it looks like you didn't restart apache after updating PATH environment variable.
Check out the older discussion :
How do I add paths to the Apache PATH variable?
Setting environment variables in OS X?
And if you want to modify environment variable in PHP, getenv() and putenv() can be a better choice.
getenv : http://php.net/manual/en/function.getenv.php
putenv : http://www.php.net/manual/en/function.putenv.php
$path = getenv('PATH');
putenv( "PATH=$path:/new_path_that_you_want_to_add" );
Important note for El Capitan (Apologies for the new answer - I don't have enough Rep to comment)
On OSX 10.11, the /System/Library folder is protected, so the files can't be edited.
You need to:
Reboot into Recovery Mode (hold CMD + r after the startup sound)
Once in recovery mode, go to Utilities > Terminal
Run:
csrutil disable
Reboot back into OSX - you should now be able to change the files
Once done, go back to recovery mode and run
csrutil enable
Hope that helps
I created this gist that helped me out from the information above:
https://gist.github.com/srayhunter/5208619
My problem was that PHP was not finding a program that we had installed under /usr/local/bin. Once we did the above it all worked and played nice on mac osx.
for ubuntu server, in /etc/apache2/envvars,
for centos server, in /etc/sysconfig/httpd,
to add:
export PATH=<your php cli path>
and restart apache
A similar problem to what I was having installing Derby. The way I solved it was by opening TextEdit. Select File > Open at this point press Shift + Command + . , this will allow you to view all the documents. Head to the user directory and search for a file called ".profile" . Open it and add the export VARIABLE= Value line for example:
export DERBY_HOME=/opt/local/share/java/derby/
Save the document and restart your terminal to see if the changes went into affect.
I'm using the Kohana framework (3.0.9), which generates daily logs. I want to mail the log file if one was made the day before CRON runs the script, but after days trying I can't figure out how to put off safe_mode in PHP CLI modus.
When I'm running my script on the web, there is no problem. But I want to run the script as a CRON task on my Plesk 9.5.2 server (or on the command line as root user) I'm getting the following error:
ErrorException [ 2 ]: dir(): SAFE MODE Restriction in effect. The script whose uid is 10001 is not allowed to access /var/www/vhosts/mydomain.com/subdomains/mysubdomain/httpdocs/application/logs/2011/01 owned by uid 48 ~ APPPATH/classes/controller/ajax.php [ 181 ]
I've allready put SAFE MODE off in my Plesk control panel, which works fine for the web request, but not in on the command line or as an CRON task.
I'm using the following code to test if its working:
$d = dir(APPPATH.'logs/2011/01/');
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
echo $entry."\n";
}
$d->close();
I can read the directory APPPATH.'logs/', and also the directory APPPATH.'logs/2011', but the directory's representing each month with the daily log files always give an error.
At nowadays you can schedule php script execution from UI like this:
In case you still need execute script via command line pay attention that Plesk's PHP binaries are placed in:
# 7.0
/opt/plesk/php/7.0/bin/php
# 5.6
/opt/plesk/php/5.6/bin/php
# 5.5
/opt/plesk/php/5.5/bin/php
# and so on
Original answer:
I know this is a few months old, but for the next person that comes across a problem while using Plesk and cron and PHP, here's the answer.
While Plesk does run cron as ROOT, it also runs PHP by default with safe mode ON, which means that when you setup a cron in Plesk that needs PHP, it's going to have restrictions that you do not experience from the shell or from the web.
So what you do is use the CLI /etc/php.ini option override, like so:
/usr/bin/php -q -d safe_mode=Off /var/www/vhosts/path-to-your-php-file.php
Have you disabled safe_mode in the php.ini for CLI?
You can find the location of this file by running the following command php --ini. Search for safe_mode in this file and change the line to safe_mode = Off.