sandesh-s-blog-banner

Setup Virtual Host in macOS using Nginx for Magento 2.4.*

Hello World,

In this blog, I am going to write about how to set up a virtual host in macOS using the Nginx server. As you have already known that Magento has moved its index.php file from the root directory and from Magento 2.4 it will be served only from the pub directory it’s a little bit tricky to set up for the latest versions.
To check the official documentation stating the above point please click here.

To demonstrate this scenario, I have installed Nginx using the brew package manager.

To create a virtual host we need to follow 2 steps

1. Create a configuration file
2. Add the URL in the hosts file

Step 1: Create a Configuration file

Create a configuration file with any name (example:- _magento24.local.conf) in /usr/local/etc/nginx/servers/_magento24.local.conf and add the below contents in that file

     upstream fastcgi_backend {
         server  127.0.0.1:9000;
     }
     server {

              listen 80;
              server_name magento24.local;
              set $MAGE_ROOT /usr/local/var/www/magento24;
              include /usr/local/var/www/magento24/nginx.conf.sample;
    }

Note:- The server mentioned in the upstream block is taken from /usr/local/etc/php/7.4/php-fpm.d/www.conf (refer the screenshot)

www.conf-screenshot

Step 2: Add the URL in hosts file

Add your virtual host URL in hosts file located in /etc/hosts

127.0.0.1 magento24.local

Then restart your Nginx server

brew services restart nginx

That’s it. your virtual host will be loading your Magento site in any browser from now on…

Thank you for referring to this blog, if you have any doubts/ queries feel free to put them in the comment section. I will be happy to answer your queries.

Add comment: