Install Apache On Mac Catalina

Installing Apache and PHP on macOS Catalina 10.15. The title of this page is quite 'misleading' as both Apache and PHP comes pre-bundled in macOS Catalina 10.15. We merely need to configure them. Press ⌘ + SPACE (Spotlight Search) and bring up the terminal. When I wrote 'The correct version for Mac Catalina', I meant the correct version of OpenOffice for Mac Catalina. Apache OpenOffice 4.1.10 on Xubuntu 20.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP. In order to Install Apache Tomcat version 8.x.x (Supports Servlet 3.1 specifications) on your Mac OS X (macOS) running Yosemite OS 10.10.x you must have java version 7 or later installed on your Mac. How to check your java version installed: Go to Terminal. Run command: java -version. If it is less than 1.8, download and install java8. If Apache server is started, you should see the below: localhost on browser Create Sites directory. Let’s create a Sites directory under username folder (username is your mac login name) This directory is going to be the document root. Go to Mac HDD Users your account folder 2. Create folder with the name Sites. When the folder is.

The Servlet 4.0 specification is out and Tomcat 9.0.x does support it. Time to dive into Tomcat 9.

Prerequisite: Java

Since OS X 10.7 Java is not (pre-)installed anymore, let’s fix that by installing a Prebuilt OpenJDK Binary. Easy to follow details about how to install OpenJDK are available here. Anyway, after opening the Terminal app,

hopefully shows something like this:

Whatever you do, when opening Terminal and running ‘java –version’, you should see something like this, with a version of at least 1.8.x I.e. Tomcat 9.x requires Java 8 or later.

sudo is a program for Unix-like operating systems, allowing you to run programs with the security privileges of another user (normally the superuser, or root). Since we are creating directories, outside of your home folder, administrator right are required. I.e., when executing sudo you will be asked to enter your password; and your Mac User account needs to be an ‘Admin’ account.

JAVA_HOME is an important environment variable, not just for Tomcat, and it’s important to get it right. Here is a trick that allows me to keep the environment variable current, even after a Java Update was installed. In ~/.zshrc, I set the variable like so:

Installing Tomcat

Here are the easy to follow steps to get it up and running on your Mac

  1. Download a binary distribution of the core module: apache-tomcat-9.0.40 from here. I picked the tar.gz in Binary Distributions Core section.
  2. Opening/unarchiving the archive will create a new folder structure in your Downloads folder: (btw, this free Unarchiver app is perfect for all kinds of compressed files and superior to the built-in Archive Utility.app)
    ~/Downloads/apache-tomcat-9.0.40
  3. Open the Terminal app to move the unarchived distribution to /usr/local like so:
    sudo mkdir -p /usr/local
    sudo mv ~/Downloads/apache-tomcat-9.0.40 /usr/local
  4. To make it easy to replace this release with future releases, we are going to create a symbolic link that we are going to use when referring to Tomcat (after removing the old link, you might have from installing a previous version):
    sudo rm -f /Library/Tomcat
    sudo ln -s /usr/local/apache-tomcat-9.0.40 /Library/Tomcat
  5. Change ownership of the /Library/Tomcat folder hierarchy:
    sudo chown -R <your_username> /Library/Tomcat
  6. Make all scripts in Tomcat’s ./bin folder executable:
    sudo chmod +x /Library/Tomcat/bin/*.sh

Tomcat 9.x

Starting and stoping Tomcat works with executing the provided scripts, like so:
/Library/Tomcat/bin/startup.sh
/Library/Tomcat/bin/shutdown.sh

Finally, after your started Tomcat, open your Mac’s Web browser and take a look at the default page: http://localhost:8080

Apple released its 2020 newest macOS Big Sur on November 12, 2020. It is a time of year again that you might need to reconfigure your macOS if you are upgrading from the macOS Catalina. Or if you have a new macOS, follow the below steps to enable your local web server on macOS Big Sur (version 11.0.1)

Start the Apache Server

macOS comes with Apache Server by default. To start the built-in Apache server, open the Terminal app from your Application folder or type Terminal in the Spotlight Search (shortcut: Command + Space Bar)

Type sudo apachectl start and press enter

Open any of your favorite browser (e.g. Safari, Chrome)

Type localhost or 127.0.0.1 in the address bar

If Apache Server is started, you should see the below:

Create Sites Directory

It is recommended to create a Sites directory under username folder (username is your mac login name) This directory will be your document root for any web-related stuff.

  1. Go to Mac HDD > Users > [your account folder]
  2. Create a folder with the name Sites. When the folder is created, it will generate a folder with a compass image on the folder as you can see from the below screenshot.

Create username.conf file

To be able to recognize the files putting into Sites directory, username.conf needed to be setup.

1. Type whoami and press enter. (Note down the name. this is your account name / username) For example, if your username is developer, we will be making a .conf file with the name of developer.conf under /etc/apache2/users

2. Type cd /etc/apache2/users and press enter.

3. Type ls and press enter. Check if there is an existing username.conf file (username is your account name)

4. If there is an existing username.conf, make a backup copy by typing sudo cp username.conf username.conf.bak

5. Type sudo nano username.conf and press enter (note: username will be your account name e.g. developer.conf)

6. Copy and paste the following configuration.

7. Press Control + o and press enter to save the file.

8. Press Control + x to exit the nano editor.

Configure the httpd.conf file

1. Open the Terminal app from your Application folder or type Terminal in the Spotlight Search (shortcut: Command + Space Bar)

2. Type cd /etc/apache2 and press enter.

3. Type sudo cp httpd.conf httpd.conf.bak and press enter. (This step is optional if you want to keep the copy of the original config file but I would recommend keeping one just in case.)

4. Type sudo nano /etc/apachae2/httpd.conf and press enter.

5. Press control + w and type LoadModule authz_core_module and press enter. (control + w will activate the search and it will look for a line with the keyword you put in)

Uncomment the following modules. The # you see in front of each line means that line is commented out. That means that a specific line or module on that line will be ignored. What we want to do is, uncomment this so the module is enabled.

6. Use control + w to find each of the modules below.

7. Uncomment the following line for the User home directories.

8. Replace the below two lines with your username document root. (You can comment on those two lines by putting # in front of them.

9. Replace with the following:

Note: USERNAME needs be replaced with your username (e.g. developer)

Install Apache On Mac Catalina

10. Press control + w and type AllowOverride None then enter

Replace AllowOverride None to AllowOverride All

Your DocumentRoot configuration in httpd.conf will look like below:

11. Press control + o and press enter to save the file.

12. Press control + x to exit the nano editor.

Configure the httpd-userdir.conf file

1. Type cd /etc/apache2/extra and press enter.

2. Type sudo cp httpd-userdir.conf httpd-userdir.conf.bak and press enter. (this step is optional if you want to keep the copy of original file.)

3. Type sudo nano httpd-userdir.conf and press enter.

Uncomment the following line.

4. Press control + o and press enter to save the file.

5. Press control + x to exit the nano editor.

6. Type sudo apachectl restart (this step will restart the Apache server to take effect of the changes made in the config file)

Enable the PHP

macOS has built-in PHP (at least in Big Sur and prior versions) You just need to enable the PHP from the Apache’s config file. Follow the below steps to do so.

1. Open the Terminal app from your Application folder or type Terminal in the Spotlight Search (shortcut: Command + Space Bar)

2. Type cd /etc/apache2 and press enter.

3. Type sudo nano /etc/apache2/httpd.conf and press enter.

4. Press control + w and type php (this will search for a line with keyword php in Apache’s config file.)

You should be seeing the following line. Uncomment the LoadModule php7_module libexec/apache2/libphp7.so by removing the # in the front of that line of code.

5. Press control + o and press enter to save the file.

6. Press control + x to exit the nano editor.

7. Type sudo apachectl restart (this step will restart the Apache server to take effect of the changes made in the config file)

Create a phpinfo() page

To try out the PHP is working on your local mac web server, create a phpinfo() file and load it on the browser.

1. Open the Terminal app from your Application folder or type Terminal in the Spotlight Search (shortcut: Command + Space Bar)

2. Type cd ~/Sites/ and press enter.

3. Type sudo nano phpinfo.php and press enter. (this will bring up the nano editor with blank screen since the phpinfo.php is newly created file and has no code at this point)

4. Put the following code.

5. Press control + o and press enter to save the file.

Install Apache On Mac Catalina Os

6. Press control + x to exit the nano editor.

7. Open a browser and type the following in the address bar.

You should be seeing a page something like below. This means, the PHP is working on your local mac server.

Setting Up the MySQL Server

To be able to use a local database, you need to install a database server. In this case, we will be installing the MySQL Server. Follow the below steps to setup your MySQL Server on your local macOS.

  1. Go to https://dev.mysql.com/downloads/mysql/

2. Download the installer with DMG file.

3. Double click the MySQL server installer.

Follow the instructions on the Installer.

If above message shows up, click Allow.

Select Use Strong Password Encryption

Setup a password for “root” user and click Finish to complete the setup.

Install Apache Mysql Php On Macos Catalina 10.15

Once the installation is complete, you can move the installer to the trash.

Now, if you go to System Preferences, you should be seeing MySQL.

If you check, it should have the green indicator showing it is up and running.

If you need to setup a MySQL Workbench, you can refer to Using MySQL Workbench on macOS Catalina (2019)

How To Install Apache On Macos Catalina

If you are using macOS Catalina, check out Setting Up Your Local Server on macOS Catalina (2019) – MAMP – macOS, Apache, MySQL, PHP to setup your mac local web server.

Latest Post