phpapachepermissionscentos7permission-denied

Permission denied on php require()


I have a php file within /var/www/html that is called from the client side, and within this php file I require a file from a directory I created and called /app/lib/ where all of my custom libraries and classes reside.

However, every time the endpoint is hit, I get the following PHP warning & error:

PHP Warning: require(/app/lib/User/User.php): Failed to open stream: Permission denied

PHP Fatal error: Uncaught Error: Failed opening required '/app/lib/User/User.php' (include_path='.:/usr/share/pear:/usr/share/php')

My server OS is centOS

Currently, the permissions on the /app/lib directory are apache:apache, with permissions on all directories set to 755, and the php files being set to 644.

I am not sure what else I am missing, so if anyone has any insight, I would greatly appreciate the help


Solution

  • This is for anyone dealing with the same issue.

    ÁlvaroGonzález's comment helped me figure this out, but the root of the issue was SELinux which runs on centOS by default.

    In order to fix my issue I disabled SELinux, which I do not recommend, you should research SELinux before you decide to disable it, but I feel comfortable doing so on my server.

    To disable SELinux:

    1. vi /etc/sysconfig/selinux
    2. Set SELINUX=disabled
    3. Restart the server (not apache)