How setup Apache Virtual Host to Laravel on Ubuntu Server 20.04? - laravel

I have a server running Ubuntu 20.04 and Apache 2 that I use as a webserver. I made a configuration of a virtual host to point to a Laravel application, as you can see in the configuration file below.
<VirtualHost laravel-8.test>
DocumentRoot /var/www/laravel-8/public
ServerName laravel-8.test
<Directory "/var/www/laravel-8/public">
allow from all
Options None
Require all granted
</Directory>
</VirtualHost>
And everything works perfectly on the server, but when I try to access the address laravel-8.test from another machine on the network, it goes to the Apache page. I even added in the Ubuntu hosts file to inform the address.
127.0.0.1 laravel-8.test
And I did the same on the workstation (Windows 10 Pro), I added the line
192.168.0.112 laravel-8.test
What am I doing wrong? I have the necessary Apache modules for Laravel to work (rewrite)

change your v-host config to something like this...
<VirtualHost *:80>
DocumentRoot /var/www/laravel-8/public
ServerName laravel-8.test
<Directory "/var/www/laravel-8/public">
allow from all
Options None
Require all granted
</Directory>
</VirtualHost>

If you want to connect from another PC, you need to write an external IP.

Related

Named virtual host not working in xampp windows

I have following config in extra\httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/history"
ServerName history.test.in
<Directory "C:/xampp/htdocs/history">
Options All
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
Also, I enabled this in apache\conf\httpd.conf file,
Include conf/extra/httpd-vhosts.conf
In drivers\etc\hosts file, I have
127.0.0.1 localhost
127.0.0.1 history.test.in
When I try to access http://history.test.in, site is not loading but when tried with http://localhost/history, it works. Am I doing anything wrong? Also, I don't see any error logs in Apache.
The above configuration is correct. The reason for the virtual host not working was due to incorrect settings like firewall block, anti-virus software interruption, multiple OS environment etc. in system.
This post(eye-opener) helped me found the issue in windows xampp environment: https://serverfault.com/questions/452268/hosts-file-ignored-how-to-troubleshoot
especially ipconfig /displaydns DNS command helped me find that new hosts take effect correctly.
Additionally, if you are running multiple versions of OS (windows 7, vista or windows 10) in your system, make sure you edit the running drivers\etc\hosts OS's hosts file and not the idle one.

publish xampp publically from home laptop

I'm trying to publish a locally installed WordPress website - publically.
Had to reformat my laptop, so now running Windows 10 from my laptop at home.
I can already RDP to it from e.g. work PC, externally, etc.
I used to have Windows 8, WAMP installed and used to publish websites to my domain - www.site01.co.uk
site01.co.uk has been pointing to my fixed IP since I had Windows 8 and still is pointing. The fixed IP address hasn't changed.
I now opened up XAMPP httpd.conf and placed below "code" at the bottom:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\wp"
servername http://www.site01.co.uk
<Directory "C:\xampp\htdocs\wp">
Allow from all
Require all granted
Options Indexes
</Directory>
</VirtualHost>
This didn't work .
WordPress is installed in htdocs\wp folder.
You have a couple of problems with your Virtual Hosts definition. Virtual Hosts is definitely the way to go though.
When you create a Virtual Host Apache ignores the default definition of localhost in your httpd.conf file so its always a good idea to include a VH definition for that as the first VH defined, with access limited to Require local this helps stop drive-by ip address access attempts as the Require local will return an Access denied if you/they just use your WAN ip to try and see whats on your web server.
This should go in the \xampp\apache\conf\extra\httpd-vhosts.conf file. Remove all the example stuff from that file when you add this definition.
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
<Directory "C:\xampp\htdocs">
AllowOverride All
Options Indexes FollowSymLinks
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\wp"
ServerName site01.co.uk
ServerAlias www.site01.co.uk
<Directory "C:\xampp\htdocs\wp">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
Apache 2.4 uses the Require parameter and not the Allow/Deny which was Apache 2.2 syntax.
You now edit the httpd.conf file and find the
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
and remove the # comment like so
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Then make sure that the Port Forwarding on your router is forwarding port 80 to the correct ip address for your PC.

Virtual Host is not working on XAMPP

I just tried creating a virtual host on my local machine but when I try visiting the URL on my browser, instead it connects to the internet. I have put off my internet and tried but it still doesn't route to my site folder. I don't know what I'm doing wrong.
BTW, I am using Apache 2.4
Here's my httpd-vhosts.conf code.
<directory C:/auth/public>
AllowOverride All
Require all granted
</directory>
<virtualhost *:80>
DocumentRoot "C:/auth/public"
ServerName auth.local
</virtualhost>
And here is my hosts code.
#127.0.0.1 localhost
127.0.0.1 auth.local
#::1 localhost`
What am I doing wrong here?

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>

Cannot access XAMPP (1.7.3) from my local network

I am running XAMPP 1.7.3 on windows 7. My problem is that when I try to access my server (localhost) from another computer, the server does not respond. For example, [on my computer] when I type in 'http://localhost', my pages come up. However, when I try accessing 'http://192.168.0.102' from my computer, nothing happens. When I type in my external IP, nothing shows up, but when add HTTPS to the external IP, my Linksys WRT54GS config page shows up, asking for a password. I have already tried port forwarding and a local "static IP", and no luck, other than my local IP never changing. Can anyone help me?
Here's how I have my XAMPP installation configured. Maybe it will work for you.
Open C:\xampp\apache\conf\extra\httpd-vhosts.conf
Add a VirtualHost block for each site you are running:
Apache config
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot C:/path/to/website/files
ServerName exampledomain.dev
<Directory "C:/path/to/website/files">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Add a line to your hosts
127.0.0.1 exampledomain.dev
On the connecting computer's host file:
192.168.0.102 exampledomain.dev
You can easily access your hosts file by using ctrl+r and running
notepad %SYSTEMROOT%\system32\drivers\etc\hosts

Resources