简体   繁体   中英

Creating virtual host for laravel in Lamp

I have laravel setup and I am trying to create subdomain routing. Basically my route needs to accept this parameter blog.example.dev

I have my routes set up now I just need to create virtual host. As my domain in laravel app accepts blog.example.dev . What are the steps I need to do in order to create the virtual host? Also any other changes should I make in application like htaccess. I am using latest version of laravel

For the OS I am using Ubuntu 17.

Edit: Making virtual host is quite easy in linux but it doesn't work anything like how I imagined. The laravel serve should start the page but it doesn't and page is unreachable even if I make virtual host. Any tips would be great I have tried to create virtual host via DigitalOcean blog. https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

source

A while back, Google purchased the .dev TLD (Top Level Domain). At that time, they announced that they had no plans for it and that they were only going to use it for internal purposes. For years, the .dev TLD was primarily used for developers and designers to use in their local development environments. It was considered general acceptable use and, as a result, developers everywhere are now running sites locally which may now be affected.

Recently Google announced that in a soon to be released update to Chrome, they will be forcing .dev to HTTPS. In short, this means that if you are running local sites using .dev AND running Google Chrome, you will find your site unreachable. Fortunately, there are a couple of options which are fairly simple to implement to get around this issue. Keep in mind that since .dev has been a standard TLD for local development for some time, this new policy by Google will affect you whether you are using DesktopServer or any other local development tool which utilizes the .dev TLD. This issue is NOT specific to DesktopServer.

Therefore you need to use any other extension other than .dev like .com , .test . In your virtual hosts file of apache add new entry as follows:-

<VirtualHost *:80>

ServerAdmin webmaster@dev.blog.com
ServerName dev.blog.com
ServerAlias dev.blog.com
DocumentRoot /var/www/blog/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

And add this new entry to your local machine hosts file:-

127.0.0.1 dev.blog.com

Restart the apache server to load new changes.

Note:- blog is the name of your laravel project. Change it according to what you have named.

`<VirtualHost *:80>
ServerAdmin webmaster@dummy.com
ServerName projectname.local
ServerAlias projectname.local
DocumentRoot "c:xampp/htdocs/projectname/public"
 ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>`

Make virtual host using .local

127.0.0.1 projectname.local

Add this line in your host file And restart your local server

Solved

Basically I just created the virtual host but I noticed some strange behaviour in laravel after placing subdomain on top of file it worked. I didn't knew that laravel would process suddomain routes first and if you place subdomain routes after some routes then it didn't work then you would not get desired routes.

About apache it seems that I couldn't make the subdomain work and from what I have learned in local environment how it works is that domain must come first here.

ServerAlias blog.example.dev didn't work in ServerName example.dev domain.

I created two seperate virtual host one for example.dev and another for blog.example.dev . Also thanks to parthu_panther I changed the .dev to another .local .

Also the hosts file was same

127.0.0.1 example.local

127.0.0.1 blog.example.local

Please correct me if I am wrong.

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