cups icon indicating copy to clipboard operation
cups copied to clipboard

Cups web server

Open markosjal opened this issue 4 years ago • 8 comments

I was wondering if it is possible to get the CUPS web interface linux to run php . I ask this because it is installed and already running . I would like to work in additional printer and scanning related functionality through that web interface. It also makes perfect sense that it be integrated into the same interface.

markosjal avatar Aug 02 '21 00:08 markosjal

@markosjal Yes, it is possible. Look at the http://localhost:631/help/cgi.html documentation on setting this up.

michaelrsweet avatar Aug 03 '21 14:08 michaelrsweet

Not quite so easy. I followed the instructions and after a cups restart PHP code is displayed on page .

So I made sure php was installed , but do not think I need it???

Now after full system restart the phpinfo.php page i created downloads in browser

PHP is not processed

Using Linux Mint 20.1 Ulyssa (based on Ubuntu 20.04) and CUPS from repos

markosjal avatar Aug 03 '21 17:08 markosjal

@markosjal Depending on the version of CUPS you are using, you might also need to make sure the execute bit (chmod +x filename.php) is set.

michaelrsweet avatar Aug 03 '21 19:08 michaelrsweet

set phpinfo.php with execution bit chmod +x owner is root:root just like the other files there no PHP scripts are executed. Instead. phpinfo.php is downloaded.

There is something missing in the docs to get this working

markosjal avatar Aug 03 '21 21:08 markosjal

@markosjal Can you attach the PHP file you are using?

michaelrsweet avatar Sep 05 '21 15:09 michaelrsweet

The funtionality is compile time dependent, in 2018 libcupscgi1 was removed and is not packages anymore in ubuntu and think in debian too. I am really not sure what that means, could it be that it is unavailable since version 2.2.9?? Can anyone confirm that it is working in other distros or Macos?

jschwender avatar Sep 09 '21 10:09 jschwender

@jschwender The CGI support was simplified in CUPS 2.0, but unfortunately the documentation hasn't been updated.

All that is required is to create a MIME .types file (call it cgi.types) in /etc/cups and then list the extensions you use, e.g.:

application/x-httpd-cgi cgi php

will allow any executable file in the document root with the extensions "cgi" or "php" to be run as a CGI script. You also need the #! line to tell the system which interpreter to use, e.g.:

#!/usr/php -fn
<?php
...
?>

Anyways, I am in the process of updating the documentation and adding some explicit tests to the CUPS sources so this works as expected.

michaelrsweet avatar Sep 09 '21 14:09 michaelrsweet

Documentation changes and examples added to Apple CUPS:

[master d03753f33] Update CGI documentation and add testable examples for CGI support (Issue #5940)

and OpenPrinting CUPS:

[master 3318d9f4f] Update CGI documentation and add testable examples for CGI support (Apple #5940)

@markosjal Please let me know if these examples help you get your PHP scripts to work.

michaelrsweet avatar Sep 09 '21 15:09 michaelrsweet