Skip to content
Redlyst

How to Enable Apache PHP and Change Apache Port on MacOS

Apache, Homebrew, Guide, MacOS, PHP1 min read

After we are already done with switching to Apache Homebrew, to enable PHP, we need to install it first with Homebrew.

Open the terminal and install the latest PHP version by this command:

brew install php

The output you may get if the process is done: Result

The next step is to add the Apache httpd.conf with this line of the configuration:

Add-/opt/homebrew/etc/httpd/httpd.conf
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

and edit the Apache httpd.conf from:

Edit-from-/opt/homebrew/etc/httpd/httpd.conf
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>

to:

Edit-to-/opt/homebrew/etc/httpd/httpd.conf
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>

and the last step to change the apache port is to edit the Apache httpd.conf from:

Edit-from-/opt/homebrew/etc/httpd/httpd.conf
Listen 8080

to

Edit-to-/opt/homebrew/etc/httpd/httpd.conf
Listen 80

Restart the Apache services by this command:

brew services restart httpd

Check the Apache port by this command:

sudo lsof -i:80

and the output: Httpd

This tells us that the Apache is running and we have already succeeded to change the port, and for the PHP version we can check by this command:

php -v

the output: PHPV

and check it via Browser by adding <?php phpinfo(); ?> to a .php at the DocumentRoot

PHPB

MISSION IS COMPLETED!!

© 2023 by Redlyst. All rights reserved.
©LekoArts