Apache Macos Catalina

A basic check you can perform yourself is to check the existence of Apache processes after the apachectl start command. On macOS with netstat command display all the network connection. You can filter only 'listen' connections and see the http (s) servers. Tcp46 0 0.https. LISTEN tcp46 0 0.http. MacOS 10.13 High Sierra and 10.14 Mojave come with Apache pre-installed. However, instead of using the delivered version we’re going to install Apache via Homebrew and then configure it to run. The reason is that I am using the homebrew version of both Apache and PHP. The current version of PHP that I am using is PHP 7 as you can see in the screenshot below but when I use php -v in the terminal it shows me PHP version 5.6. See screenshot below. 2018 Mac-Mini macOS Big Sur, 32 GB. Assuming you are using the version of Apache that came bundled with Mojave, I would suggest switching over to the Homebrew version of httpd instead. It's already up to date at 2.4.46. Once you've installed Brew, you can use.

Disable

Question or issue on macOS:

I have Apache webserver (the one supplied by Apple) running on my Macbook and it ran flawlessly, until I upgraded to Catalina 10.15.
I used the same httpd.conf, but now it is displaying

You don’t have permission to access this resource.Server unable to read htaccess file, denying access to be safe

I thought is was folder access by Catalina, but I don’t know how to let Apache access the web root folder (which is inside my /Users/me/Documents folder)as Apache is not a normal /Application.

Port 80 is open when I check with lsof -nP -i4TCP:80 | grep LISTEN op nmap, so Apache does start.

I set a simple index.html in the root folder, but the problem persists.
And when I remove the .htaccess from the Apache root folder I get:

You don’t have permission to access this resource.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

Macos

What can be the problem here ?

How to solve this problem?

Solution no. 1:

I have found the solution, myself.

It is a Catalina issue:

  1. Go to System Preferences => Security & Privacy => Full Disk Access
  2. Click on the “+” button to add an app and go to the root folder of the disk and press
    Cmd + Shift + .(dot)
  3. Go to /usr/sbin/ and select httpd.

That worked for me.

Solution no. 2:

i had the same error, the problem in my case was that macOS Catalina comes with the php module disable by default, in the error log apear as:

tail /private/var/log/apache2/error_log


[Wed Feb 26 18:10:57.123036 2020] [autoindex:error] [pid 3145] [client
127.0.0.1:53734] AH01276: Cannot serve directory /Library/WebServer/Documents/subdir/: No matching DirectoryIndex
(index.html) found, and server-generated directory index forbidden by
Options directive

the apache server was loking for index.html instead of index.php so it was blocking the list directory, I uncommented the line #LoadModule php7_module libexec/apache2/libphp7.so in /etc/apache2/httpd.conf and restart the apache server


sudo apachectl restart

and it just work. hope it helps.

Solution no. 3:

The above answer save my life!

I tried all the different Apache configs possible, nothing worked.

Just a small correction for step 2 – click on the “+” sign to add an app, navigate to the root folder then press Cmd + Shift + .(dot) which will show all hidden folders and allow you to see the folder in step 3 (/usr/sbin/)

I wish Apple would have at least shown some error in such a case…

Solution no. 4:

Mac catalina apache forbidden issue

Step 1: sudo code /etc/apache2/httpd.conf

Step 2:search for line #LoadModule php7_module libexec/apache2/libphp7.so
and uncomment no need to delete it.

Step 3: sudo apachectl restart

Step 4: open Web browsers type localhost

Step5: Done

Hope this helps!

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

Mac

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)

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.

Disable Apache Mac Catalina

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.

Mac

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

Apache Macos Catalina Update

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.

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.

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)

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