简体   繁体   中英

The requested URL could not be retrieved while trying to access Laravel project on Virtual Host with XAMPP

I want to create a virtual host for my Laravel project with XAMPP, so I have followed these steps:

Step 1) C:\\WINDOWS\\system32\\drivers\\etc\\ Opened the "hosts" file (as Administrator):

127.0.0.1       test.com

Step 2) xampp\\apache\\conf\\extra\\httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/freedeliveries/public"
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/freedeliveries/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>    
    ServerName www.test.com
</VirtualHost>

Step 3) C:\\xampp\\apache\\conf\\httpd.conf . Scrolled down to the Supplemental configuration section at the end, and located the following section (around line 500), Removed the # from the beginning of the second line so the section now looks like this:

#Virtual hosts
Include conf/extra/httpd-vhosts.conf

Step 4) Restarted XAMPP and now run this in my browser :

www.test.com

But now I get this as result:

ERROR The requested URL could not be retrieved

The following error was encountered while trying to retrieve the URL: http://test.com/

Unable to determine IP address from hostname test.com

The DNS server returned:

Name Error: The domain name does not exist.
This means that the cache was not able to resolve the hostname presented in the URL. Check if the address is correct.

Your cache administrator is root.

So how to solve this and ran the Laravel project on a virtual hostname?

UPDATE:

在此处输入图片说明

Follow these steps you will get your solution

1. Creating local domain for your project:

so you need to modify the hosts file of Windows located in

C:\Windows\System32\drivers\etc\hosts

Then add the host using a custom host on your system, in this case we will add the 127.0.0.2 host that will be accesible as well with an alias of “ www.test.com ”.

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.2 www.test.com

2. Configure Virtual Host The entry point of a laravel application is the index.php inside the public folder, so the desired directory for our application will be the absolute path to your project in the public folder as shown in the following example. The virtual host needs to point out the same host declared in the hosts file of windows (in this case 127.0.0.2) at the port 80. You can create this virtual host appending the following snippet at the end of the content of the httpd-vhosts.conffile located in the

xampp folder \\xampp\\apache\\conf\\extra

 <VirtualHost 127.0.0.2:80>
 DocumentRoot “C:/xampp/htdocs/freedeliveries/public”
 DirectoryIndex index.php
 ServerName www.test.com
 <Directory “C:/xampp/htdocs/freedeliveries/public”>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride all
 Order Deny,Allow
 Allow from all
 Require all granted
 </Directory>
 </VirtualHost>

3. Open your project from the browser Finally as expected, by visiting either www.test.com or 127.0.0.2 in your browser will show the entry point of your Laravel application:

For More Details Follow this URL .

port in use problem solution

Disable the FTP Server that is already running (most likely running via Windows Add/Remove Programs -> Windows Features). Otherwise, you will need to change the port in the FileZilla settings located at %APPDATA%/FileZilla

If you want to support subdomains in your project, you would need a DNS service. you can simply go with Acrylic DNS Service , the configuration setup is here .

If using Acrylic DNS service

  1. Go to Acrylic UI
  2. Open Acrylic Host from File>Open Acrylic Hosts
  3. Place 127.0.0.1 *.test.com test.com at the bottom of the host file
  4. Restart the DNS service from Actions>Restart Aclyic Service
  5. Place 127.0.0.1 test.com in your windows host file

You may also setup your vhost file supporting the domain in httpd-vhosts.conf

<VirtualHost test.com:80>
    DocumentRoot "C:/xampp/htdocs/freedeliveries/public"
    ServerName test.com
    ServerAlias *.test.com
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/freedeliveries/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>    
</VirtualHost>

Simply add this routing to your .htaccess file in /public folder . Credits to @randall adding this answer

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

If not using a DNS service

If you want www.test.com only you could simply specify the host in your windows host file as 127.0.0.1 www.test.com as @rakesh has shown and follow the steps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM