Now Bald, questioning my life (libraries + env paths)

iamoort

Registered
Mar 26, 2021
3
0
1
USA
cPanel Access Level
Root Administrator
So I'm not sure where to post.

I've spent 3 hours Googling, trying things, and nothing works; so here's what I know.

OS: CloudLinux
CPanel: Bare Metal License
Access: WHM / Root

I have a php app that requires jpegoptim and optipng. Thus far I've only tried jpegoptim.

As a root user in SSH; I can execute
Code:
/usr/local/bin/jpegoptim -P -p --max=50 image_name.jpg
and it works fine. Says it compressed.

The issue comes from when I attempt to run this via the PHP exec command. It returns error code 127. Contacted jpegoptim and they said:
After discussing this with our team of developers, these errors are normally returned by your shell when any given command within your script is not found in any of the paths defined by the PATH system environment variable. This is an issue we aren't able to fix within the add-on because the error is actually coming from the server itself
So I spent an hour Googling.

Logged into the terminal / cpanel for my user, tried echo $PATH and it wasn't there; so I opened .bash_profile for the cpanel user, and added:
Code:
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/bin/jpegoptim

export PATH
Then went back to Cpanel terminal, echo $PATH; and it was returning with the extra path to jpegoptim I affixed to it via the bash file.

Tested again; same thing. Went back to cpanel terminal; tried to run the command manually in terminal, and it said jpegoptim not found. However, if I use Putty, login as root; I can find it, run it, and it compresses. So that tells me it's something with the user, a perm, etc.

Went back to terminal, listed directories, and I cannot find the path at all, jpegoptim is not there: /usr/bin/jpegoptim

I also tried two separate version of jpegoptim;
v1.4.3 -> /usr/local/bin/jpegoptim
v1.4.6 -> /usr/bin/jpegoptim

Tried all the same steps for both installs, including setting the ENV path in bash_profile; same issue. If I execute it via terminal in cpanel on that user, command not found. However, root works fine.

I'm lost as to how I am supposed to allow my cpanel user to access that.

Also; I went into WHM, ensured that exec() was not in php's disabled functions; ran a few lines of code, and exec works.

I'm sure I've missed a few points, but here I am. I've tried every bit of research I can, and it's just a circle. I don't know where I should be posting this. I tried cpanel since it may involve how cpanel deals with permissions and users.

jpegoptim isn't in the EasyApache / WHM area; so I had to do it manually.
If I can get some sort of direction to go in; I would be more than grateful. I'm all for figuring things out on my own, but I'm really at a wall here.

Why Post on Cpanel Forums?
Because I tried the cpanel terminal; and cannot seem to locate jpegoptim at all, I'm wondering if there's a step or procedure I've missed which allows a cpanel account to access or see libraries such as jpegoptim.

As I said; I can see jpegoptim fine as root, but if I login as the cpanel user / terminal; I cannot locate the jpegoptim file at all.
 
Last edited:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
6,951
921
313
cPanel Access Level
Root Administrator
Hey there! By default, I would expect "echo $PATH" to work properly when run as a cPanel user with command line access. Here is what I see on my test machine:

Code:
[[email protected] /]$ echo $PATH
/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/cpanel/composer/bin:/root/bin:/opt/cpanel/composer/bin
This could indicate a path issue with that user you tested with.

It's important to note that cPanel doesn't offer either jpegoptim or optipng as part of our tools, so if they have been installed manually it's possible they may not be available to all users.
 

iamoort

Registered
Mar 26, 2021
3
0
1
USA
cPanel Access Level
Root Administrator
Thanks for the reply.

I did manage to figure out the issue. It appears to be CloudLinux's CageFS feature, which makes sense now since it encapsulates each user.
I found that it worked if I disabled CageFS for the user (just popped up in my head as a last-ditch effort to try after a little nudging by CloudLinux).

In case anyone else runs into an issue like this; once I found that it started working, I had to create a new file in /etc/cagefs/jpegoptim.cfg
with the text:

Code:
[jpegoptim]
comment=jpegoptim
paths=/usr/bin/jpegoptim,/usr/local/bin/jpegoptim
Then restart cagefs:
Code:
cagefsctl --force-update
cagefsctl --remount-all
Adding that config file allows the library to be executable by all cpanel users.
 

iamoort

Registered
Mar 26, 2021
3
0
1
USA
cPanel Access Level
Root Administrator
lol it definitely did for me. It was roughly a full day's worth of doing everything under the sun I could think of.
I installed two different version of jpegoptim, and the PHP application kept erroring out that it couldn't access it.

So I manually ran jpegoptim and it compressed fine, created a small php script to echo the errors, and it kept returning the errors. Printed results to files. Literally anything you could think of, and I was going crazy.

Then I opened a ticket with CloudLinux initially asking if there were any special things in the OS that could limit, while I waited I went back to WHM, and just so happened to scroll past the LVE Manager saw CageFS, and a lightbulb kicked on. I disabled Cage on that one user, tested, and it worked immediately.

Talk about a frustrating set of events; all to be outsmarted by a single damn toggle switch and a config file with 3 lines.

I'll definitely look to CageFS first for any future issues. lol

Thanks for the reply though.