Create a Vhost in Ubuntu 16.04

烈酒焚心 提交于 2019-12-10 10:19:54

问题


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>

回答1:


Setup a virtual host for a Laravel project

  1. First, copy the default configuration file and rename it:

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

  1. open myVhost.conf file using this command:

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

  1. Add the directives:

assuming that the Laravel project is in /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:

save and close.

  1. Now add an entry in the hosts file:

$sudo nano /etc/hosts

add this line:

127.0.0.1   www.myAwesomeLink.com

save and close.

  1. Enable site and the rewrite mode:

$sudo a2enmod rewrite

$sudo a2ensite myVhost.conf

  1. Restart the server:

$sudo service apache2 restart

  1. Serve the Laravel project:

open the project folder

php artisan serve

this will serve on port 8000 by default

you can also specify the port

php artisan serve --port=4200

  1. Open the browser:

http://www.myAwesomeLink.com:8000

or any other specified port.




回答2:


Source.

Its not working because the browsers have updated their security terms and policies including SSL certificates over .dev domains. just change your extension from .dev to something else like .localhost or .test.

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

Also change the extension in /etc/hosts from .dev to .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

Hope it helps.




回答3:


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

127.0.0.1 mywebsite.dev

You will need to restart server after this.




回答4:


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

2.Copy the following to the file

  # 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"

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

5.Restart apache server



来源:https://stackoverflow.com/questions/49606407/create-a-vhost-in-ubuntu-16-04

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!