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

nginx server

Starting several years ago, the apache web server is no longer active by default.

After asking ChatGPT, it advised to use nginx as a web server.

ChatGPT Answer

Here’s the simplest, cleanest way to configure nginx (Homebrew version) on macOS to serve files from your ~/Sites directory.


✅ Step-by-step: Configure nginx to use ~/Sites as the web root

1. Install nginx with Homebrew (if not installed)

brew install nginx

Start nginx:

brew services start nginx

Check status:

brew services info nginx

✅ 2. Find the nginx config directory

Homebrew installs nginx configs here:

/opt/homebrew/etc/nginx/

(Main config file is nginx.conf)


✅ 3. Create a server block that points to ~/Sites

Create a new config file:

nano /opt/homebrew/etc/nginx/servers/sites.conf

(If servers/ does not exist, create it.)

Add this:

server {
    listen 8080;   # avoid port 80 permissions
    server_name localhost;

    root /Users/YOURUSERNAME/Sites;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
}

Replace:

/Users/YOURUSERNAME/Sites

with your actual username.

You can find your username with:

whoami

✅ 4. Make sure the servers directory is included in nginx.conf

Open:

nano /opt/homebrew/etc/nginx/nginx.conf

Look for a block like:

include servers/*;

If missing, add it inside the http { ... } block:

http {
    ...
    include servers/*;
}

Save & quit.


✅ 5. Test configuration

nginx -t

If you see:

syntax is ok
test is successful

you’re good.


✅ 6. Restart nginx

brew services restart nginx

✅ 7. Test in the browser

Visit http://localhost:8080.

You should now see files served from: ~/Sites.


Optional: Serve on port 80

macOS protects port 80, so you’d need sudo:

sudo /opt/homebrew/bin/nginx

OR update nginx.conf to:

listen 80;

But usually it’s easier to stick with 8080.


### Results

I have not yet tested the results.