I ran chown -R www-data:www-data /var/www and got 500 Internal Server Error

March 15, 2017 342 views
WordPress Ubuntu 16.04

I ran chown -R www-data:www-data /var/www and got 500 Internal Server Error, get a file not found error on all of my domains and can't seem to fix it.

I feel like it used the wrong path since everything is there but I'm not positive.

6 Answers

Got it! It had changed the permission of the folder /var/www and the ownership of vhost files and folders also. Thanks folks!

@andrewobenreder

What web server are you using, Apache or NGINX?

If apache, please run:

tail -50 /var/log/apache2/error.log

If NGINX, please run:

tail -50 /var/log/nginx/error.log

If your log files are in a different directory, please replace accordingly and post the output in a code block -- we can take a closer look at the error logs to see what's going on.

@andrewobenreder

The only issue I can see from the logs appears to be from the warning being generated.

server certificate does NOT include an ID which matches the server

The above seems to persist across all domains which would indicate that there's something wrong with the SSL Certificates being used.

That being said, can you also post your site-specific configuration (i.e. VirtualHost blocks) for the site or sites affected? Normally running chown won't cause file not found issues, unless the user that you're changing ownership to doesn't have permission to read/write on those specific files.

I didn't specify any user or other attributes but the error appeared directly after utilizing the base code.

It also affected the sites different: muvtest.space gives and internal server error and muvmag.com says file not found.

  • @andrewobenreder @jtittle

    Do you know which user/group Apache is running as?
    Try running this command to show all Apache processes

    ps -aux | grep -i "apache"
    

    By the way, the "File not found" does not look like an Apache error. Are you using PHP or similar? And do you have a CMS system running?

    • I have no idea about the user/group but I will check. All sites are Wordpress installations.

    • root 19570 0.0 0.2 131092 12012 ? Ss Mar15
      0:02 /usr/sbin/apache2 -k start
      www-data 19573 0.0 0.1 129320 6100 ? S Mar15
      0:00 /usr/sbin/apache2 -k start
      www-data 19574 0.0 0.1 130496 5608 ? S Mar15
      0:00 /usr/sbin/apache2 -k start
      www-data 19575 0.0 0.2 131432 10220 ? S Mar15
      0:00 /usr/sbin/apache2 -k start
      www-data 19576 0.0 0.2 131440 10208 ? S Mar15
      0:00 /usr/sbin/apache2 -k start
      www-data 19577 0.0 0.2 131384 10304 ? S Mar15
      0:00 /usr/sbin/apache2 -k start
      www-data 19578 0.0 0.2 131332 10216 ? S Mar15
      0:00 /usr/sbin/apache2 -k start
      www-data 19579 0.0 0.2 131320 10144 ? S Mar15
      0:00 /usr/sbin/apache2 -k start
      www-data 23807 0.0 0.2 131388 10300 ? S Mar15
      0:00 /usr/sbin/apache2 -k start
      root 32474 0.0 0.0 14516 1032 pts/0 R+ 05:19
      0:00 grep --color=auto -i apache

      • @andrewobenreder
        Okay, so it is running as www-data. There must be something else that was changed.
        Would it be possible to add the Apache configurations from /etc/apache2/sites-enabled/ ? Just remember to click the Code-button in this editor, when inserting, so it doesn't garble the text.

        • # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
                  # error, crit, alert, emerg.
                  # It is also possible to configure the loglevel for particular
                  # modules, e.g.
                  #LogLevel info ssl:warn
          
                  ErrorLog ${APACHE_LOG_DIR}/error.log
                   CustomLog ${APACHE_LOG_DIR}/access.log combined
          
                  # For most configuration files from conf-available/, which are
                  # enabled or disabled at a global level, it is possible to
                  # include a line for only one particular virtual host. For example the
                  # following line enables the CGI configuration for this host only
                  # after it has been globally disabled with "a2disconf".
                  #Include conf-available/serve-cgi-bin.conf
          </VirtualHost>
          
          # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
          
          
          
          • This is only a part of one file. We need to see all the data to be able to help.

          • It was the only file in there and I'm not super familiar with apache.

          • Here's the whole file. I missed the beginning.

            <VirtualHost *:7080>
                    # The ServerName directive sets the request scheme, hostname and port that
                    # the server uses to identify itself. This is used when creating
                    # redirection URLs. In the context of virtual hosts, the ServerName
                    # specifies what hostname must appear in the request's Host: header to
                    # match this virtual host. For the default virtual host (this file) this
                    # value is not decisive as it is used as a last resort host regardless.
                    # However, you must set it for any further virtual host explicitly.
                    #ServerName www.example.com
            
                    ServerAdmin webmaster@localhost
                    DocumentRoot /var/www/html
            
            # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
                    # error, crit, alert, emerg.
                    # It is also possible to configure the loglevel for particular
                    # modules, e.g.
                    #LogLevel info ssl:warn
            
                    ErrorLog ${APACHE_LOG_DIR}/error.log
                     CustomLog ${APACHE_LOG_DIR}/access.log combined
            
                    # For most configuration files from conf-available/, which are
                    # enabled or disabled at a global level, it is possible to
                    # include a line for only one particular virtual host. For example the
                    # following line enables the CGI configuration for this host only
                    # after it has been globally disabled with "a2disconf".
                    #Include conf-available/serve-cgi-bin.conf
            </VirtualHost>
            
            # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
            
            
            
          • @andrewobenreder Something is completely wrong. Are you sure you're on the right server?
            All your websites are running Nginx and controlled via Plesk - or so it seems.
            It is hosted on 198.199.76.32 - is that your droplet IP?
            @jtittle There's conf file, in case you missed it.

          • @hansen Yes, the droplet ip is 198.199.76.32 and it's definitely the correct one.

          • @andrewobenreder Okay, but you're using Nginx as your front end server. And you're also running Apache, but seems like it's running on http://198.199.76.32:7080/

          • @hansen I guess so, I just know there were settings for both configured in Plesk or something.

  • @andrewobenreder

    The user www-data would be the user and group in this case (as noted in your first post).

    Without looking at the VirtualHost blocks and knowing what kind of sites we're working with, it's a little hard to pinpoint what could be wrong.

    For example, this could be a common issue with Apache and mod_php, in which case, since it's disabled by default, we'd want to turn on error display in php.ini by finding:

    display_errors = off
    

    and setting it to:

    display_errors = on
    

    You would then restart Apache and reload your page. If this was a PHP script, you should now be able to see errors being displayed which may be more beneficial in this case since there are times that logs just don't log as they should.

    If that doesn't help and doesn't yield an error (because you're not running PHP, or otherwise), then we need more information and we need to know more details so we can better help you.

@andrewobenreder @hansen

Starting a new reply as the other was maxed out.

Now that I can see the "File Not Found" using the IP address, that's most likely an issue with NGINX, not Apache and also an issue with permissions. I've seen the same error on proxy setups with NGINX before and it falls back on PHP-FPM in most cases.

So if you have NGINX in front of Apache and setup as a proxy (NGINX on Port 80/443, Apache on Port 7080, etc), then I'd take a look at your PHP-FPM configuration and if possible, post that as well.

Specifically, we'd need to look at the location block that handles PHP connections for NGINX.

  • @jtittle
    But "File not found" is available directly through the Apache port. And neither Nginx or Apache will show an error like that - the default template for errors looks different.
    I've never worked with Plesk, but couldn't it be some configuration of how that works, which has been messed up by chown'ing everything to www-data?
    The domains are visible in apachelog.pdf - muvtest[dot]space muvmag[dot]com muvmentlab[dot]com

    • @andrewobenreder @hansen

      I was thinking the same, though there's a lot going on here and it's hard to pinpoint without seeing 100% of the configuration and knowing exactly how everything has been setup.

      As I'm not familiar with how Plesk works modern-day (last I used it was ran by Parallels), it's hard to really troubleshoot as would normally be the case (going back to the above).

      ...

      When it comes to Plesk, cPanel, VestaCP, etc -- you shouldn't need to physically modify any permissions or ownership as that should be managed either by the CP or SFTP when you're uploading files.

      Whatever permissions are set by default are what should be used -- tampering with them often leads to an unstable environment or, best case, any of the changes you made will be overwritten by the control panel when it updates. The design is normally to be simple and geared towards non-sysadmins, so when you get in to modifying any aspect of the existing environment, things you wouldn't expect can start to happen.

      ...

      That being said, if NGINX was installed manually, then that's most likely one issue as you shouldn't be installing anything on the server that isn't designed to work with Plesk either through a module, plugin, or core feature.

      If it was installed through a module, plugin, or core feature, and you can disable it, I would for now and allow Apache to take over as the primary web server until we can get this all wrapped up and working as it should (i.e. Apache accepting requests on Port 80/443).

      Once Apache is the default web server, and with NGINX out of the picture, test a few more requests and let the log fill. Then check the logs again and see if anything is being logged.

      So we'd run the command below again (after you've made the above changes).

      tail -50 /var/log/apache2/error.log
      

      If nothing is changing in the log, then you need to check the Apache configuration and make sure the chown you've set on the files is equal to that of the user:group that Apache is running as.

      If that still is not working, then we'd need to look at the VirtualHost files again as the one that you posted isn't valid for anything other than IP based access since it doesn't tie to a domain.

      i.e. ServerName is commented out.

      The only valid location where the VirtualHost block you posted will pull from is:

      /var/www/html
      

      Thus if files don't exist in /var/www/html, then the files will result in a not found error.

  • Not entirely sure how to copy all of the code from the config file and I am only able to select what the terminal shows.

    Otherwise, it could be a Plesk conflict with Nginx or Apache. Plesk has been known to conflict with certain changes in the terminal without turning off the panel services first.

Have another answer? Share your knowledge.