Mac OS X setting up virtual hosts

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Thanks Samet! 🤩
Game changer Catalin! I hate working with mamp and those things, so this has been a game changer for the old projects that don't use docker.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

You might remember the days of MAMP/XAMP/WAMP? Well, for Mac OS X, we don't need these tools anymore.
It's actually possible to host a website on your local Mac, and it's not as hard as you would think!
Today, we'll set up a local PHP website that we can reach through our browser.
The first step to making this work is enabling virtual hosts on Mac OS X.
To do this, we need to modify the httpd.conf file. Execute the following command in your terminal.
sudo nano /etc/apache2/httpd.conf
Look for the following line:
#Include /private/etc/apache2/extra/httpd-vhosts.conf
And below that, on a new line add the following:
Include /private/etc/apache2/vhosts/*.conf
This tells Apache to load all .conf files in this directory.
Note: You could also add all the hosts in the
httpd-vhostfile, but I found this a cleaner method.
Now we need to make the configuration files, make sure the directory exist or create it.
mkdir /etc/apache2/vhosts
Now we can create our first configuration in that folder.
sudo nano /etc/apache2/vhosts/daily-dev-tips.conf
Place the following information inside:
<VirtualHost *:80>
DocumentRoot "/Users/chrisbongers/www/daily-dev-tips"
ServerName daily-dev-tips.local
<Directory "/Users/chrisbongers/www/daily-dev-tips">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
You have to set the DocumentRoot to your own directory on your local machine. For me, it's a www folder at my user level. Next, set the ServerName to the URL you want to serve it on.
Now we need to restart Apache
sudo apachectl restart
However, if we now visit: http://daily-dev-tips.local we don't see anything...
To make the local domain work, we need to map the domain to our local server.
Modify your host file.
sudo nano /etc/hosts
And add a line like this:
127.0.0.1 daily-dev-tips.local
Make sure you use the domain you set in the vhost file.
If you open your website link, another app might point to the default page, depending on whether you already set up the folder.
I didn't, so create the folder in the place you provided in the vhost file and create a simple index.php inside.
<?php
echo 'Hello world from my own Mac OS X server';
?>
Now open the website again and see the beauty of your server.

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter