1

There is a chance this has been answered elsewhere - I have searched as thoroughly as I can here and elsewhere.

I have the following errors on my site, wonkylogic.co, (hosted on LAMP server on Digital Ocean, I followed their tutorials):

  1. Could not create directory for theme installation. I manually created the directory over ssh to fix this; but may still be relevant to my other errors.
  2. When updating a page: “Publishing failed. The response is not a valid JSON response.” I’ve found various “solutions” to this: editing .htaccess multiple ways, editing Apache config, editing urls in mysql database. Tried them all and they didn’t fix anything. Change permalinks to plain or /index.php/<post_name>. Changing permalinks works - I can update pages. But obviously this isn’t a real solution because now I have SEO unfriendly urls and all external links to my site are broken.
  3. Navigation to webpages generates a 404 error. This is fixed by changing the permalinks as in 2. above. Again not an ideal fix.

So the overarching questions are “Why is my site broken this way?” and “How do I fix the root problem?”

Additional context: I migrated my site from shared hosting to Digital Ocean using WP-migrate plugin. It appeared to work for a while, got totally broken after installing SSL with Let’s encrypt. I’ve basically rebuilt the LAMP stack and after much blood sweat and tears got my site vaguely visible as it is now (http only right now - one step at a time).

As an interim measure I will set up some custom redirects to the new urls for external visitors using a plug-in I’ve found.

Update: it seems that my website may not even be accessible, I'm not sure why but I can access it via Safari, but not with Chrome or Firefox.

Seeing what's in .htaccess was requested.

==================== .htaccess ====================                                                
#Block the include-only files.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>


# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPres>
# dynamically generated, and should only be modified via WordPress f>
# Any changes to the directives between these markers will be overwr>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
================== END .htaccess ==================
10
  • What is in your .htaccess file?
    – Q Studio
    Commented Jan 23, 2021 at 15:45
  • 1. sounds like file system permissions and ownership are improperly configured. 2. is probably any PHP error being generated while handling an AJAX request, and thus polluting the JSON response - you should be able to see the error by checking the HTTP response body using the Network tab of your browser's developer tools.
    – bosco
    Commented Jan 23, 2021 at 16:36
  • Hi @QStudio , I've added the .htaccess file contents to my OP. TBH now I'm looking at the contents afresh I don't know how some of that got in there originally (obv Wordpress added the contents in it's section) but the rewrite rules above that I don't recall putting there.
    – Dan
    Commented Jan 23, 2021 at 16:52
  • @bosco, please could you help me out by being a little more specific of what you mean by checking the "http response body …"?
    – Dan
    Commented Jan 23, 2021 at 16:53
  • If you have WP_DEBUG & WP_DEBUG_LOG enabled, these errors should also be recorded in the log. But the dev tools Network tab records HTTP requests which the web page is making. If you have the tab open and recording when you attempt to publish a post, you'll see a new request made, probably to something like index.php?rest_route= - if you select that request, and then the "Response" tab of the inspector panel for that request, you will be able to directly inspect the server's response. And there you will likely find that some extraneous output has messed up the JSON
    – bosco
    Commented Jan 23, 2021 at 18:14

1 Answer 1

0

I have finally figured out the root cause of why I was getting the invalid JSON response and why permalinks had to be set to include index.php in all urls. My Apache configuration file was not allowing overrides and I think that means Wordpress was unable to alter files in my directory. The setting for my directory was:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

This was changed to:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

Errors no longer plaguing my site. Thank you to everyone who took the time to respond.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.