Reputation: 5663
I am using ubuntu 16.04 and working on a laravel
project.
I have a new laravel project in /var/www/html
named myproject
and can access it by going to
localhost/myproject/public/
But in order for the routes to work, I found a solution to create a site in /etc/apache2/sites-available
like this:
<VirtualHost *:80>
ServerName myproject.dev
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/myproject/public
<Directory /var/www/html/myproject>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and then added a new entry in /etc/hosts
file, like this:
127.0.0.1 localhost
127.0.1.1 myhostname
127.0.0.1 myproject.dev
restarted apache now can access the project using http://myproject.dev
in the browser.
Now I want to test some responsive stuff using an actual phone.
I tried http://myproject.dev
it doesn't work, also if I do
http://myhostname/myproject/public
It takes me to the landing page, but accessing any other route gives a 404. and this format also doesn't work on the computer browser.
However this works on the computer:
http://localhost/myproject/public
but not on the phone.
How can I access the myproject
site on my phone? And also both my computer and phone are connected to the same wifi access point.
Upvotes: 1
Views: 1652
Reputation: 20473
Consider using .xip.io
solution.
Example:
if your local computer IP address is 192.168.1.2
, and you can visit your local site as http://192.168.1.2/somepage.html
, in your phone you can access it with http://192.168.1.2.xip.io/somepage.html
. To make this solution work, you need to edit your apache virtualhost, something like:
<VirtualHost *:80>
DocumentRoot "/path/to/site"
ServerAlias site.*.xip.io
ServerName site.dev
</VirtualHost>
Note: Don't forget to restart apache.
Upvotes: 0
Reputation: 94642
Remember you phone does not know about your sites url as it is not in any DNS server and you cannot fiddle with the hosts file on the phone unless you jailbreak it.
What I normally do is create a new Virtual Host to be used when accessing the site from a phone. But on this Virtual Host I use another port number as adding a port number is easy on the phones browser.
So add another VH like this and another Listen command
Listen 81
<VirtualHost *:81>
ServerName myproject.dev
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/myproject/public
<Directory /var/www/html/myproject>
AllowOverride All
# add access from any ip on your subnet
Require ip 192.168.1
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then assuming the Server is running on 192.168.1.100
you use this url to get to the site
http://192.168.1.100:81
and your routes should work without any fiddling
Upvotes: 2
Reputation: 1348
Add an alias on the IP address to your <VirtualHost>
-directive. Something like ServerAlias 192.168.1.100
. Then, you should be able to reach the web application on that IP address, like this: http://192.168.1.100/myproject/public
.
The main principles at work here are pretty independent of laravel, but more related to DNS and networking, and apache configuration.
Upvotes: 0