Running build-in tomcat server

It is possible to deploy Jekyll sites locally, because OSX has a build-in Apache tomcat server. The local sites reside under ~/Sites. However, the setup of this server often changes with new versions of OSX.

John does a great job on documenting how to do this on Apple Community. For the version Sonoma 14.0, these instructions can be seen here.

For Ventura, the instructions can be found here.

If you follow these instructions, you should be able to run http://localhost/, and it should respond with:

It works!

If you browse to http://localhost/~mmgreiner/, you should see the files:

Index of ~/mmgreiner

Or, if you have enabled the english language in /etc/apache2/users/mmgreiner.conf with

AddLanguage en .en

you should see the content of the file ~/Sites/index.html.en, which could be:

<html>
    <body>
        <h1>My site works. File at /Users/mmgreiner/Sites </h1>
    </body>
</html>

Deploying Jekyll static site locally

To deploy your Jekyll generated static sites locally, use

jekyll build --drafts -d ~/Sites/mypages --baseurl "~mmgreiner/mypages"

If you now browse to http://localhost/~mmgreiner/mypages/, you should see your Jekyll sites.

Deploy Hugo locally

I later moved all the Jekyll pages to Hugo. To publish and deploy the Hugo site locally, use the following command

hugo --destination ~/Sites/mypages --baseURL http://localhost/~mmgreiner/mypages

Make sure that the destination directory name corresponds to the last name of the baseURL, in this case mypages.

You should now see your pages at http://localhost/~mmgreiner/mypages/.

Potential problems

If the server cannot be found, it may be, that apache is not running. Check with:

apachectl

This may throw an error like this:

% apachectl
[Fri Dec 08 09:25:16.726003 2023] [so:error] [pid 18207] AH06663: Unable to find code signature authority 
on module at /usr/local/opt/php/lib/httpd/modules/libphp.so that matches authority name "Markus Greiner" configured on LoadModule directive.
httpd: Syntax error on line 192 of /private/etc/apache2/httpd.conf: 
Code signing error - not loading module at: /usr/local/opt/php/lib/httpd/modules/libphp.so

Basically, this may happen after you have upgraded apachectl. The code needs to be signed again, which is a complex procedure.

From stackoverflow:

To fix the above problem, I created Certificate Authority in mac machine by following - https://www.simplified.guide/macos/keychain-ca-code-signing-create and trying to codesign to sign the AEM Dispatcher module with below command

Only once, you have to create yourself a certificate. This is in detail described in https://www.simplified.guide/macos/keychain-cert-code-signing-create

Everytime php is updated, for instance through a brew update command, the libphp.so file needs to be signed again.

  • First, open Keychain Access, the Keychains, not the passwords. There, check that a certificate for Markus Greiner exists.
  • Now in the terminal, do:
% codesign --sign "Markus Greiner" --force --keychain ~/Library/Keychains/login.keychain-db /usr/local/opt/php/lib/httpd/modules/libphp.so

Restart the server with:

% sudo apachectl