Grav-plugin-admin: 500 Error Apache - PHP 7.0

Created on 23 Oct 2016  路  8Comments  路  Source: getgrav/grav-plugin-admin

Getting 500 on prod server running ubuntu, apache, php 7.0 ..
Please help. I was able to run cms without an issue locally.

Here is the virtual host info, mod_rewrite is enable,

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/web.org/public_html

    ServerName web.org
    ServerAlias *.web.org

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory "/var/www/web.org/public_html">
Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted


RewriteEngine On

## Begin RewriteBase
# If you are getting 500 or 404 errors on subpages, you may have to uncomment the RewriteBase entry
# You should change the '/' to your appropriate subfolder. For example if you have
# your Grav install at the root of your site '/' should work, else it might be something
# along the lines of: RewriteBase /<your_sub_folder>
##

# RewriteBase /

## End - RewriteBase

## Begin - X-Forwarded-Proto
# In some hosted or load balanced environments, SSL negotiation happens upstream.
# In order for Grav to recognize the connection as secure, you need to uncomment
# the following lines.
#
# RewriteCond %{HTTP:X-Forwarded-Proto} https
# RewriteRule .* - [E=HTTPS:on]
#
## End - X-Forwarded-Proto

## Begin - Exploits
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Grav
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Exploits

## Begin - Index
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
## End - Index

## Begin - Security
# Block all direct access for these folders
RewriteRule ^(.git|cache|bin|logs|backup|webserver-configs|tests)/(.*) error [F]
# Block access to specific file types for these system folders
RewriteRule ^(system|vendor)/(.*)\.(txt|xml|md|html|yaml|php|pl|py|cgi|twig|sh|bat)$ error [F]
# Block access to specific file types for these user folders
RewriteRule ^(user)/(.*)\.(txt|md|yaml|php|pl|py|cgi|twig|sh|bat)$ error [F]
# Block all direct access to .md files:
RewriteRule \.md$ error [F]
# Block all direct access to files and folders beginning with a dot
RewriteRule (^|/)\.(?!well-known) - [F]
# Block access to specific files in the root folder
RewriteRule ^(LICENSE.txt|composer.lock|composer.json|\.htaccess)$ error [F]
## End - Security

</Directory>

</VirtualHost>

Also left the .htaccess on site directory, but still getting 500, The permissions were given properly as well.. Please help.

Most helpful comment

Hello,

I had a similar error and it was because of file permissions.

In the documentation, on permissions page I found that the following line was confusing, I didn't get the humour:
chown -R joeblow:staff .

I would rather prefer something more direct like
chown -R myuser:www-data .
or
chown -R myuser:http .

Many thanks!

All 8 comments

Did you already try the "usual suspects" for 500 errors? https://learn.getgrav.org/troubleshooting/internal-server-error

Yup already tried, thanks for your response tho, I am on a virtual host environment running apache and Ubuntu.

I am afraid the problem might be that I'm using PHP 7.0, anyone using 7 successfully?

We're all (dev team) using PHP 7 since its pre-releases, no issue with it.

Is there something in the PHP error log?

Thanks for the reply @flaviocopes

PHP Fatal error:  Uncaught RuntimeException: Opening file for writing failed on error fopen(/var/www/example.com/public_html/cache//compiled/files/44df1f1830a764eb1a541139e6d066a5.yaml.php): 
failed to open stream: Permission denied in /var/www/example.com/public_html/vendor/rockettheme/toolbox/File/src/File.php:202\nStack trace:\n#0 /var/www/example.com/public_html/vendor/rockettheme/toolbox/File/src/File.php(316): 
RocketTheme\\Toolbox\\File\\File->lock()\n#1 /var/www/example.com/public_html/vendor/rockettheme/toolbox/File/src/PhpFile.php(31): RocketTheme\\Toolbox\\File\\File->save(Array)\n#2 /var/www/example.com/public_html/system/src/Grav/Common/File/CompiledFile.php(66): 
RocketTheme\\Toolbox\\File\\PhpFile->save(Array)\n#3 /var/www/example.com/public_html/system/src/Grav/Common/Config/Setup.php(178): Grav\\Common\\File\\CompiledYamlFile->content()\n#4 /var/www/example.com/public_html/system/src/Grav/Common/Processors/SiteSetupProcessor.php(17): 
Grav\\Common\\Config\\Setup->init()\n#5 /var/www/example.com/public_ht in /var/www/example.com/public_html/vendor/rockettheme/toolbox/File/src/File.php on line 202

Ok looks like a permissions problem on the cache folder, see https://learn.getgrav.org/troubleshooting/permissions

Thanks a lot! indeed was permission problems and corrupted dependencies. After trying again the permison part, nothing changed.

#!/bin/sh
chown myuser:staff .
chown -R myuser:staff *
find . -type f | xargs chmod 664
find ./bin -type f | xargs chmod 775
find . -type d | xargs chmod 775
find . -type d | xargs chmod +s
umask 0002

Since you point at the cache folder, i went ahead and chmod -R 0777 cache/ just for kicks, and i was able to advanced to the next screen-shot, in the page - Issues Found Please Review and Resolve before continuing... I was able to see the dependencies that got corrupted, and re-installed them succesfully.

After that i am still getting the error page and now it says;

/var/www/web.org/public_html/cache exists but is not writeable

/var/www/web.org/public_html/logs exists but is not writeable

/var/www/web.org/public_html/images exists but is not writeable

/var/www/web.org/public_html/assets exists but is not writeable

/var/www/web.org/public_html/user/data exists but is not writeable

/var/www/web.org/public_html/backup exists but is not writeable

/var/www/web.org/public_html/tmp exists but is not writeable

The only way so far i have found to by pass this error is to set those folder to find . -type d -exec chmod -R 0777 {} \; for time being, instead of 775 like it says on the site. I strongly feel this is not secure, i will try to lower permission on directory folders after installation to see if it works.

I was able to figure it out, The problem was a server misconfiguration. But for sakes of other people time, i was given an ssh account with a non-root user but added to the sudo groups.

I created the bash script as instructed on the documentation and ran it.
nano perms.sh then;

#!/bin/sh
chown MyUser:MyUser .
chown -R MyUser:MyUser *

find . -type f | xargs chmod 664
find ./bin -type f | xargs chmod 775
find . -type d | xargs chmod 775
find . -type d | xargs chmod +s

umask 0002

After running it and heading to the site, i will get 500 error, all php mods were enable, as well has .htaccess. The problem for me was, i was giving a non-global user.

To find which user apache was running on, i did ps aux | egrep '(apache|httpd)' to then find my global user was www-data .....

So changed back the script to the proper user, and website its working great now! thanks!

Hello,

I had a similar error and it was because of file permissions.

In the documentation, on permissions page I found that the following line was confusing, I didn't get the humour:
chown -R joeblow:staff .

I would rather prefer something more direct like
chown -R myuser:www-data .
or
chown -R myuser:http .

Many thanks!

Was this page helpful?
0 / 5 - 0 ratings