How to Enable Apache & PHP on MacOS

MacOS is an operating system made by technology giant Apple Computer. This operating system is one of several Unix branches that still exist today.


Apache & PHP are two open source projects that have been around for a long time. Apache was founded and managed by the Apache Foundation, while PHP was created by Rasmus Lerdorf whose development was then continued by the PHP development team and Zend Technology.

These two projects are often used in web development and can be run on various operating systems such as Linux and Windows. Not many know, that Apache and PHP are also available on MacOS, but are not yet activated.

To activate Apache, we simply type the command sudo apachectl start. Meanwhile, to stop it simply change the command to sudo apachectl stop. To find out whether the Apache server is running or not, we can simply type http://localhost in the browser and the screen will display the words It’s works! which means Apache has been successfully run on the system.

How to Enable Apache & PHP on MacOS

That’s how Apache has been running successfully in our browser. The next step is to activate PHP. We can edit the Apache config file i.e httpd.conf which is located in /etc/apache2. The command is sudo nano edit /etc/apache2/httpd.conf. Don’t forget to enter your Mac password.

Because we are using the nano editor, we just need to find the word php by doing a combination of letters Ctrl + W then type the query “php” and the search results immediately appear “#LoadModule php7_module libexec/apache2/”

How to Enable Apache & PHP on MacOS

Remove the # sign to activate the PHP module, then press the letter combination Ctrl + S to save changes and Ctrl + X to get out.

In the httpd config too, we can change the main directory for our web server, by searching for the query DocumentRoot, using the method Ctrl + W as previously.


How to Enable Apache & PHP on MacOS

We can leave it as it was or change it to our liking, don’t forget to save all changes by pressing Ctrl + S.

Make changes to Apache by restarting it using the command sudo apachectl restart.


Those are the easy steps to activate Apache & PHP on MacOS systems, this method also applies to Hackintosh users (i.e. using MacOS systems on non-Apple devices).

Leave a Comment