Search code examples
phpwordpresslocalhostlamp

Set localhost name to custom name inside for local wordpress setup


I want to put a live wordpress site in my local environment, let's say for example the site url is www.test.com , this opens the page, so when I normally set up a local environment in /var/www/html (using lamp btw) i create a directory let's say test (/var/www/html/test) and update in the database the siteurl and home links to http://localhost/test

So when I write in the browser http://localhost/test it will open....but I want to change the hostname and url directy, I want to have in my local environment something like http://local.test.com


Solution

  • Here is simplest way to convert your localhost to a domain name
    if you are on windows follow this steps;

    1- goto C:\Windows\System32\drivers\etc (C:\windows is your windows installation folder)
    2- seek on a file called "hosts" (may be marked as hidden or system)
    3- open it with text editor like notepad
    4- find line containing "127.0.0.1 localhost"
    5- add new line below it containing "127.0.0.1 www.google.com"
    6- save file and its done!

    Note: replace www.google.com with every domain name that you like
    Note: if you have problem in editing this file just boot your windows in safe mode and you will be able to edit and save it

    UPDATE
    if you are using Linux or Mac there is same way!
    in linux edit this file /etc/hosts
    in mac edit this file /private/etc/hosts