We have been working on this for 2 weeks now, so I will attempt to condense this as much as possible. We are writing an application that requires PDF generation. We have attempted more libraries than I am able to keep track of at this point and they all fail. Many of them use headless Chrome, so that is where I concentrated my troubleshooting efforts.
We got to where we were just sending the command to the shell using the PHP Function
We have 2 servers that are AlmaLinux 8, CyberPanel with OpenLiteSpeed, and PHP 8.1. One server is bare metal, and the other an instance on AWS EC2. Both of these fail. In fact every other way to run the command other than via the web browser, which puts the seb server into the chain, passes and the command runs fine. It only fails if called via the broswer and never gives us any useful errors.
At this point to rule out OpenLiteSpeed I built a new server that is AlmaLinux 8, Apache 2, PHP 8.1 (no control panel) and the command runs fine via the web browser when Apache is serving the file. To have a sanity check, I moved the files from Apache back to one of the CyberPanel servers, fixed the paths, and fixed the permissions. I then did an
Details - with domain obfuscated as needed.
Command we are trying to run:
How it is run in the php file:
Again, if I run the command itself on any server from the shell, it generates the PDF file fine. If I run the php file as follows, it runs fine:
However, if I call the URL for the php file in the web browser, I get no error output and it doesn't generate a pdf file. The log is blank, and it completes imeadately without hanging. I'm sure there is some kind or output there, error or warning messages of some type, but I am not seeing them.
Any assistance would be appreciated. I would really prefer to avoid rebuilding our entire dev environment for this project. Especially since that would make this project an odd man out and pull it completely outside how all of our others are setup.
We got to where we were just sending the command to the shell using the PHP Function
shell_exec()
, so everything here will be related to the ability to run the command from the shell vs running it through the web server. The condensed version is that the command works from the shell via SSH. The command works being called by a php file via the php command at the cli. The command failes if the page is called in a web browser and is passed though the web server.We have 2 servers that are AlmaLinux 8, CyberPanel with OpenLiteSpeed, and PHP 8.1. One server is bare metal, and the other an instance on AWS EC2. Both of these fail. In fact every other way to run the command other than via the web browser, which puts the seb server into the chain, passes and the command runs fine. It only fails if called via the broswer and never gives us any useful errors.
At this point to rule out OpenLiteSpeed I built a new server that is AlmaLinux 8, Apache 2, PHP 8.1 (no control panel) and the command runs fine via the web browser when Apache is serving the file. To have a sanity check, I moved the files from Apache back to one of the CyberPanel servers, fixed the paths, and fixed the permissions. I then did an
su
to the web server user, and ran the php file though php 8.1 on the command line, and the command succcedded. I attempted to open the same file in the web browser, and the command failed. So everything points to OpenLiteSpeed being the issue. My options are get help here and fix the issue with OpenLiteSpeed, or rebuild our entire development environment to eliminate it. That means local dev server, public dev server, production server, and all of the CI/CD involved. I would rather not do this as we have about a week to get this working, and rebuilding everything would in itself exceed that.Details - with domain obfuscated as needed.
Command we are trying to run:
Bash:
/opt/google/chrome/google-chrome --headless --no-sandbox --no-pdf-header-footer --no-update-notifier --hide-scrollbars --disable-translate --run-all-compositor-stages-before-draw --virtual-time-budget=10000 --print-to-pdf="/home/sites.local/cattle.local/public/testing/test.pdf" http://xxxxxxxxx.tld/cattle_test2.html
PHP:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$cmd = '/opt/google/chrome/google-chrome --headless --no-sandbox --no-pdf-header-footer --no-update-notifier --hide-scrollbars --disable-translate --run-all-compositor-stages-before-draw --virtual-time-budget=10000 --print-to-pdf="/home/sites.local/cattle.local/public/testing/test.pdf" http://xxxxxxxxx.tld/cattle_test2.html';
header("Content-Type: text/plain");
echo "\n".date("Y-m-d H:i:s")."\n";
echo "Running command:\n";
echo shell_exec($cmd.' 2>&1 | tee /home/sites.local/cattle.local/public/testing/pdfLastRun.log');
echo "\n";
echo "\n";
echo "Directory listing of /home/sites.local/cattle.local/public/testing\n";
echo shell_exec('ls -al /home/sites.local/cattle.local/public/testing 2>&1');
exit();
Bash:
/usr/local/lsws/lsphp81/bin/php /home/sites.local/cattle.local/public/testing/pdftest.php
Any assistance would be appreciated. I would really prefer to avoid rebuilding our entire dev environment for this project. Especially since that would make this project an odd man out and pull it completely outside how all of our others are setup.