Trouble setting up a virtual host for my local Laravel project - macos

I'm on OSX (El Capitan), using XAMPP and trying to use a local URL for my project. The idea is to run http://projectname.local in the browser and see that it points to Programma's/XAMPP/xamppfiles/htdocs/projectname/public, and the same if I enter http://localhost/projectname/public.
I've edited my hosts file like below:
127.0.0.1 projectname.local
I've followed the steps in this tutorial (enabling vhosts and setting one up)
This is the vhost configuration I have:
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
ServerName projectname.local
ServerAlias www.projectname.local
DocumentRoot "/Programma's/XAMPP/xamppfiles/htdocs/projectname/public"
ErrorLog "/Programma's/XAMPP/xamppfiles/htdocs/projectname/storage/logs/laravel.log"
CustomLog "/Programma's/XAMPP/xamppfiles/htdocs/projectname/storage/logs/laravel_custom.log"
</VirtualHost>
I've flushed the cache using dscacheutil -flushcache and ran apachectl restart
But when I go to http://projectname.local I get the XAMPP dashboard rather than my project's Laravel welcome route.
Am I missing something?

Related

Windows - Apache DocumentRoot in VirtualHost ignored

On my Windows 7 PC, I'm using XAMPP => Apache to run a testing webserver. But for a certain website I don't want the regular "C:\xampp\htdocs", but a custom path - which when I work on Ubuntu I usually setup in VirtualHost just as a DocumentRoot and it works.
On this PC the target path is similar to: "C:\Users\X\Disk External\DIRWITHDIÁCRÍCÍCS\WEBS\some path\path"
However on this PC when I do
<VirtualHost test2020.test:443>
DocumentRoot "C:\Users\X\Disk External\DIRWITHDIÁCRÍCÍCS\WEBS\some path\path"
ServerName test2020.test
ServerAlias www.test2020.test
</VirtualHost>
The DocumentRoot directive is completely ignored - it still seems to target files in the default C:\xampp\htdocs
I've also tried moving the files around the system and changing forward/backward slashes with no success:
DocumentRoot "C:/Users/X/Disk External/DIRWITHDIÁCRÍCÍCS/WEBS/some path/path"
DocumentRoot C:\xampp\htdocs\testdocumentroot
DocumentRoot "C:\Users\X\www"
Also I've tried swapping order of DocumentRoot and ServerName with no success.
I've checked C:\xampp\apache\conf\httpd.conf - the line Include conf/extra/httpd-vhosts.conf IS uncommented.
And the file C:\xampp\apache\conf\extra\httpd-vhosts.conf seems to affect apache start-up when set-up wrongly.
EDIT: also I did restart apache between each try :)
What am I missing?
So it's just my idiotism, I've tried to overdomain everything, but the directive attribute inside the VirtualHost tag is for network incoming limitation. For regular cases * is just fine there, also then I had a problem with Directory tag directive because aparently there's a new directive for Apache 2.4+
<VirtualHost test2020.test:443> => <VirtualHost *:443>
Working final code:
# (or *:80 for http:// , 443 is for https://)
<VirtualHost *:443>
DocumentRoot "C:\Users\X\Disk External\DIRWITHDIÁCRÍCÍCS\WEBS\some path\path"
ServerName test2020.test
ServerAlias www.test2020.test
<Directory "C:\Users\X\Disk External\DIRWITHDIÁCRÍCÍCS\WEBS\some path\path">
# NEW&SIMPLE FROM APACHE 2.4+ !
Require all granted
</Directory>
</VirtualHost>

How do I reset Xampp's default page?

I used to be able to go to localhost on my windows PC with xampp running and be shown the /dashboard page which is fine. I think I made a mistake with a Laravel install and now when I go to localhost I get a Laravel landing page.
How can I reset this so it goes back to the default /dashboard page?
I've tried this in http-vhosts.conf but didn't help:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
This is the default it was at before. I can't do a local Wordpress install any more as when I drop the folder in htdocs and navigate in the browser it gives a Laravel 404 error.
In C:\xampp\apache\conf\httpd.conf
set
DocumentRoot "C:/xampp/htdocs"
In C:\xampp\apache\conf\extra\httpd-vhosts.conf
Add below settings
<VirtualHost *:80>
ServerAdmin webmaster#localhost.com
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
Hope this will help

laravel virtual host setup not showing front-end

I have a new laptop, and am now trying to run a laravel application.
First, am trying to setup a virtual host for the project so that I can access blog.local
I went my hosts file and setup the drivers like the following:
127.0.0.1 localhost
127.0.0.1 test.local
127.0.0.1 blog.local
The for the apache configuration I have the following:
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs\blog"
ServerName blog.local
</VirtualHost>
When I try to access my url I do not see the site but the files only:
For this and future projects, how can I create a local url and see the front-end when I visit it?
You need to address your public folder,
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs\blog\public"
ServerName blog.local
</VirtualHost>
The document root is a directory (a folder) that is stored on your host's servers and that is designated for holding web pages. When someone else looks at your website, this is the location they will be accessing.
Change the DocumentRoot to according to your PHP project is located.
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/blog/public"
ServerName blog.local
</VirtualHost>
Restart the servers after making any changes! If you don’t reset the server to apply the changes, nothing will work even though you know you’ve done everything right.

Create a Vhost in 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>
Setup a virtual host for a Laravel project
First, copy the default configuration file and rename it:
$sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myVhost
open myVhost.conf file using this command:
$sudo nano /etc/apache2/sites-available/myVhost.conf
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.
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.
Enable site and the rewrite mode:
$sudo a2enmod rewrite
$sudo a2ensite myVhost.conf
Restart the server:
$sudo service apache2 restart
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
Open the browser:
http://www.myAwesomeLink.com:8000
or any other specified port.
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.
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.
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

Keep XAMPP default page as developing website

I am preparing to create my portfolio site and this is something I always thought. I find XAMPP default admin page useful in some ways to me, but as I am developing website, I can't access it any more.
I want to know is there a way to keep XAMPP default page as I am developing other websites.
I know I can setup virtual hosts for several websites, but is it same for XAMPP? I have done virtual host one time as work. At, first it didn't work(what was CakePHP app), but later I have managed to make it work.
UPDATE:
So I found out this post about Hosting multiple local sites with XAMPP and have edited my Virtual Host config file like this:
<VirtualHost *:80>
ServerName localhost/xampp
DocumentRoot "C:/xampp/htdocs/xampp/"
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs/"
</VirtualHost>
My windows host file:
127.0.0.1 localhost
127.0.0.1 localhost/xampp
For now, accessing both 127.0.0.1 and 127.0.0.1/xampp redirect me to XAMPP home page, which is in C:/xampp/htdocs/xampp/
When I access localhost, browser redirects me to index.php file(As 127.0.0.1 also should), which is for testing purposes in htdocs folder. However if I try to access localhost/xampp I get error in Chrome - "This webpage has a redirect loop".
I have no idea how to progress on from here.
I found out answer. THe issue was with my naming of xampp admin page domain, instead of using someting, which include localhost for xampp page, I had to use something else, as it will not conflict when using your own naming.
So my hosts file now:
127.0.0.1 localhost
127.0.0.1 xampp-admin
And Apache Virtual Host file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs/"
</VirtualHost>
<VirtualHost *:80>
ServerName xampp-admin
DocumentRoot "C:/xampp/htdocs/xampp/"
<Directory "C:/xampp/htdocs/xampp/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This part(below) didn't change anything, I added, because I saw it in examples, but I still have no idea, what it's useful to:
<Directory "C:/xampp/htdocs/xampp/">
Order allow,deny
Allow from all
</Directory>
Still, maybe someone can suggest me more conventional name for Xampp admin page?
All you need to is place this at the top of your httpd-vhost.conf before other virtual host configurations.
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/dashboard/"
ServerName xampp.admin
<Directory "C:/xampp/htdocs/dashboard/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Resources