Pre-Requisites
Before starting the installation of the Apache (httpd) server using this tutorial you must have the following prerequisites.
Terminal: You must have Mac Terminal access and little knowledge about working with the terminal application. Ao login to your Mac system and open terminal Homebrew: Homebrew is a popular package manager for the Mac operating systems. It is useful for installing most open-source software like Node. Homebrew installation tutorial
Step 1 – Installing Apache on macOS
Step 2 – Configuring the Apache HTTP Server
The Apache web server is running now on your macOS system. Now you will want to make some configuration changes according to your local development environment. A configuration file /use/local/etc/httpd/httpd.conf is generated by the installer which you need to edit in a text editor and make following changes.
Step 3 – Create Test HTML Page on Apache
Let’s create a Sites folder in your home directory and create a sample index.html file for testing. You also need to change the tag configured just right below the DocumentRoot line. This should also be changed to point to your new document root as well: In that same block you will find an AllowOverride option, Set this to all to enable the uses of the .htaccess file in Apache. Restart apache to ensure your configuration changes have taken effect: Now, Point your browser to http://localhost, This should display your newly created index.html. All done.
Step 4 – Manage Apache Service
At this point, you have successfully installed the Apache server on macOS. The below-mentioned commands will help you to stop, start, and restart the Apache service at any time.
Stop the Apache Server:sudo apachectl stop Start the Apache Server:sudo apachectl start Restart the Apache Server:sudo apachectl restart
Conclusion
Apache is a web server that serves HTML content to internet users. The default Homebrew version of Apache runs on port 8080, so we also have included the steps to change the port. You can also change the document root to use a different location than the default. This tutorial helped you to install and configure the Apache webserver on the macOS system.