Skip to content
Advertisement

PHP cannot execute local programs when accessed through a browser

I am a bit new to PHP and web development in general, and I am trying to execute a program from php. I setup my virtual machine and hosted it properly, but when the website attempts to load the page, it says that the program could not be executed: “permission denied.” I tried everything including:

  1. Adding execute permissions to every file in /var/www/html
  2. setfacl -m u:apache:rwx /var/www/
  3. chown -R apache:apache /var/www/

Further context:

  1. I am on fedora linux

heres index.php:

JavaScript

When I run it from a browser, this is the output:
browser output

JavaScript

Most tips on the internet tell you to make sure user ‘apache’ has permission to execute the file. I have done that and verified by doing the following commands.

JavaScript

I sudoed into the apache user and was able to read every file in the directory and execute them via the shell. After that, I ran php index.php, and it executed the script perfectly with the exepcted output.

I am at a complete loss for why it can’t execute this script in the browser, any help would be much appreciated!

Edit: I checked my php.ini file and there are no disabled functions

JavaScript

Advertisement

Answer

I checked my SELinux configuration and the scripts were not set to the correct permissions. They were set to httpd_sys_content_t when they needed to be httpd_sys_script_exec_t.

the simple fix was:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement