Apache Macos Catalina

Catalina

Here’s where to find httpd.conf on Mac. This is the httpd.conf location on Mac OS X 10.6 Snow Leopard and Mac OS X 10.7 Lion. This article also shows how to make the httpd.conf directory visible in the Mac Finder.

What is Httpd.conf?

Httpd.conf is the Apache web server’s main configuration file. Mac OSX ships with Apache installed. See Apache’s configuration docs for how to configure Apache.

A handy ssh book for beginners and forgetful veteran developers and Unix/Linux/macOS users. Open a terminal and than type the following command to restart the apache 2 web server: $ sudo /usr/sbin/apachectl restart. $ sudo apachectl -k restart. Sample outputs: Restart Apache 2 Mac OS X.

Httpd.conf Location on Mac

  • Option 1: Drag Apache icon to the Trash. Open up the Finder, click Applications on the left side, and then select Apache. Drag Apache to the Trash (or right click on it and then select Move to Trash option). Right click the Trash icon and select Empty Trash option to start the uninstall. This drag-to-delete method works in all versions of Mac OS X.
  • MacOS Catalina 10.15.5 introduces battery health management in the Energy Saver settings for notebooks, an option to control automatic prominence of video tiles on Group FaceTime calls, and controls to fine-tune the built-in calibration of your Pro Display XDR. The update also improves the stability, reliability, and security of your Mac.

On Mac httpd.conf location is in the directory /etc/apache2. You can access this folder through the Mac Finder or through the Mac Terminal.

Checked on OS X 10.7, 10.6.8, 10.6.7.

Httpd.conf Location in Mac Finder

You won’t normally see even the /etc/apache2 directory showing up in the Mac Finder. I tried looking in MacintoshHD, but /etc doesn’t show up.)

I found a tip at Codejacked on how to open hidden files in the Finder.

Here’s how to view httpd.conf’s directory in the Mac’s finder:

  1. In the Finder, click the Go menu, and choose Go to Folder…
  2. Type in /etc/apache2.
  3. Click Go.

The Finder will show the apache2 folder, and in it, you’ll see httpd.conf.

Httpd.conf Location in Mac Terminal

You can also get to the httpd.conf file through a terminal session, which is okay if your comfortable in the Unix shell (bash):

Can’t Save Httpd.conf?

Httpd.conf is protected by OSX from being edited. If you open it with the TextEdit application for example, you won’t be able to save it. For details to bypass this security, see How to Easily Edit Httpd.conf on Mac.

Restart Apache to Apply Configuration Changes

Apache Macos Catalina

Don’t forget you will need to restart Apache for your configuration changes in httpd.conf to be applied. To restart Apache on Mac:

  1. Go to the Apple menu and choose System Preferences.
  2. Click on Sharing.
  3. Untick Web Sharing.
  4. Tick Web Sharing.

PREREQUISITES:


In order to follow this guide, you should have a Mac computer with the Catalina OS installed.

I was using for several years MAMP, Fywheel, as well as package managers like brew, and all work pretty well, but why not using the preinstalled Apache and PHP that is shipped in almost all macOS?

In this tutorial, I will show you how to setup/install Apache, PHP, and MySQL on macOS Catalina.

Restart Apache Mac Catalina

Open the Terminal app and switch to the root user so you can run the commands in this post without any permission issues:

Enable Apache on macOS

Check if works by accessing:
http://localhost

Enable PHP for Apache

First, let’s make a backup of the default Apache configuration


Edit the Apache configuration


Uncomment the following line

Restart Apache:


You can verify PHP is enabled by creating a phpinfo() page in your DocumentRoot.

The default DocumentRoot for macOS Catalina is /Library/WebServer/Documents. In order to verify this, we run the command below to find out our Apache configuration.


Create the phpinfo() page in your DocumentRoot:

Verify PHP by accessing http://localhost/phpinfo.php

Customizing PHP settings (php.ini)

MacOS’ PHP uses a default php.ini file based on /private/etc/php.ini.default.
To customize your PHP environment, if a php.ini file doesn’t already exist at /private/etc/php.ini, copy the default template to create a main php.ini file:

Make any changes you wish to php.ini and restart apache to reload all configuration files:

Macos Catalina Apache

If you were to run phpinfo() in a PHP file from the web server, you should now see that the Loaded Configuration File property now has the value /etc/php.ini.

A very common tweak to the default PHP configuration is to allow larger file upload sizes. The post_max_size and upload_max_filesize properties are only a few megs by default. These limits can be raised as you see fit.

Apache Macos Catalina Download

Many developers also tweak the max_execution_time, max_input_time, and memory_limit settings depending on their project.

Always remember to restart apache after making changes to your PHP configuration.

Install MySQL on macOS Catalina

Download and install the latest MySQL version for your macOS.


Setup
Open a new terminal and run the code below this will update the mysql path on your ~/.profile

Macos


Please run mysql_secure_installation to make your MySQL secured

Recommended setup:
Strong Password? Yes
Change the root password? Yes
Remove anonymous users? yes
Disallow root login remotely? Yes
Remove test database? Yes
Reload privileges tables now? Yes

We can set a command shortcut for mysql:

Now, to access mysql console, we can run below short command:


Useful mysql commands

Connect PHP and MySQL

Create symlink to ensure PHP and MySQL can communicate each other.

Edited my Apache Configuration:


Uncommented the following lines

Virtual Hosts

Apache Macos Catalina Free

Edit the Apache configuration file:


Add the below line after this included #Include /private/etc/apache2/extra/httpd-vhosts.conf


Create the apache2 vhosts directory.


Create the default virtual host configuration file.


Add the following configuration:


The default virtual host was created for when the Apache web server can’t find a virtual host, it will use this configuration. By prefixing this file with an underscore, Apache will include it first.

Now we can create our first virtual host. The example below contains the virtual host configuration for my test site.

Create the virtual host configuration file:


Add the following configuration:

This VirtualHost configuration allows me to access my site from http://nuno-test.test for local development.


The final step is to restart Apache:


Test our apache configuration/strong>

Start, Stop, Restart and test Apache server config


I know it is a little bit daunting but I promise that we’ll never come back to this nasty lengthy configuration file again. Four simple commands are everything that we need to remember from now on. Start, stop, restart and configuration test.

Mapping our vhosts on macOS hosts file


Add your virtual host to the bottom of the file. It should match the value you used for the ServerName configuration.


Flush macOS DNS cache:

Permissions

You may receive 403 Forbidden when you visit your local site. This is likely a permissions issue. Simply put, the Apache user (_www) group (_www) needs to have access to read, and sometimes write, to your web directory.

Disable Apache Mac Catalina

Conclusion

By using the macOS preinstalled Apache and PHP we can avoid installing extra software on our macOS which sometimes could lead us to conflicts/errors/miss configuration on our Mac Operating system.