laravel 在 Ubuntu 16.04 中创建 Vhost

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49606407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:35:20  来源:igfitidea点击:

Create a Vhost in Ubuntu 16.04

laravelubuntulampp

提问by Vasim Shaikh

I have started working in laravel and using lampp. I have watched many tutorials that use a vhost to make user-friendly url. I want to do it on Ubuntu 16.04.

我已经开始在 laravel 工作并使用 lampp。我看过很多使用 vhost 制作用户友好网址的教程。我想在 Ubuntu 16.04 上做。

Following tutorial is not working for me:

以下教程对我不起作用:

https://ourcodeworld.com/articles/read/302/how-to-setup-a-virtual-host-locally-with-xampp-in-ubuntu

https://ourcodeworld.com/articles/read/302/how-to-setup-a-virtual-host-locally-with-xampp-in-ubuntu

<VirtualHost *:80>
    DocumentRoot "/opt/lampp/htdocs/basicwebsite/public"
    ServerName mywebsite.dev
</VirtualHost>

回答by Mouhammed Elshaaer

Setup a virtual host for a Laravel project

为 Laravel 项目设置虚拟主机

  1. First, copy the default configuration file and rename it:
  1. 首先,复制默认配置文件并重命名:

$sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myVhost

$sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myVhost

  1. open myVhost.conf file using this command:
  1. 使用以下命令打开 myVhost.conf 文件:

$sudo nano /etc/apache2/sites-available/myVhost.conf

$sudo nano /etc/apache2/sites-available/myVhost.conf

  1. Add the directives:
  1. 添加指令:

assuming that the Laravel project is in /var/www/html/

假设 Laravel 项目在 /var/www/html/

ServerAdmin webmaster@localhost
serverName www.myAwesomeLink.com
DocumentRoot /var/www/html/laravel-app/public


<Directory /var/www/html/laravel-app>
        AllowOverride All
</Directory>

so now the file will look something like this:

所以现在文件看起来像这样:

myVhost.conf file

myVhost.conf 文件

save and close.

保存并关闭。

  1. Now add an entry in the hosts file:
  1. 现在在 hosts 文件中添加一个条目:

$sudo nano /etc/hosts

$sudo nano /etc/hosts

add this line:

添加这一行:

127.0.0.1   www.myAwesomeLink.com

save and close.

保存并关闭。

  1. Enable site and the rewrite mode:
  1. 启用站点和重写模式:

$sudo a2enmod rewrite

$sudo a2ensite myVhost.conf

$sudo a2enmod 重写

$sudo a2ensite myVhost.conf

  1. Restart the server:
  1. 重启服务器:

$sudo service apache2 restart

$sudo 服务 apache2 重启

  1. Serve the Laravel project:
  1. 为 Laravel 项目服务:

open the project folder

打开项目文件夹

php artisan serve

php工匠服务

this will serve on port 8000 by default

默认情况下,这将在端口 8000 上提供服务

you can also specify the port

您还可以指定端口

php artisan serve --port=4200

php 工匠服务 --port=4200

  1. Open the browser:
  1. 打开浏览器:

http://www.myAwesomeLink.com:8000

http://www.myAwesomeLink.com:8000

or any other specified port.

或任何其他指定的端口。

回答by Parth Pandya

Source.

来源

Its not working because the browsers have updated their security terms and policies including SSL certificates over .devdomains. just change your extension from .devto something else like .localhostor .test.

它不起作用,因为浏览器已更新其安全条款和策略,包括.dev域上的SSL 证书。只需将您的扩展名从.dev其他内容更改为.localhost.test

<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/basicwebsite/public"
ServerName dev.mywebsite.test
</VirtualHost>

Also change the extension in /etc/hostsfrom .devto .test.

还将扩展名/etc/hosts从更改.dev.test

127.0.0.1  dev.mywebsite.test

Also keep in mind to restart the service to load the new added virtual host i.e: restart the Apache server

还要记住重新启动服务以加载新添加的虚拟主机即:重新启动Apache服务器

Hope it helps.

希望能帮助到你。

回答by Ahsan

I think you also need to add a host in /etc/hosts. Open the hosts file and add this line:

我认为您还需要在/etc/hosts. 打开主机文件并添加以下行:

127.0.0.1 mywebsite.dev

You will need to restart server after this.

在此之后,您将需要重新启动服务器。

回答by Abishek Biji

1.Create new file under this path /etc/apache2/sites-available/myweb.conf

1.在此路径下创建新文件/etc/apache2/sites-available/myweb.conf

2.Copy the following to the file

2.将以下内容复制到文件中

  # Indexes + Directory Root.
  DirectoryIndex index.php
  DocumentRoot /var/www/html/mywebsite/public
  ServerName dev.mywebsite.test
  <Directory "/var/www/html/mywebsite/public">
  Options All
  AllowOverride All
  Allow from all

  </Directory>

3.Run "sudo a2ensite myweb.conf"

3.运行“sudo a2ensite myweb.conf”

4.Add this line "Listen 80" to file "/etc/apache2/ports.conf"

4.将“Listen 80”这一行添加到文件“/etc/apache2/ports.conf”中

5.Restart apache server

5.重启apache服务器