To prepare for lab day make sure the API for your blog.yourdomain Wordpress
install is working. Visit https://blog.yourdomain/wp-json/wp/v2. This will
likely produce a 404 (page not found) response. If that is the case you'll need to
follow the instructions below. If it happens to produce a large block of JSON text
then you can skip the remaining steps.
- Make sure
mod_rewrite
is installed in apache: sudo a2enmod rewrite
- In Wordpress go to the dashboard -> Settings -> Permalinks. Make sure index.php
is removed from the URL.
- Edit your the SSL version of your blog.yourdomain.conf to add lines
similar to these:
<Directory "/var/www/live/blog.yourdomain/wordpress">
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
</Directory>
- Restart apache
- Revisit the URL in your browser and verify you now get a JSON response.
- We'll make use of your favoite JSON tool, jq, again, so make sure it is installed.
sudo apt install jq
- Test the install from browser and using curl from the command-line:
curl https://blog.yourdomain/wp-json/wp/v2 # a wall of JSON code
curl https://blog.yourdomain/wp-json/wp/v2 | jq . -C # pretty JSON w/ colors
curl https://blog.yourdomain/wp-json/wp/v2 | jq . -C | less -R # pretty & scrollable
Now that the API is configured and working take a moment to read through this site
which gives very helpful examples of using jq:
https://shapeshed.com/jq-json/
Begin working through the instructions given for
Homework #9