IDE + Server on Catalina

https://mallinson.ca/posts/5/the-perfect-web-development-environment-for-your-new-mac

https://discussions.apple.com/docs/DOC-250001766

Host / Computer / Internet

HostName: https://flapflap.ferociousbutterfly.com

Computer Name: SPIFFYdesign-holdME

Internet: Reachable at 73.162.197.30, no services



Network Interfaces:
Wi-Fi – IP: 10.0.0.204
Wi-Fi – 2601:645:8480:2c10:4c7:41c


Name Servers IP Address
ns1.bluehost.com. 162.159.24.80
ns2.bluehost.com. 162.159.25.175

sub-domain
flapflap .ferociousbutterfly.com. /public_html/flapflap. not redirected


Local Web Server on macOS 10.15 Catalina

Here is my definitive guide to getting a local web server running on OS X 10.15 “Catalina”. This is meant to be a development platform so that you can build and test your sites locally, then deploy to an internet server. This User Tip only contains instructions for configuring the Apache server, PHP module, and Perl module. I have another User Tip for installing and configuring , web, and services, I have found it easier to just setup the client OS version manually.

Requirements:

  1. Basic understanding of Terminal.app and how to run command-line programs.
  2. Basic understanding of web servers.
  3. Basic usage of vi. You can substitute nano if you want.

Optional: Xcode is required for adding PHP modules.

Lines in bold are what you will have to type in. Lines in bold courier should be typed at the Terminal.Replace <your short user name> with your short user name.

Here goes… Enjoy!

To get started, edit the Apache configuration file as root:

sudo vi /etc/apache2/httpd.conf

Enable PHP by uncommenting line 186, changing:

#LoadModule php7_module libexec/apache2/libphp7.so

to

LoadModule php7_module libexec/apache2/libphp7.so

(If you aren’t familiar with vi, go to line 186 by typing “186G” (without the quotes). Then just press ‘x’ over the ‘#’ character to delete it. Then type ‘:w!’ to save, or just ‘ZZ’ to save and quit. Don’t do that yet though. More changes are still needed.)

If you want to run Perl scripts, you will have to do something similar:

Enable Perl by uncommenting line 187, changing:

#LoadModule perl_module libexec/apache2/mod_perl.so

to

LoadModule perl_module libexec/apache2/mod_perl.so

Enable personal websites by uncommenting the following at line 183:

#LoadModule userdir_module libexec/apache2/mod_userdir.so

to

LoadModule userdir_module libexec/apache2/mod_userdir.so

and do the same at line 520:

#Include /private/etc/apache2/extra/httpd-userdir.conf

to

Include /private/etc/apache2/extra/httpd-userdir.conf

Now save and quit.

Open the file you just enabled above with:

sudo vi /etc/apache2/extra/httpd-userdir.conf

and uncomment the following at line 16:

#Include /private/etc/apache2/users/*.conf

to

Include /private/etc/apache2/users/*.conf

Save and exit.

Lion and later versions no longer create personal web sites by default. If you already had a Sites folder in Snow Leopard, it should still be there. To create one manually, enter the following:

mkdir ~/Sites

echo “<html><body><h2>My site works</h2></body></html>” > ~/Sites/index.html.en

While you are in /etc/apache2, double-check to make sure you have a user config file. It should exist at the path: /etc/apache2/users/<your short user name>.conf.

That file may not exist and if you upgrade from an older version, you may still not have it. It does appear to be created when you create a new user. If that file doesn’t exist, you will need to create it with:

sudo vi /etc/apache2/users/<your short user name>.conf

Use the following as the content:

<Directory “/Users/<your short user name>/Sites/”>

AddLanguage en .en

AddHandler perl-script .pl

PerlHandler ModPerl::Registry

Options Indexes MultiViews FollowSymLinks ExecCGI

AllowOverride None

Require host localhost

</Directory>

Now you are ready to turn on Apache itself. But first, do a sanity check. Sometimes copying and pasting from an internet forum can insert invisible, invalid characters into config files. Check your configuration by running the following command in the Terminal:

apachectl configtest

If this command returns “Syntax OK” then you are ready to go. It may also print a warning saying “httpd: Could not reliably determine the server’s fully qualified domain name”. You could fix this by setting the ServerName directive in /etc/apache2/httpd.conf and adding a matching entry into /etc/hosts. But for a development server, you don’t need to do anything. You can just ignore that warning. You can safely ignore other warnings too.

Turn on the Apache httpd service by running the following command in the Terminal:

sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

In Safari, navigate to your web site with the following address:

It should say:

It works!

Now try your user home directory:

short user name>

It should say:

My site works

Now try PHP. Create a PHP info file with:

echo “<?php echo phpinfo(); ?>” > ~/Sites/info.php

And test it by entering the following into Safari’s address bar:

short user name>/info.php

You should see your PHP configuration information.

To test Perl, try something similar. Create a Perl test file with:

echo “print $ENV{MOD_PERL} . qq{n};” > ~/Sites/info.pl

And test it by entering the following into Safari’s address bar:

short user name>/info.pl

You should see the string “mod_perl/2.0.9”.

If you want to setup MySQL, see my User Tip on Installing MySQL.

If you want to add modules to PHP, I suggest the following site. I can’t explain it any better.

If you want to make further changes to your Apache system or user config files, you will need to restart the Apache server with:

sudo apachectl graceful

The Perfect Web Development Environment for Your New Mac

This version of the tutorial works with macOS Catalina (10.15), and versions going back to Mavericks (10.9) and uses Homebrew as a package manager. I streamlined this tutorial in August 2014 to make it even easier to set up your development environment. I’ve archived the original version. In January 2016, I added support for xip.io, which is a DNS redirecting service. This allows you to access your local sites from any device on your network.

I’ve been using this particular configuration, or one quite like it, for several years, but when I picked up a new laptop recently, I decided to start from scratch. There were a ton of settings, scripts, and programs installed on my old machine that I no longer used, and I wanted them gone.

Feel free to use this guide on any Mac, but you may find that there are differences on your machine if it’s not a fresh install of OS X. These are the exact steps I used to get things running on my machine, and it’s been tested on many machines.

Why Not Just Use MAMP?

MAMP is a package that will install MySQL, PHP, and Apache on your Mac all with one download, and a quick install. It’s a great option and MAMP Pro, the paid version, will provide most of the features you need to run multiple web sites on your machine. I don’t use it because most of what it offers is already a part of OS X, and I prefer to customize my environment beyond what MAMP provides out of the box. If I’m already going to be playing around with the config files, I may as well go the distance. The main benefit of MAMP is that it leaves all your default system settings alone, sandboxing your development environment. I don’t get any benefit out of that. It also allows you to easily turn on and off services. I don’t ever turn them off, so that’s not any help to me either.

Housekeeping

Mac OS X is a great operating system for developers, but many of the features important to us are turned off to make the OS more easy to use for everyday tasks, and more secure. Many of the configuration files we need to edit are hidden away in directories that do not show up in the Finder by default. I’m not going to tell you how to edit files here. Some people prefer command-line tools like Vim or Pico. For most of my code editing needs, I use Sublime Text. It’s not free, but I find the features well worth the price. If you’re going to be using a text editor every day, you’re going to want to pay for a good one. Sublime Text can open files like any other GUI text editor, and can also be invoked from the command line. Make sure you’re familiar with editing config files in the text editor of your choice before continuing.

Everything we’ll be installing here is free, and you can certainly go a long way without having to pay a cent for any of your software. However, don’t be afraid to pay actual money for great apps. If you’ve bought a Mac, you already understand that spending money on a well designed product usually saves you time in the long run. Software works the same way.

Xcode

First, you need to have Xcode (Apple’s development bundle) installed for a few of these tools to work. You can get by without it if you try really hard, but if you’re a developer, you’re probably going to need to have it at some point. It’s massive, so start downloading it now. Grab it from the App Store, and then grab a coffee or play with your kid or dog.

For OS X 10.9 (Mavericks) and up, the developer command line tools can be installed by running the following command within terminal.

xcode-select --installcopy

This will trigger a software update dialog box. Click install and wait for it to complete. If this does not work, download the installation package from Apple. You will need an Apple developer account to do this.

Once Xcode is installed, start it up. The tools we need will not work unless the app has run once, and you’ve accepted the licence agreement. You don’t need to do anything with the app. Just start it up (It can take a while to run the first time, even on a fast machine) click agree, and shut it down.

Homebrew

Homebrew is a popular and amazing package manager for OS X. Package managers keep all the big and small tools that we need to install on our machines tidy and up-to-date. It could not be easier to install. Switch over to your terminal, and type in this one command:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"copy

It can take a while for the install, but that one command is all you need for Homebrew. Really.

MySQL

This is optional. You may prefer another kind of database, or no database at all. Feel free to skip this if you don’t need it, but really, you probably do. MySQL no longer comes pre-installed as of Mountain Lion (10.8) as it did with previous versions or OS X. Download it here. You can try the latest version of MySQL for the latest version of OS X. The latest version is currently for 10.11. Choose the 64bit “DMG Archive” one.

dnsmasq

This is a great little tool to that allows us to use wildcard subdomain names.

With the default apache settings, you can add as many sites as you like in subfolders of the web root. You can have sites like this:

http://home.test/client1 http://home.test/client2 http://home.test/client3

However, that creates a problem. When you have each site in a folder, it’s more difficult to manage the settings for each site. Each one must then have a different absolute root. The solution is to create a subdomain for each site, and use URLs like these:

http://client1.test http://client2.test http://client3.test

We can accomplish this by placing all three sites in our /private/etc/hosts file, but then we need to keep adding entries every time we add a new site. dnsmasq allows us to do this by interrupting each request that ends with .test and forwarding it to a designated IP address (127.0.0.1 in our case). Previous versions of this tutorial used .dev as a local TLD but .dev has been registered for use by Google and forced by Chrome to use SSL, so it is no longer an option for local development. The .test TLD is now reserved for development use. You can also use .localhost or .example. You can even make up your own as long as it’s not a real TLD in use.

To install dnsmasq, we use the previously installed Homebrew. The following commands will install dnsmasq, configure it to point all requests to the .test top-level domain to our local machine, and make sure it starts up and runs all of the time.

brew install dnsmasqcopy

cd $(brew --prefix); mkdir etc; echo 'address=/.test/127.0.0.1' > etc/dnsmasq.confcopy

sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemonscopy

sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plistcopy

sudo mkdir /etc/resolvercopy

sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/test'copy

We’re now done with dnsmasq, and if all goes well, you’ll never need to think about it again. Now, to get Apache going.

Your Local Web Root

Apache has a default location for storing website files, but I prefer to create my own web root that is independent of Apache. You can place your files anywhere you wish, but I prejust put them in a directory called /www on my main hard drive. Put yours wherever you wish. In that folder, I have a few subfolders. /www/home is a main website that I use to list all my local sites (I’ll show you how to make that site dynamic later on). /www/sites is the folder in which I place each of my other sites. Each of those site folders has a webroot (/www/sites/client1/wwwroot), and an assets folder (/www/sites/client1/assets), where I keep source files or other documents related to the site.

Apache

Step one is easy. It’s actually almost done. Mountain Lion (10.8) was the first version of OS X without Apache in the “sharing” section of the preferences pane. No big deal though, since you just need to start it up once using the terminal. Open up the Terminal app, and enter the following command. You’ll be asked for your administrator password.

sudo apachectl startcopy

That’s it. Test it out by visiting http://localhost in your browser. You should see a simple page that says “It Works”. Apache is up and running, and is ready to serve your sites. It will stay on until you turn it off (I never turn it off), and will start up automatically each time you start your computer. Don’t worry about taxing your computer’s resources by running Apache. It won’t be a problem.

You should also try http://home.test, which should work since dnsmasq is pointing all *.test domains to the local IP. You can try http://ANYTHING.test as well.

Apache will serve up sites as is, but there are a few quick changes we need to make to the configuration files before we are ready to go. Using your favorite text editor, open up /private/etc/apache2/httpd.conf

If you’re going to be using PHP, you need to tell Apache to use the PHP module to handle .php files. On line 169 (line 117 before 10.10 (Yosemite) but could be different on your system), you need to uncomment this line (remove the “#”)

168  #LoadModule perl_module libexec/apache2/mod_perl.so
169  #LoadModule php5_module libexec/apache2/libphp5.so
170  LoadModule hfs_apple_module libexec/apache2/mod_hfs_apple.so

becomes

168  #LoadModule perl_module libexec/apache2/mod_perl.so
169  LoadModule php5_module libexec/apache2/libphp5.so
170  LoadModule hfs_apple_module libexec/apache2/mod_hfs_apple.so

Scroll to Top