Error 500 - after changing var/www/html chown to www-data

I get a 500 error, it was after I tried to set chown to www-data over my html folder.

OpenEMR Version
7.0.1

Browser:
I’m using:Chrome

Operating System
I’m using: Ubuntu

Search

Logs

 PHP Fatal error:  Uncaught RuntimeException: Directory "/var/www/html/sites/default/documents/smarty/gacl" was not created in /var/www/html/interface/globals.php:243\nStack trace:\n#0 /var/www/html/interface/login/login.php(41): require_once()\n#1 {main}\n  thrown in /var/www/html/interface/globals.php on line 243

I ran ls-l

/var/www/html/sites/default/documents/smarty# ls -l
total 8
drwxr-xr-x 2 www-data www-data 4096 Sep 17 15:59 gacl
drwxr-xr-x 7 www-data www-data 4096 Sep 17 12:47 main

Thank you all

I have fixed it.
I think it is not the best practice, but I have set chown -R root:root /var/www then set it to chmod -R 777 /var/www.
Is there a script that may set appropiate folder and file permissions. Or there is a guide somewhere?

Hi Marco Meza,

I’m glad to hear that you were able to resolve the issue you were facing with the 500 error. However, it’s important to note that setting folder and file permissions to 777 (read, write, and execute for everyone) is generally not recommended for security reasons, as it grants wide-open access to your files and directories.

Instead of setting such permissive permissions, you can follow best practices for setting up permissions in a more secure way. Here’s a more secure approach:

  1. Ownership: Change ownership of the web directory to the web server user (www-data in your case). You already did this with the chown command:
chown -R www-data:www-data /var/www/html
  1. Directory Permissions: Set the directory permissions to 755. This allows the owner (www-data) to read, write, and execute while giving read and execute permissions to others:
find /var/www/html -type d -exec chmod 755 {} \;
  1. File Permissions: Set the file permissions to 644. This allows the owner (www-data) to read and write while giving read-only access to others:
find /var/www/html -type f -exec chmod 644 {} \;

This is a more secure setup that follows the principle of least privilege, ensuring that only necessary permissions are granted. It’s essential to prioritize security when managing file and directory permissions.

Remember to always exercise caution when changing permissions on your server, as improper configuration can introduce security vulnerabilities.

1 Like

Thank you @Thepherm, I have done what you suggest and it works perfect.
I owe you one.

Now I got a little issue, when I want to compile my scss (custom color theme) I can´t run npm run build.
Nor npm install at /var/www/html.
Any advise?

After running npm run build
sh: 1: gulp: Permission denied

Looking at gulpfile.js, I can see that there are some folders that need more permissions

// Source file locations

    src: {

        styles: {

            style_tabs: 'interface/themes/tabs_style_*.scss',

            style_uni: 'interface/themes/oe-styles/style_*.scss',

            style_color: 'interface/themes/colors/*.scss',

            directional: 'interface/themes/directional.scss',

            misc: 'interface/themes/misc/**/*.scss'

        }

    },

    dist: {

        assets: 'public/assets/'

    },

    dest: {

        themes: 'public/themes',

        misc_themes: 'public/themes/misc'

    }

However, I have switched back to 777 just to compile SCSS and then returned to 755 and 644. Thanks!