icishoot

Member
Jun 18, 2007
6
0
51
Good afternoon.

I am trying to get a web application called clipbucket working and am running into a couple problems.

Clipbucket is written in php and makes use of the exec and shell_exec functions to make system calls to video utilities such as ffmpeg, flvtool2.

One of the issues I am having is it couldn't find flvtool2.

I took their code, copied it to an php file and threw a ton of echo and vardump statements to try and figure it out.


What I discovered was that just doing "exec("which flvtool2") - returned nothing.

Doing: exec("PATH=\$PATH:/bin:/usr/bin:/usr/local/bin which flvtool2") returned the expected result: /usr/local/bin/flvtool2


To test it, if I did exec("echo \$PATH"); I just get /bin:/usr/bin

If I do exec("PATH=\$PATH:/bin:/usr/bin:/usr/local/bin; echo \$PATH"); I get /bin:/usr/bin:/bin:/usr/bin:/usr/local/bin.

They must know that this matters as for all their shell_exec() calls, they use a function wrapper that prepends the path before calling ultimately calling shell_exec.

This script has dozens of exec calls - I don't want to go through modifying their code to include the needed path (/usr/local/bin) in the $PATH.

So How can I add /usr/local/bin to $PATH by default, Preferably only for this 1 cpanel account on the VPS?


I am using whm/cpanel 78, centos 7.6, php7.0

Any help will be greatly appreciated,

Seth
 

APatchworkBoy

Active Member
Feb 26, 2018
27
7
3
West Yorkshire, UK
cPanel Access Level
Root Administrator
You used to set the full path to each of the necessary CLI tools directly within ClipBucket's Admin Panel, which would then be prefixed in front of the executable - is this no longer the case...? (Go to admin_area > Website Configurations > Upload and Conversion Settings)
 

icishoot

Member
Jun 18, 2007
6
0
51
It may in some areas - I haven't gotten that far. Something isn't right with the software - even with it having all the correct paths it won't convert video, and if you go to toolbox -> server modules info, site locks up.

When it tries to use shell_exec("PATH=\$PATH:/bin:/usr/bin:/usr/local/bin; bash -c /usr/bin/php --version 2>&1") the site locks up. It was while I was investigating this that I noticed the PATH issue. They could be unrelated - I very well could have gone down a bunny trail trying to fix a minor issue.

though having slept on it and taking an other look, I'm wonder if that php issue could be related to the command calling /usr/bin/php, but /opt/cpanel/ea-php70/root/usr/bin/php-cgi is what actually gets run? time for more digging I guess.

Thanks for your input - it may have refocused my investigation
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,911
2,233
363
cPanel Access Level
DataCenter Provider
Twitter
Hello @icishoot,

If you wish to export a system path to the user's environment, you can add a line similar to the one below in the /home/username/.bashrc file:

Code:
export PATH=/opt/cpanel/ea-nodejs10/bin/:$PATH
In this example, the modification allows for the use of the "node app.js" command from shell instead of the "/opt/cpanel/ea-nodejs10/bin/node app.js" command.

In your example, you may also want to review the document below regarding the ea-php-cli package:

EasyApache 4 and the ea-php-cli Package - EasyApache 4 - cPanel Documentation

Let me know if this information helps.

Thank you.
 

icishoot

Member
Jun 18, 2007
6
0
51
Adding
export PATH=/opt/cpanel/ea-nodejs10/bin/:$PATH to /home/<user>/.bashrc didn't do any thing.

To test, I wrote a simple script:

<?php
echo shell_exec("whoami; echo \$PATH");
?>


Running it in browser I get:

<expectedusername> /bin:/usr/bin


running echo $path from terminal I get:

/opt/cpanel/ea-nodejs10/bin/:/home/*****/perl5/bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin:/opt/bin:/opt/cpanel/composer/bin:/home/sdbtest/.local/bin:/home/*****/bin

****'s being the username.

And yes, I know the path given by cPanelMichal has nothing to do with php - I just threw it in there to see if it would show up.


Results: the path that a script uses when run through apache/php is different then when echoed straight from a terminal. And looking at the path echoed at the terminal, the directory I want to add is already there - something must be changing the PATH.

In doing a little more searching - it seems apache or the php handler is the one that sets the environment variables for PHP - Some one back in 2012 posted here with my exact same question, the answer then was to use mod_php and add the export path command to /usr/local/apache/bin/envvars - I'm using suphp and and the envvars path doesn't exist.


Seth
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,911
2,233
363
cPanel Access Level
DataCenter Provider
Twitter
Hello @icishoot,

Thank you for sharing the additional information.

I believe you're looking for the "putenv" PHP function:

putenv — Sets the value of an environment variable
Here's a comment from PHP's documentation of this function with background information about how it works:

PHP: putenv - Manual

Can you confirm if this aligns with what you're attempting to configure?

Thank you.