Skip to content

Instantly share code, notes, and snippets.

@carsuki
Last active May 13, 2024 13:12
Show Gist options
  • Save carsuki/cc2f460529143f01f18beec6d908d6c8 to your computer and use it in GitHub Desktop.
Save carsuki/cc2f460529143f01f18beec6d908d6c8 to your computer and use it in GitHub Desktop.
Guide to set up Rehike on macOS

⚠️ These instructions may not work on Chrome due to an unknown problem with SSL. At the moment I'm unsure of the cause or how to fix it. Firefox has been tested and works.

Clarifications

While I've tried to make these instructions fairly comprehensive, some knowledge of the command line will be helpful when following this guide.

You may find it useful to cross reference with the official Rehike install guide, in case I've missed something or new information is added before I can update this guide.

The minimum macOS version listed has not been extensively tested and is solely based on claims from XAMPP and MacPorts's "Port Health" sections for Apache and PHP 8.

Prerequisites

To install Rehike you currently need the following prerequisites:

  • Apache
  • PHP 8.0 or greater
  • Mac OS X 10.7 (Lion) or higher, running on an Intel or Apple Silicon Mac
  • Git (recommended but optional)

A version of Apache is present on your Mac out of the box, but it's not recommended for use here. It's likely out of date, and as of macOS Monterey, no longer includes PHP.

XAMPP is a simple and easy way of installing Apache and PHP. You can uncheck the rest of the components in the installer. We only need Apache and PHP for these purposes.

  • Included with your XAMPP installation is a graphical app for managing your Apache server. This app is not useful for this guide—everything will be done through the terminal.

A package manager such as Homebrew or MacPorts is recommended to install Git.

  • Note that Homebrew only supports macOS 11 (Big Sur) and up. If you're on 10.15 (Catalina) or lower, you must use MacPorts.

Setting up Rehike

As mentioned in the last section, you're highly encouraged to use Git to install Rehike. This way you can easily pull new Rehike updates with git pull.

Full instructions on how to update this way are available later in the guide.

Install Rehike with Git

Find the web root of your Apache installation. Using XAMPP, it's /Applications/XAMPP/xamppfiles/htdocs.

Change to the directory that contains the current web root.

cd /Applications/XAMPP/xamppfiles

Now we'll replace Apache's default web root folder with Rehike.

  • You might need to run these commands with sudo.
rm -r htdocs
git clone https://github.com/Rehike/Rehike htdocs

Restart Apache for the changes to take effect.

sudo /Applications/XAMPP/xamppfiles/bin/apachectl restart

Advanced users: You may find it convenient to add an alias for /Applications/XAMPP/xamppfiles/bin/apachectl in your bashrc or zshrc.

Rehike should now be your new web root. You can test by navigating to localhost in your browser.

Proxying Rehike via Hosts File

Download the first linked file in this section of the Rehike documentation by clicking on the first link.

Two links, Apache certificates and browser certificate. The first link is outlined in red.

Then, to download the second file, right click the second link and select Save Link As. (if using Firefox/Chrome - in Safari it's called Download Linked File). You may need to add .pem to the end of the file before saving if it is not there already. If there is no file extension, like in this example, your browser will save it as a text file instead of a certificate.

The same two links from the previous image. Context menu is shown with the option to "Save Link As" highlighted.

You should get a zipped folder named apache_conf_ssl.zip from the first link and a certificate file named rehike_master_cert.pem from the second.

A more detailed explanation of their purpose is also available at that page.

Apache certificates

Unzip the apache_conf_ssl.zip you downloaded in the previous step. You should see what's in the picture below. Copy all 3 items to /Applications/XAMPP/xamppfiles/etc/conf. Hold on to this folder, it's also needed in the next step.

Finder window with three folders visible

System certificates

Now, double-click the rehike_master_cert.pem certificate. The Keychain Access app should open up. Ensure the login keychain is currently selected in the menu on the far left.

Without closing Keychain Access, bring up the Finder and navigate back to the folder you copied the Apache certificates from. Inside the ssl.crt folder should be a file called server.crt. Double click it and Keychain Access should be brought to the front. If not, just bring it up manually.

Scroll down to the bottom of the list and you should see two certificates named www.youtube.com.

Keychain Access window

One by one, right click on each of the two www.youtube.com certificates and select Get Info. Ensure that the Subject and Issuer for both certificates is Taniko Yamamoto.

Now while Get Info is still open on both certificates, click to expand the Trust section. Change When using this certificate: to Always Trust for each certificate. Click the close button on the Get Info windows and authenticate yourself when prompted.

Get Info menu on one certificate showing the correct organization being Taniko Yamamoto

Setting up the Rehike server

Open the file /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf in your text editor of choice. Add the following designation to the end of it:

<VirtualHost 127.0.0.1:443>
   ServerName www.youtube.com
   DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
   SSLEngine on
   SSLCertificateFile "etc/conf/ssl.crt/server.crt"
   SSLCertificateKeyFile "etc/conf/ssl.key/server.key"
   <Directory "/Applications/XAMPP/xamppfiles/htdocs">
      AllowOverride All
      Require all granted
   </Directory>
</VirtualHost>

Next, open /Applications/XAMPP/xamppfiles/etc/httpd.conf in your text editor. Find the Listen section. There should be a line reading Listen 80 already there, near line 50 or so. Underneath it, on a new line, add Listen 443.

Apache Listen config

Restart Apache for the new configuration to take effect.

sudo /Applications/XAMPP/xamppfiles/bin/apachectl restart

Setting up native redirection

Open /etc/hosts in your text editor of choice. Ensure you run the editor with sudo. In the example, I use nano to edit.

sudo nano /etc/hosts

This file is important for manually defining DNS resolutions. Avoid editing any entries that are already there.

Underneath the existing localhost entry at the top, while above the broadcasthost line, manually type in the following additions:

127.0.0.1 www.youtube.com
:: www.youtube.com
127.0.0.1 youtube.com
:: youtube.com

It should look something like the image below. Note the placement of my own entries: underneath the first localhost but above broadcasthost. Single-line comments are supported with hashes: ## like this if you want to leave yourself a note.

Terminal window showing GNU nano editing a hosts file

Double check your work. When you're sure you're done, save the file and exit your editor.

Run Apache at login

Advanced users: you could try adding /Applications/XAMPP/xamppfiles/bin/apachectl start to your crontab, but I don't know enough about cron to properly test this.

A simpler solution is creating a workflow in Automator. Open Automator and click New Document at the bottom of the window that pops up. Select the Application type and click Choose. In the search bar, look for Run Shell Script and drag it into the workflow view on the right.

In the shell script text box, just enter /Applications/XAMPP/xamppfiles/bin/apachectl start and save the application in Automator.

Now open System Preferences and navigate to Login items. On Ventura it's under General. At the top there should be a list of apps you have set to open when you login. Regardless of how populated the list is, there should be a plus on the bottom left of it. Click it and add your new Automator app. Now the command to start Apache should run when you log in.

macOS Login Items settings

Updating Rehike

Having Git installed will be required for these steps. I won't be providing instructions on how to update Rehike without Git in this guide, as it's much more time consuming and not recommended. Refer to this section of the official Rehike documentation instead, if necessary.

To update Rehike, first open your terminal and change directory to where you previously installed it:

cd /Applications/XAMPP/xamppfiles/htdocs

Now, just run:

git pull

The resulting message will depend on whether Rehike has updated or not. If you see Already up to date, there is currently no update. If you see something more like this, then there was an update. Rehike is still in active development, so try to check for updates at least every few days so you don't miss out on new fixes and changes.

Advanced users: You may find it useful to automate this to run at every startup.

Troubleshooting

Safari SSL errors

Tried loading YouTube but just see an error that looks something like this?

WebKit private connection error

This is likely a result of improperly set up certificates. Open Keychain Access and ensure you have two www.youtube.com certificates. Make sure both are issued by Taniko Yamamoto and the trust is set to Always Trust on both.

Safari will always see the certificates as "not standards compliant" if the system isn't told to Always Trust them. This usually also applies to other WebKit browsers.

Viewing certificates in Safari

Apache says the port is already in use?

If you try starting Apache and it throws an error saying the port or address is in use, this may be a conflict with macOS's built in version of Apache. Many macOS versions come with older, now outdated versions of Apache out of the box.

You'll need to disable the built in Apache altogether with the following commands:

sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 

If the second command throws an error, such as this, try running this instead:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null

I followed all the instructions to set Apache up and YouTube still doesn't load!

Check your httpd.conf and ensure your ServerRoot is set to the right directory.

While in httpd.conf, search for the Virtual hosts line (command+F) and ensure the line below it is not commented out. It should look like this: Screenshot of Apache config

Rehike starts with a fatal error

This is likely due to Rehike not being able to write to its install directory. Run the following command to fix this:

chmod -R 777 /Applications/XAMPP/xamppfiles/htdocs

Something else?

Also check out the troubleshooting section of the official Rehike guide. There are more general troubleshooting steps available there. I mainly wanted to focus on macOS specific problems in this section.

@TheR1chard
Copy link

please just make a video about it

@Meowmew124
Copy link

can you tell me where rehike_master_cert.pem is? If you say it's located in the file I've just downloaded, why can't I find it?

@carsuki
Copy link
Author

carsuki commented Feb 4, 2024

@Meowmew124 Looks like the Rehike devs have changed that part of the docs since I wrote this. rehike_master_cert.pem is now at this link:
Screenshot 2024-02-03 at 6 30 49 PM
Updating the guide to reflect this now, thanks.

@Meowmew124
Copy link

Now how do I download the browser certificate because when I try to download it, it opens a link showing its code?

@carsuki
Copy link
Author

carsuki commented Feb 21, 2024

@Meowmew124 Right click on the link and click Save Link As (if using Chrome/Firefox - in Safari it's called Download Linked File). Make sure it has .pem at the end of the name. If it's just rehike_master_cert with nothing at the end, it will be saved as a .txt file, so add .pem to the end to prevent that. Will also add this info to the guide

@Meowmew124
Copy link

@carsuki Thanks, but now it shows as this ↓
Screenshot 2024-02-21 at 2 24 11 PM

@carsuki
Copy link
Author

carsuki commented Feb 21, 2024

@Meowmew124 What browser are you using? I just tested the steps and got a valid certificate. Does the downloaded file have this icon in the Finder?

@Meowmew124
Copy link

@carsuki Wait, It just randomly changed into a certificate. for like 26 minutes, it showed as the image from the top, now it turned into a certificate.

@Meowmew124
Copy link

So uh, @carsuki, once I have followed your directions at the end, and did troubleshooting, I got this ↓
Screenshot 2024-02-21 at 3 50 48 PM

@Meowmew124
Copy link

How do I quit the rehike thing?

@carsuki
Copy link
Author

carsuki commented Feb 22, 2024

@Meowmew124 YouTube is probably caching the Polymer layout. Try reloading the page without cache, Cmd+Shift+R is how to do that IIRC.

@Meowmew124
Copy link

so uh i deleted xampp and the certificates and now the website is f*cked

@Meowmew124
Copy link

I thought that would fix it but the problem is still there 😭😭😭😭

@Meowmew124
Copy link

Meowmew124 commented Feb 22, 2024

Now it giving me an SSL error
Screenshot 2024-02-21 at 4 41 02 PM

Pls help

@carsuki
Copy link
Author

carsuki commented Feb 22, 2024

@Meowmew124 I didn't have Chrome installed but I downloaded it to test and I get the same error as you. I'm honestly stumped. Everything works completely fine in Firefox and Safari on this same machine, yet somehow not in Chrome. Not sure how to fix it, sorry. Certificate stuff is far above my skill level and I don't know the inner workings of how Rehike handles all of that.

If you want to uninstall, basically follow the instructions in reverse but without the Apache configuration (since you're removing it). Remove the edits you made to your hosts file for Rehike. Disable Apache with /Applications/XAMPP/xamppfiles/bin/apachectl stop and then trash the entire XAMPP folder plus its manager app. That should safely revert you back to regular YouTube.

@Meowmew124
Copy link

@carsuki IIIIIIIIIIIIII'm afraid that's faaaar too late

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment