{"id":22,"date":"2023-06-30T11:19:40","date_gmt":"2023-06-30T03:19:40","guid":{"rendered":"https:\/\/clifford.io\/blog\/?p=22"},"modified":"2024-05-06T07:55:56","modified_gmt":"2024-05-05T23:55:56","slug":"configuring-a-custom-domain-name-on-mamp","status":"publish","type":"post","link":"https:\/\/clifford.io\/blog\/configuring-a-custom-domain-name-on-mamp\/","title":{"rendered":"Configure a Custom Domain Name on MAMP"},"content":{"rendered":"\n<p>In this post, we&#8217;ll look at how to configure a custom domain name on MAMP.<\/p>\n\n\n\n<p>If you&#8217;re using <a href=\"https:\/\/clifford.io\/blog\/install-mamp-local-php-development-environment\/\">MAMP<\/a> (and do not want to invest in MAMP Pro) as your local development environment, you might find it useful to have a custom domain name set up on your machine during development. For example, using &#8220;yoursite.local&#8221; rather than &#8220;localhost&#8221;. This is especially useful when you are developing multiple projects on the same computer. You can associate each custom domain with a project directory under your MAMP&#8217;s &#8220;htdocs&#8221; directory. So, let&#8217;s see how we can set this up!<\/p>\n\n\n\n<p>To set up a custom domain name on MAMP, you&#8217;ll need to make changes to your system&#8217;s hosts file and the Apache configuration. Here are the step-by-step instructions for configuring a custom domain name on MAMP:<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_60 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\" role=\"button\"><label for=\"item-69d28a8e7e133\" ><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input aria-label=\"Toggle\" aria-label=\"item-69d28a8e7e133\"  type=\"checkbox\" id=\"item-69d28a8e7e133\"><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/clifford.io\/blog\/configuring-a-custom-domain-name-on-mamp\/#Step_1_Choose_a_custom_domain_name\" title=\"Step 1: Choose a custom domain name\">Step 1: Choose a custom domain name<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/clifford.io\/blog\/configuring-a-custom-domain-name-on-mamp\/#Step_2_Edit_the_hosts_file\" title=\"Step 2: Edit the hosts file\">Step 2: Edit the hosts file<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/clifford.io\/blog\/configuring-a-custom-domain-name-on-mamp\/#Step_3_Edit_the_Apache_configuration\" title=\"Step 3: Edit the Apache configuration\">Step 3: Edit the Apache configuration<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/clifford.io\/blog\/configuring-a-custom-domain-name-on-mamp\/#Step_4_Restart_MAMP_servers\" title=\"Step 4: Restart MAMP servers\">Step 4: Restart MAMP servers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/clifford.io\/blog\/configuring-a-custom-domain-name-on-mamp\/#Step_5_Test_the_custom_domain_name\" title=\"Step 5: Test the custom domain name\">Step 5: Test the custom domain name<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_1_Choose_a_custom_domain_name\"><\/span>Step 1: Choose a custom domain name<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Decide on the custom domain name you want to use for your local development. For example, let&#8217;s assume you want to use &#8220;myproject.local&#8221;. It can also be &#8220;.yourname&#8221; or whatever other names you prefer to use.<\/p>\n\n\n\n<p>A note : try to use a domain TLD that is not publicly used as top-level domain in the Domain Name System (DNS). &#8220;.local&#8221; is a good example.  Refer to <a href=\"https:\/\/data.iana.org\/TLD\/tlds-alpha-by-domain.txt\" target=\"_blank\" rel=\"noopener\">this page<\/a> to see which domain TLDs are already in public and avoid using those TLDs.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_2_Edit_the_hosts_file\"><\/span>Step 2: Edit the hosts file<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the Terminal application on your Mac. You can find it in the Applications folder under Utilities. Or press command+spacebar and search for &#8220;terminal&#8221;<\/li>\n\n\n\n<li>In the Terminal, enter the following command to open the hosts file in a text editor:<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo nano \/etc\/hosts<\/pre>\n\n\n\n<p>You will be prompted to enter your administrator password. Enter the password as prompted.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The hosts file will open in the nano text editor. Scroll to the bottom of the file.<\/li>\n\n\n\n<li>Add a new line at the bottom and enter the following:<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">127.0.0.1    myproject.local<\/pre>\n\n\n\n<p>Replace &#8220;myproject.local&#8221; with your chosen custom domain name.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Press &#8220;Control + X&#8221; to exit nano, then press &#8220;Y&#8221; to save the changes, and finally press Enter to confirm the file name.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_3_Edit_the_Apache_configuration\"><\/span>Step 3: Edit the Apache configuration<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In the Terminal, enter the following command to open the Apache configuration file in a text editor:<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo nano \/Applications\/MAMP\/conf\/apache\/httpd.conf<\/pre>\n\n\n\n<p>Again, you will be prompted to enter your administrator password.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The Apache configuration file will open in the nano text editor. Search for the section that starts with &#8220;&lt;VirtualHost _default_:80&gt;&#8221;.<\/li>\n\n\n\n<li>Below that section, add the following code:<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;VirtualHost *:80>\n    DocumentRoot \"\/Applications\/MAMP\/htdocs\/yourfoldername\"\n    ServerName myproject.local\n&lt;\/VirtualHost><\/pre>\n\n\n\n<p>Replace &#8220;myproject.local&#8221; with your chosen domain name. The &#8220;DocumentRoot&#8221; folder will be the root for this custom domain.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Press &#8220;Control + X&#8221; to exit nano, then press &#8220;Y&#8221; to save the changes, and finally press Enter to confirm the file name.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_4_Restart_MAMP_servers\"><\/span>Step 4: Restart MAMP servers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In the MAMP control panel, stop the Apache and MySQL servers by clicking the &#8220;Stop Servers&#8221; button.<\/li>\n\n\n\n<li>Start the servers again by clicking the &#8220;Start Servers&#8221; button.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_5_Test_the_custom_domain_name\"><\/span>Step 5: Test the custom domain name<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open your web browser and enter your custom domain name (e.g., <a href=\"http:\/\/myproject.local\/\" target=\"_blank\" rel=\"noopener\">http:\/\/myproject.local<\/a> or whatever you have set up in step 3).<\/li>\n\n\n\n<li>If everything is set up correctly, you should see your MAMP project loaded using the custom domain.<\/li>\n<\/ul>\n\n\n\n<p>Note: Make sure that any PHP files or projects you want to access using the custom domain name are placed in the &#8220;htdocs\/yourfoldername&#8221; folder of your MAMP installation directory.<\/p>\n\n\n\n<p>By following these steps, you can configure a custom domain name for your local PHP development using MAMP on macOS. You can repeat the steps with a different domain name and root folder if you are developing for multiple projects. This will keep your projects organized. Enjoy!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To set up a custom domain name on MAMP, you&#8217;ll need to make changes to your system&#8217;s hosts file and the Apache configuration. Here are the step-by-step instructions for configuring a custom domain name on MAMP<\/p>\n","protected":false},"author":1,"featured_media":25,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[12,11,8],"class_list":["post-22","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development","tag-custom-domain","tag-mamp","tag-php"],"_links":{"self":[{"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":4,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":117,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/posts\/22\/revisions\/117"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/media\/25"}],"wp:attachment":[{"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}