1

On macOS there is a terminal utility called 'pbcopy' which copies text into the clipboard. pbcopy < file copies the contents of 'file' into the clipboard. But from PHP (running under Apache, both the standard PHP and Apache included in macOS) it does not work. The only difference is that I have changed the Apache user to my username instead of the standard _www or www-data, for convenience of changing files on my development webserver (which is my Macbook Pro). I am running Apache 2.4.33 and PHP 7.3.11 under Catalina 15.3.

system("pbcopy < /Users/me/.profile");

from PHP does not do anything, but also not issue any errors.

system("pbcopy < /Users/me/.profile 2>&1");

to show stderr errors in PHP.

When running from a terminal

/usr/bin/php -r 'system("pbcopy < /Users/me/.profile");'

it does work: the contents of my .profile is copied into the clipboard. I have given /usr/sbin/httpd accessibility access under Settings => Security & Privacy => Accessibility to allow clipboard access.

Why does this not work under Apache ?

0 Answers0