Hi there,
For a new project I want to try out a headless wordpress setup as described in this article and dettach the site’s front-end with the backend. I only want to use Wordpress for it’s REST API and retrieve data to use in a React front-end.
Ideally I would like to continue using Trellis for local development, remote server provisioning and deploying my site etc.
So first of all I created a blank and stripped down wordpress theme for just setting up my custom post types, acf, wordpress hooks etc.
Initially I left the Trellis config to default for setting up Worpdress.
In bedrock’s web/index.php
I set WP_USE_THEMES to false:
define('WP_USE_THEMES', false);
Now I succesfully tested my API endpoints:
http://example.test/wp-json/wp/v2/posts/1
http://example.test/wp-json/acf/v3/posts/1
Now I’m struggling how to use a separate frontend folder in Bedrock’s web root, because http://example.test/ will obviously still load web/index.php
.
I was thinking I could just change the wp_home address to http://example.test/wp/ and use the endpoints like this in order to use a dettached frontend in the web root:
http://example.test/wp/wp-json/wp/v2/posts/1
http://example.test/wp/wp-json/acf/v3/posts/1
But even after re-provisioning these result in Nginx 500 Internal Server Errors (the backend itself works fine by the way). Normal page permalinks also result in a 500 Internal Server Error with this setup.
After some research I found this topic suggesting I should edit the nginx.conf and add these lines:
location ^~ /wp {
root /var/www/example.com;
index index.php index.html index.htm;
try_files $uri $uri/ /wp/index.php;
location ~ \.php {
fastcgi_split_path_info ^(.*\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
}
}
But I was wundering where I should add this in the ansible playbook or if anyone has any other suggestions how this setup can be achieved with the least possible adjustment to the Trellis setup?
Any tips are welcome, thanks!