bitnami / vms

Bitnami VMs
https://bitnami.com
Other
206 stars 44 forks source link

[Wordpress] WP-Rocket plugin can't write to .htaccess #717

Closed y-chen closed 1 year ago

y-chen commented 1 year ago

Describe your issue as much as you can

I am having this warning after restoring a Wordpress site on an AWS Lightsail instance running Bitnami Wordpress image:

image

I can't find .htaccess anywhere, reading the docs the file name and location has been changed but also how it work.

On this point I didn't get how to edit the files to dismiss that warning. What I tried is to change AllowOverride None to AllowOverride All in /opt/bitnami/apache/conf/vhosts/APPNAME-vhost.conf and in /opt/bitnami/apache/conf/vhosts/htaccess/APPNAME-htaccess.conf I added another Directory tag like this:

<Directory "/opt/bitnami/wordpress/wp-content/plugins/wp-rocket">
# BEGIN WP Rocket v3.10.9
# Use UTF-8 encoding for anything served text/plain or text/html
AddDefaultCharset UTF-8
# Force UTF-8 for a number of file formats
<IfModule mod_mime.c>
AddCharset UTF-8 .atom .css .js .json .rss .vtt .xml
</IfModule>

# FileETag None is not enough for every server.
<IfModule mod_headers.c>
Header unset ETag
</IfModule>

# Since we’re sending far-future expires, we don’t need ETags for static content.
# developer.yahoo.com/performance/rules.html#etags
FileETag None

<IfModule mod_alias.c>
<FilesMatch "\.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$">
<IfModule mod_headers.c>
Header set X-Powered-By "WP Rocket/3.10.9"
Header unset Pragma
Header append Cache-Control "public"
Header unset Last-Modified
</IfModule>
</FilesMatch>

<FilesMatch "\.(css|htc|js|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$">
<IfModule mod_headers.c>
Header unset Pragma
Header append Cache-Control "public"
</IfModule>
</FilesMatch>
</IfModule>

<IfModule mod_mime.c>
    AddType image/avif                                  avif
    AddType image/avif-sequence                         avifs
</IfModule>
# Expires headers (for better cache control)
<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault                              "access plus 1 month"
    # cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
    ExpiresByType text/cache-manifest           "access plus 0 seconds"
    # Your document html
    ExpiresByType text/html                     "access plus 0 seconds"
    # Data
    ExpiresByType text/xml                      "access plus 0 seconds"
    ExpiresByType application/xml               "access plus 0 seconds"
    ExpiresByType application/json              "access plus 0 seconds"
    # Feed
    ExpiresByType application/rss+xml           "access plus 1 hour"
    ExpiresByType application/atom+xml          "access plus 1 hour"
    # Favicon (cannot be renamed)
    ExpiresByType image/x-icon                  "access plus 1 week"
    # Media: images, video, audio
    ExpiresByType image/gif                     "access plus 4 months"
    ExpiresByType image/png                     "access plus 4 months"
    ExpiresByType image/jpeg                    "access plus 4 months"
    ExpiresByType image/webp                    "access plus 4 months"
    ExpiresByType video/ogg                     "access plus 4 months"
    ExpiresByType audio/ogg                     "access plus 4 months"
    ExpiresByType video/mp4                     "access plus 4 months"
    ExpiresByType video/webm                    "access plus 4 months"
    ExpiresByType image/avif                    "access plus 4 months"
    ExpiresByType image/avif-sequence           "access plus 4 months"
    # HTC files  (css3pie)
    ExpiresByType text/x-component              "access plus 1 month"
    # Webfonts
    ExpiresByType font/ttf                      "access plus 4 months"
    ExpiresByType font/otf                      "access plus 4 months"
    ExpiresByType font/woff                     "access plus 4 months"
    ExpiresByType font/woff2                    "access plus 4 months"
    ExpiresByType image/svg+xml                 "access plus 4 months"
    ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
    # CSS and JavaScript
    ExpiresByType text/css                      "access plus 1 year"
    ExpiresByType application/javascript        "access plus 1 year"
</IfModule>
# Gzip compression
<IfModule mod_deflate.c>
# Active compression
SetOutputFilter DEFLATE
# Force deflate for mangled headers
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
# Don’t compress images and other uncompressible content
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|rar|zip|exe|flv|mov|wma|mp3|avi|swf|mp?g|mp4|webm|webp|pdf)$ no-gzip dont-vary
</IfModule>
</IfModule>

# Compress all output labeled with one of the following MIME-types
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
                                  application/javascript \
                                  application/json \
                                  application/rss+xml \
                                  application/vnd.ms-fontobject \
                                  application/x-font-ttf \
                                  application/xhtml+xml \
                                  application/xml \
                                  font/opentype \
                                  image/svg+xml \
                                  image/x-icon \
                                  text/css \
                                  text/html \
                                  text/plain \
                                  text/x-component \
                                  text/xml
</IfModule>
<IfModule mod_headers.c>
Header append Vary: Accept-Encoding
</IfModule>
</IfModule>

# END WP Rocket
</Directory>

But then the web server doesn't go up anymore and I get a 502 Bad Gateway error.

How can I correctly dismiss that warning message?

jotamartos commented 1 year ago

The htaccess configuration looks good. Please remember that you should have edited an existing "/opt/bitnami/apache/conf/vhosts/htaccess/wordpress-htaccess.conf" file, is that correct?

Regarding the permissions issue, you can try reconfiguring the permissions allowing daemon to write in all folders and files

https://github.com/bitnami/vms/issues/22#issuecomment-1143906974

samuelm00 commented 1 year ago

@jotamartos having the same issues, I was able to add the config for wp-rocket but I still see the warning. I don't think that it is a permission issue:

ls -l inside /opt/bitnami/conf/vhosts/htaccess -rw-r--r-- 1 bitnami bitnami 6075 Mar 2 08:47 wordpress-htaccess.conf -rw-r--r-- 1 root root 5310 Feb 27 12:17 wordpress-htaccess.conf.save

ls -l inside /opt/bitnami/wordpress -rw-rw-r-- 1 bitnami daemon 405 Dec 15 12:12 index.php drwxrwxr-x 2 bitnami daemon 4096 Dec 15 12:21 licenses -rw-rw-r-- 1 bitnami daemon 19915 Dec 15 12:12 license.txt -rw-rw-r-- 1 bitnami daemon 7389 Dec 15 12:12 readme.html drwxrwxr-x 2 bitnami daemon 4096 Dec 15 14:38 tmp -rw-rw-r-- 1 bitnami daemon 7205 Dec 15 12:12 wp-activate.php drwxrwxr-x 9 bitnami daemon 4096 Dec 15 12:21 wp-admin -rw-rw-r-- 1 bitnami daemon 351 Dec 15 12:12 wp-blog-header.php -rw-rw-r-- 1 bitnami daemon 2338 Dec 15 12:12 wp-comments-post.php lrwxrwxrwx 1 bitnami daemon 32 Feb 23 16:41 wp-config.php -> /bitnami/wordpress/wp-config.php -rw-rw-r-- 1 bitnami daemon 3001 Dec 15 12:12 wp-config-sample.php lrwxrwxrwx 1 bitnami daemon 29 Feb 23 16:41 wp-content -> /bitnami/wordpress/wp-content -rw-rw-r-- 1 bitnami daemon 5543 Dec 15 12:12 wp-cron.php drwxrwxr-x 27 bitnami daemon 12288 Dec 15 12:21 wp-includes -rw-rw-r-- 1 bitnami daemon 2494 Dec 15 12:12 wp-links-opml.php -rw-rw-r-- 1 bitnami daemon 3985 Dec 15 12:12 wp-load.php -rw-rw-r-- 1 bitnami daemon 49135 Dec 15 12:12 wp-login.php -rw-rw-r-- 1 bitnami daemon 8522 Dec 15 12:12 wp-mail.php -rw-rw-r-- 1 bitnami daemon 24587 Dec 15 12:12 wp-settings.php -rw-rw-r-- 1 bitnami daemon 34350 Dec 15 12:12 wp-signup.php -rw-rw-r-- 1 bitnami daemon 4914 Dec 15 12:12 wp-trackback.php -rw-rw-r-- 1 bitnami daemon 3236 Dec 15 12:12 xmlrpc.php

jotamartos commented 1 year ago

I do not know where wp-rocket is writing. I understand it's trying to write inside the wp-content folder that is a symlink to /bitnami/wordpress/wp-content. Can you check if that folder is writable by the daemon user/group?

You can also try moving the folder instead of using a symlink as explained here

https://github.com/bitnami/vms/issues/23

samuelm00 commented 1 year ago

Thanks for your response, seems like that wp-rocket wants to write wp-config.php or .htaccess.

The permissions look fine to me (/bitnami/wordpress/wp-content folder):

-rw-rw-r--  1 bitnami daemon  2475 Feb 27 06:52 advanced-cache.php
drwxrwxr-x  2 bitnami daemon  4096 Feb 23 16:43 ai1wm-backups
drwxrwxr-x  3 bitnami daemon  4096 Feb 23 17:30 backups-dup-pro
drwxrwxr-x  7 bitnami daemon  4096 Feb 23 17:30 cache
-rw-rw-r--  1 bitnami daemon    28 Feb 24 08:24 index.php
drwxrwxr-x  5 bitnami daemon 12288 Feb 24 08:25 languages
drwxrwxr-x 40 bitnami daemon  4096 Mar  2 16:00 plugins
drwxrwxr-x  3 bitnami daemon  4096 Feb 23 17:30 plugins_new
drwxrwxr-x  9 bitnami daemon  4096 Feb 23 17:30 themes
drwxrwxr-x  2 bitnami daemon  4096 Mar  2 16:00 upgrade
drwxrwxr-x 21 bitnami daemon 12288 Mar  2 17:09 uploads
drwxrwxr-x  2 bitnami daemon  4096 Feb 23 17:30 w3tc-config
drwxrwxr-x  2 bitnami daemon  4096 Feb 24 06:11 wp-rocket-config

I even tried to set /bitnami/wordpress to 777 but still, the warning persists.

y-chen commented 1 year ago

Hello,

my suspect is that the plugin isn't checking if the change is applied, but if the file writable.

Another error I had before was this one: image Adding manually the line to wp-config.php didn't fix the error, but making the file writable did.

Maybe the same is happening for .htaccess, WP-Rocket is trying to write in a file that doesn't exist in Bitnami's image.

jotamartos commented 1 year ago

You can try creating the file and set the correct permissions for the plugin to write it.

touch /opt/bitnami/wordpress/wp-content/plugins/wp-rocket/.htaccess
sudo chown bitnami:daemon /opt/bitnami/wordpress/wp-content/plugins/wp-rocket/.htaccess
sudo chmod g+w /opt/bitnami/wordpress/wp-content/plugins/wp-rocket/.htaccess

Note: I used /opt/bitnami/wordpress/wp-content/plugins/wp-rocket/.htaccess as an example path, please use the correct one.

However, I'd also contact the wp-rocket plugin's developers to let them know about this issue. If the folder is writable by the daemon user, the plugin should be able to create the file and add the needed content.

github-actions[bot] commented 1 year ago

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.

github-actions[bot] commented 1 year ago

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Issue. Do not hesitate to reopen it later if necessary.

jasperf commented 1 year ago

Where can we see complete block to be added to .htaccess . I was warned WP Rocket could not write, but I only had option to copy missing code once and do not see it now.

jotamartos commented 1 year ago

Hi @jasperf,

If you need to update the .htaccess information, you need to take into account that we disable those files by default due to security and performance reasons. You can learn more about that here:

https://docs.bitnami.com/general/apps/wordpress/administration/use-htaccess/

If you need to add new information, you will need to edit the wordpress-htaccess.conf file as explained in the docuementation and add/edit the block of code related to the folder of the .htaccess file and include the content inside. For example, if you need to create a .htaccess file inside the /opt/bitnami/wordpress/wp-content/plugins/wp-rocket folder, you will need to add/edit this block:

<Directory "/opt/bitnami/wordpress/wp-content/plugins/wp-rocket">
    NEW CODE TO ADD HERE
</Directory>
Shepdesign commented 11 months ago

Hi @jasperf,

If you need to update the .htaccess information, you need to take into account that we disable those files by default due to security and performance reasons. You can learn more about that here:

https://docs.bitnami.com/general/apps/wordpress/administration/use-htaccess/

If you need to add new information, you will need to edit the wordpress-htaccess.conf file as explained in the docuementation and add/edit the block of code related to the folder of the .htaccess file and include the content inside. For example, if you need to create a .htaccess file inside the /opt/bitnami/wordpress/wp-content/plugins/wp-rocket folder, you will need to add/edit this block:

<Directory "/opt/bitnami/wordpress/wp-content/plugins/wp-rocket">
    NEW CODE TO ADD HERE
</Directory>

What would be the general way to allow the specific plugin complete access to the .htaccess folder? I have a plugin with a folder named "hide-my-wp" that I need to give complete access to the .htaccess folder.

jotamartos commented 11 months ago

If you want to enable the usage of the .htaccess files, please set AllowOverride All in the /opt/bitnami/apache/conf/vhosts/APPNAME-vhost.conf and /opt/bitnami/apache/conf/vhosts/APPNAME-https-vhost.conf files. Remember to restart Apache for the changes to take effect.

Note: In this case replace APPNAME with wordpress

Shepdesign commented 11 months ago

Thank you, do I restart with this command?

sudo /etc/init.d/apache2 restart

jotamartos commented 11 months ago

That doesn't work with Bitnami. The script to restart the services is

sudo /opt/bitnami/ctlscript.sh restart apache
Shepdesign commented 11 months ago

Yes, I figured that out the hard way. I haven't had coffee. I will close my other ticket, too. Thanks again.