简体   繁体   English

Xampp 上用于 Laravel 的虚拟主机无法正常工作

[英]Virtual Host on Xampp for Laravel is not working

Hello i am learning Laravel and trying to modifying vhost file of my xampp server for laravel practice project, but its not working.您好,我正在学习 Laravel 并尝试为 laravel 练习项目修改我的xampp服务器的vhost文件,但它不起作用。 code of vhost file is vhost文件的代码是

<VirtualHost *:80>
    DocumentRoot "D:/xampp/htdocs/laravel5Prc/public"
    ServerAdmin admin@localhost
    ServerName laravel5.prc
    ServerAlias laravel5.prc

    <Directory "D:/xampp/htdocs/laravel5Prc/public">
       AllowOverride All
       Options Indexes FollowSymLinks

       Require local
       # if you want access from other pc's on your local network
       #Require ip 192.168.1.121
       # Only if you want the world to see your site
       #Require all granted
    </Directory>
</VirtualHost>

i have taken this code from this url How to enable Virtual Host on Xampp for Laravel?我从这个 url 中获取了这段代码如何在 Xampp 上为 Laravel 启用虚拟主机?

its not working form me, anyone please guide me what am i doing wrong in it?它对我不起作用,有人请指导我我做错了什么吗?

why you don't use php artisan serve to run laravel on localhost.为什么不使用php artisan serve在本地主机上运行 laravel。

from https://laravel.com/docs/5.4/来自https://laravel.com/docs/5.4/

I'm strongly recommend you to use Laravel's vagrant box called Homestead instead of xampp, it's really amazing!我强烈建议你使用 Laravel 的名为 Homestead 的 vagrant box 而不是 xampp,它真的很棒! You can read about it here .你可以在这里阅读它。 It's much more flexible and easier to understand than anything else.它比其他任何东西都更加灵活和易于理解。

I was using php-7.3.2 and had similar problem.我使用的是 php-7.3.2 并且遇到了类似的问题。 This is not the solution to the problem, but an alternative.这不是问题的解决方案,而是替代方案。 I went back to php-7.1.25 and ran again.我回到 php-7.1.25 并再次运行。 I'm still going to check out what the problem is with version 7.3 and laravel, but maybe this will help some people who come here with the same problem.我仍然会检查 7.3 版和 laravel 的问题是什么,但也许这会帮助一些遇到同样问题的人。

This is what you should do, add or uncomment this below at the top of the xampp vhost file这是你应该做的,在 xampp vhost 文件的顶部添加或取消注释

NameVirtualHost *:80

Change this to you valid assumed domain and add the Directory index将此更改为您有效的假定域并添加目录索引

ServerName laravel5.test
ServerAlias laravel5.test
DirectoryIndex index.php

And then go to the this folder C:\\Windows\\System32\\drivers\\etc\\hosts in windows and add your domain of choice for example see this below然后转到 Windows 中的此文件夹 C:\\Windows\\System32\\drivers\\etc\\hosts 并添加您选择的域,例如见下文

127.0.0.2      laravel5.test
127.0.0.3      anotherdomain.test

**** Please note don't use the localhost or 127.0.0.1 created by default to set yours's you should create you own eg (127.0.0.2, 127.0.0.3, 127.0.0.4) in that order **** 请注意不要使用默认创建的 localhost 或 127.0.0.1 来设置你的你应该创建你自己的,例如 (127.0.0.2, 127.0.0.3, 127.0.0.4) 在那个顺序

After then restart you xampp server you should be good to go然后重启你的xampp服务器,你应该很高兴

**** I notice your Document and Directory has this "D:/xampp/htdocs/laravel5Prc/public" change the D to C and please I would advise your laravel project should be outside the xampp folder, you can use the Document folder for this. **** 我注意到您的文档和目录有这个“D:/xampp/htdocs/laravel5Prc/public”将 D 更改为 C,请我建议您的 Laravel 项目应该在 xampp 文件夹之外,您可以使用 Document 文件夹为此。

//Open C:\Windows\System32\drivers\etc\hosts
127.0.0.1  laravel5.prc

//Open xampp/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
  ServerAdmin webmaster@dummy-host2.example.com
  DocumentRoot "C:/xampp/htdocs/laravel5Prc/public"
  ServerName laravel5.prc
  ErrorLog "logs/dummy-host2.example.com-error.log"
  CustomLog "logs/d`enter code here`ummy-host2.example.com-access.log" common
</VirtualHost>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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