I ve got a laravel app all set up and working when my virtual host is set as follows :
ServerName mylaravelproj.com
<Directory /var/www/mylaravelproj/public>
..rules here
So all i need to do is access mylaravelproj.com/api/whateverRouteHere
However, i wouldnt know how to access the api without a domain name as
DocumentRoot /var/www/mylaravelproj/public
<Directory /var/www/mylaravelproj/public>
..rules here
doesnt work when accessing 192.168.xxx.xxx/mylaravelproj/public/api/whateverRouteHere
Im quite new to configuring apache and a little confused as to why this doesnt work.
If your server is listening for the domain mylaravelproj.com, then why don't you add an entry to your hosts file like this:
192.168.xxx.xxx mylaravelproj.com
And then flush your DNS cache and then visit http://mylaravelproj.com and you should be able to access your app.
On windows, this is how I usually setup laravel apps. I use XAMPP, so I add the following entry to: C:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
ServerName mylaravelproj.com
DocumentRoot "C:/xampp/htdocs/mylaravelproj/public"
</VirtualHost>
and then get my LAN ip in windows using ipconfig /all in Command Prompt (say my LAN ip is 192.168.1.122) and then set it on the hosts file: C:\Windows\System32\drivers\etc\hosts
192.168.1.122 mylaravelproj.com
then in Command Prompt, flush the DNS Cache using ipconfig /flushdns
Note* it's not good idea to run your dev env using full domain, you should use something like mylaravelproj.dev or mylaravelproj.local
Related
I want to access my virtual hosts (websites) that I've set up in my VirtualBox -> Ubuntu-Server 18. I have apache2 installed and everything is setup.
The host machine (macOS) can presently gain access to the default website of apache2 in the guest (Ubuntu-server) through a Port Forwarding rule I have assigned in the VirtualBox Network Settings:
127.0.0.1:8000 -> 10.0.2.15:80
I've set up a virtual host in my guest machine with the following configuration:
<VirtualHost *:80>
ServerName dropn.taxi
ServerAdmin admin#dropn.taxi
DocumentRoot /var/www/dropn.taxi/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The DocumentRoot directory mentioned above exists and has the files necessary to serve a basic "Hello World" home page. I've tested it with my apache installed in my local machine as well. The website's not the problem.
But everytime I access localhost:8000 from the local machine, I'm greeted with an Ubnutu-Apache greetings page. Whereas when I try localhost:8000/dropn.taxi, I get a 404 page. I've researched quite a bit and the closest I can get to a solution is what is suggested in this page:
Ubuntu Apache2 local virtual hosts url not found
Simply put: How can I access virtual hosts of the guest machine (VM) from the host machine?
Still not specific to my case. Would appreciate any help in this regards.
localhost in the apache2 server is set to point to /var/www/html by default. For the virtual hosts to work properly, the domain name accessing them must be what is defined in the ServerName field.
localhost:8000/dropn.taxi would translate to 127.0.0.1/dropn.taxi in the VM guest. Which means, it is trying to access the /var/www/html/dropn.taxi, which, ultimately does not exist, hence the 404 error.
The solution to this is to add dropn.taxi to the /etc/hosts file in both the Host Machine and the VM. The line would look like:
127.0.0.1 localhost dropn.taxi
While accessing from the Host Machine, we use dropn.taxi:8000 in the browser whereas the port :8000 is not used in the guest machine. This way, whenever accessing the virtual hosts, the domain name accessing them matches the ServerName field and it simply works!
I just got stuck in the very begining. I have installed laravel and when i run php artisan serv command then this(Laravel development server started on http://localhost:8000/) line appears but when i access it through browser(http://localhost:8000/) then the following error gets displayed.
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.2
Please help me out. Any help would be greatly appreciated. I am beginner in laravel.
Follow the steps below to create a virtual host:
Change to your XAMPP installation directory (typically, C:\xampp) and open the " httpd-vhosts.conf " and " httpd-xampp.conf " files in the apache\conf\extra\ subdirectory using your favourite text editor.
Add these lines into both files with the following directives:
<VirtualHost *:80>
DocumentRoot "C:\Users\Shivam\Desktop\laravel_project\blog"
ServerName blog.dev
<Directory "C:\Users\Shivam\Desktop\laravel_project\blog">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
This contains two virtual host configuration blocks:
The first block is the default or fallback virtual host, which is used for all requests that are not matched by subsequent blocks.
The second block sets up a virtual host named wordpress.localhost. The DocumentRoot directive specifies the directory to be used when serving requests for this virtual host (in this case, the WordPress installation directory), while the ServerName directive specifies the custom domain name for the virtual host.
To add more virtual hosts, simply duplicate the second virtual host block and modify the port number, DocumentRoot and ServerName directives as per your requirements. For example, if you want to use SSL with your custom domain name, you can add a new virtual host block for port 443.
If you plan to have a large number of virtual hosts with very similar configuration, consider using wildcard-based subdomains with your virtual hosts.
Restart Apache using the XAMPP control panel for your changes to take effect.
At this point, your virtual host is configured. However, if you try browsing to the wordpress.localhost domain, your browser will show a failure notice, since this domain does not exist in reality. To resolve this, it is necessary to map the custom domain to the local IP address. To do this, open the file C:\windows\system32\drivers\etc\hosts and add the following line to it:
127.0.0.1 blog.dev
This takes care of mapping the wordpress.localhost domain name to the local machine, which always has the IP address 127.0.0.1
It seems to me that you already have Apache running on port 8000.
Try running the serve command like this:
php artisan serve --port=9000
After it's running navigate to http://localhost:9000
I have set up my OVH server, installing apache2, php5, mysql, phpmyadmin etc... And configured the vhosts.
The content of my VirtualHost file :
<VirtualHost *:80>
ServerName www.abracadabook.fr
ServerAlias abracadabook.fr *.abracadabook.fr
DocumentRoot /home/abracadabook/www/
<Directory /home/abracadabook/www/>
Options -Indexes
AllowOverride All
</Directory>
</VirtualHost>
When I type the ip address of my server, it displays the apache default page. But after setting up my windows hosts file (I'm on windows but the server's on linux), when I try accessing abracadabook.fr the site is loaded and the root directory is right (/home/abracadabook/www) and it displays the normal index of my website. But the problem is that the site is not accessible from another client machine.
When I try to access to it from a PC which host file is not set up, nothing will load even when I access it with the ip address.
I searched in many boards and forum but never found the solution.
I hope you can help me.
Regardly,
(PS Sorry for my bad english)
Turns out I had not the good informations.
I followed this tutorial step by step and it works well now.
Kimsufi DNS setting Tutorial (French)
I'm using local server where XAMPP is running on. This local server is in the same network as my own computer. Now I want to access different site's running on that server. I had the following in mind.
My local server IP is 10.0.0.2. In my own hosts file I added the following.
10.0.0.2 www.domain.nl
Now when I enter www.domain.nl in my browser, I will be redirected to the server's localhost.
At the server, I added a VirtualHost to the httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/domain
ServerName localhost
</VirtualHost>
So now I will be redirected to the website running in the folder domain.
The problem
The problem now is, I also have a other website running on the local server. This one is on
the local server located in c:/xampp/htdocs/anotherdomain.
Adding another virtualhost does now only work on the local server itself, but not remote, because from remote I will always have the ServerName localhost.
How will I set this up? Hope you all understand my problem and someone knows how to get this working.
Is it possible to use xip.io to access local website when using virtualhosts with different server names? (I'm on linux, fedora).
For instance, let's say I have 3 websites I can access locally like so:
- http://localsite1
- http://localsite2
- http://localsite3
I would like to access them with other devices via xip.io:
- http://localsite1.192.168.0.15.xip.io
- http://localsite2.192.168.0.15.xip.io
- http://localsite3.192.168.0.15.xip.io
I can't figure out how to make this work, is it even possible?
Yes, it should be possible. I think you can have as many localsite domains as you want to manage. Check your hosts and httpd-vhosts.conf files.
A server alias in my /etc/apache2/extra/httpd-vhosts.conf works for me. I use a * instead of the current IP in my Network Preferences.
Remember to restart the Apache server after you make a change.
For example, my current local IP from the Mac OS System Preferences > Network says: Wi-Fi is connected to Workalicious2011 and has the IP address 10.0.1.118.
So my /etc/apache2/extra/httpd-vhosts.conf file has the following:
# Ensure that Apache listens on port 80
Listen 80
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Users/davekaplan/Sites/workalicious.com"
ServerName dev.workalicious.com
ServerAlias dev.workalicious.com.*.xip.io
ErrorLog "/private/var/log/apache2/dev.workalicious.com-error_log"
CustomLog "/private/var/log/apache2/dev.workalicious.com-access_log" common
</VirtualHost>
And my /etc/hosts file has:
##
Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 dev.workalicious.com
On my local network I am able to browse to the following and see my local development site:
http://dev.workalicious.com.10.0.1.118.xip.io/
I have a similar problem where I'm working on one mac and want to test on computers and other devices. Using .xip.io works great when you don't have access to a hosts file, on say a tablet.
If you have access to your hosts file on the computer you can add the IP of the local development host computer and just browse to the same url. It's great for PCs or other Macs. For example, I would add 100.0.1.118 dev.workalicious.com to the testing computer's hosts file and as long as I'm on the local network I can browse to dev.workalicious.com on that testing computer and see the site hosted over on the development computer.
Another approach that I used before .xip.io is Charles, it works great and there are some good blog posts out there on how to setup. It's currently $50 for a 1-4 Users.
( I'm working on try to figure out how to use Pow and Apache for a similar approach, but I don't think it works outside the local development machine. )
for me, server alias work.
ex:
<VirtualHost *:80>
<Directory "/home/michelangelo/www/mysite">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
ServerAdmin michelangelo#mystie.com
DocumentRoot /home/michelangelo/www/mysite
ServerName mysite.local
ServerAlias mysite.local.192.168.0.6.xip.io
ErrorLog /home/michelangelo/public_html/logs/mysite_error_log
CustomLog /home/michelangelo/public_html/logs/mysite_access_log common
</VirtualHost>
tested on lubuntu
I was working on my project today and got stuck for a while but I've found a really easy setup which works like a charm.
You setup your virtualhost as you used to (do not have to use the alias xip.io at all tried it today)
Here comes the interesting part, when you edit host hosts file, enter your assigned local IP number before your domain name, e.g. 192.168.10.110 myawesomewebsite.com - which you can access at myawesomewebsite.com.192.168.10.110.xip.io