在Ubuntu 16.04中创建虚拟主机 [英] Create a Vhost in Ubuntu 16.04
问题描述
我已经开始在laravel中工作并使用Lampp.我看过许多使用虚拟主机制作用户友好的URL的教程.我想在Ubuntu 16.04上做到这一点.
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.
以下教程对我不起作用:
Following tutorial is not working for me:
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>
推荐答案
为Laravel项目设置虚拟主机
- 首先,复制默认配置文件并重命名:
$ 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
- 使用以下命令打开myVhost.conf文件:
$ sudo nano/etc/apache2/sites-available/myVhost.conf
$sudo nano /etc/apache2/sites-available/myVhost.conf
- 添加指令:
假设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:
保存并关闭.
- 现在在主机文件中添加一个条目:
$ sudo nano/etc/hosts
$sudo nano /etc/hosts
添加此行:
127.0.0.1 www.myAwesomeLink.com
保存并关闭.
- 启用站点和重写模式:
$ sudo a2enmod重写
$sudo a2enmod rewrite
$ sudo a2ensite myVhost.conf
$sudo a2ensite myVhost.conf
- 重新启动服务器:
$ sudo服务apache2重新启动
$sudo service apache2 restart
- 为Laravel项目服务:
打开项目文件夹
php工匠服务
php artisan serve
默认情况下,该端口将在端口8000上投放
您还可以指定端口
php artisan服务--port = 4200
php artisan serve --port=4200
- 打开浏览器:
或任何其他指定的端口.
or any other specified port.
这篇关于在Ubuntu 16.04中创建虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!