I have a laravel project and its user has a virtual domain how do I publish it in the local network only
This is my configuration in httd.vhosts.conf file
<VirtualHost *:80>
ServerName smarts.local
DocumentRoot "C:/xampp/htdocs/smarts/public"
SetEnv APPLICATION_ENV "development"
<Directory "C:/xampp/htdocs/smarts/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This is in my hosts file
127.0.0.1 smarts.local
Currently it works on my pc only but does not work on other devices in the network.
you can use the artisan command,
first run the cmd on your computer,
then go to the folder of your project like this: cd c:\wamp64\your_project_folder,
then type this code: php artisan serve --host=YOUR IP --port=ONE FREE PORT
you can find your computer port with the running this command in cmd: ipconfig /all
your command should be like this:
php artisan serve --host=192.168.1.106 --port=8080
and the others can run your project from your computer with writing this code in the addressBar of their own browser : 192.168.1.106:8080
If you want others to access smarts.local.
make sure your system ip address is static.
then every one who wants to access smarts.local should add the following to their hosts file
127.0.0.1 smarts.local (Replace 127.0.0.1 with ur public static ip)
or you should use DNS server in your network.
You can also write a startup command which will execute php artisan serve.(But you have to make sure ur public ip is static)
Its so much easy to do.
1.In windows go to cmd and type ipconfig.
2.get you local IPv4 Address (e.g:192.168.1.5).
3.Go to visual studio code and open Terminal
4.Type like this (php artisan serve --host=IPv4 Address)
Hopefully this will help you to share your project inside your same network.
Related
is there any way to auto serving you laravel project?
i'm using virtual host.
<VirtualHost *:80> #laragon magic!
DocumentRoot "C:/laragon/www/pos/public/"
ServerName apk.dev
ServerAlias *.apk.dev
</VirtualHost>
and to access it locally i open the Cmdr and write
php artisan serve --host 192.168.1.100 --port 80
every single time.
and i access it with other device with 192.168.1.100 it's working fine, i just want to know is there any way that i don't need to repeat it, and just by running the laragon i also can access the apk.dev from other device with my local network?
I am pretty new in PHP and moreover in Laravel and I am pretty desperate trying to deploy a Laravel 5.4 application that works fine on my local environment on my Linux remote server.
So I think that it is something related to virtual host configuration or something like this (maybe also something related to the .htaccess file)
In my local environment (I am using XAMPP on Windows) I have setted this virtual host into the C:\xampp\apache\conf\extra\httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
ServerName laravel.dev
</VirtualHost>
So opening the laravel.dev URL I obtain the standard Laravel homepage (I have yet not replaced it with a landing page).
Then if I open this URL: http://laravel.dev/registration
I obtain the user registration page developed by me, this because I have this route into my web.php file into my project:
Route::resource('/registration', 'RegistrationController');
Then into my RegistrationController.php there is this method showing the resources/views/registration/index.blade.php view
public function index(){
return view('/registration/index');
}
All works fine.
Now I have uploaded this Laravel website into my remote Linux server, into this folder: /var/www/html/HotelRegistration
But now my problem is that in this remote environment I have not virtual host (correct me if I am doing wrong assertion: from what I have understand the virtual host is used on the local environment to simulate a domain that Laravel need to point to the public folder, is it this reasoning correct?)
Anyway, this is the URL of the public folder of my deployed web site on my remote server:
http://89.36.211.48/HotelRegistration/public/
As you can see opening it the Laravel landing page is correctly shown, the problem is that I can access to the previous registration page, the only way that I have found is to open this URL:
http://89.36.211.48/HotelRegistration/public/index.php/registration
but it is pretty horrible and above all when the registration form is submitted it is generated a POST request toward this URL http://89.36.211.48/registration that end into a 404 Not Found error.
So I think that it depend by the fact that in this remote server I can't use a virtual host that simulate a domain (as I have on my local environment), but I am not sure about it.
What can I do to solve the situation? Do you think that using a effective domain (something like: www.myregistration.com) that points to this directory of my remote server http://89.36.211.48/HotelRegistration/public/ I can solve this problem?
You need to configure your domain in your server and need to reconfigure the apache. I'm considering you are having apache2 server so here you can do:
Step 1 Go to the apache2 folder cd /etc/apache2
Step 2 You can see sites-available folder go inside it cd sites-available
Step 3 Make a new file name it laravel.dev.conf
Step 4 Write down the following sudo nano laravel.dev.conf
Step 5 Write down the following option:
<VirtualHost *:80>
ServerAdmin webmaster#laravel.dev
ServerName laravel.dev
ServerAlias www.laravel.dev
DocumentRoot /var/www/html/laravel.dev/public/
ErrorLog /var/www/html/laravel.dev/logs/error.log
CustomLog /var/www/html/laravel.dev/logs/access.log combined
<Directory /var/www/html/laravel.dev/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Step 6 Now go to this folder/create a new one cd /var/www/html/laravel.dev
Step 7 Copy/Install your laravel application here.
Step 8 Now you can enable your site by typing sudo a2ensite laravel.dev.conf
Step 9 Now restart the apache2 sudo service apache2 restart
Now you can have proper access to your domain. Hope this helps.
Since you are using XAMPP
Add the following into your VirtualHost Directive:
<Directory "LINUX PATH TO /HotelRegistration/public">
AllowOverride All
</Directory>
Your final VirtualHost Directive should look like:
<VirtualHost *:80>
DocumentRoot "LINUX PATH TO /HotelRegistration/public"
ServerName 89.36.211.48
<Directory "LINUX PATH TO /HotelRegistration/public">
AllowOverride All
</Directory>
</VirtualHost>
After the configuration changes, restart Apache then you are good to go.
I'm running Ubuntu Server using VirtualBox to develop symfony app. I've set up shared folder, changed apache default folder /var/www/html to /media/sf_apache_shared which is shared folder, for convenient development.
The default apache's index.html file, denoting that apache is set up correctly, works fine. The problematic moment comes into play, once I try to run symfony app.
If I try to create default symfony app, I get the following result:
Although I can create symfony app using the same way, but outside of that folder, for example inside of /var/www/html.
I've checked the permission of sf_apache_shared folder with the result of 770, using the following command:
stat -c %a directory
But even aside of that fact, I manually copied symfony app project to sf_apache_shared and tried to access that project, from windows host, using chrome. The result apache's logs are:
client denied by server configuration: /media/sf_apache_shared/my_project_name/app/
client denied by server configuration: /media/sf_apache_shared/my_project_name/src/
Here is my server configuration:
i´m not too sure if this will be a final fix for your problem
but you definetly have to set the DocumentRoot and Directory in you conf
to /media/sf_apache_shared/web
ins symfony app the /web folder is designed to be the document root
also you should set ServerName and access your server via the hostname
and try Allow from All
example.
<VirtualHost *:80>
ServerName hostname.com
DocumentRoot "/media/sf_apache_shared/web"
<Directory "/media/sf_apache_shared/web">
Options Indexes FollowSymLinks
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
also check/compare the owners of the folder (ls -lrta)
I have created small blog application in laravel 5.2 .the app works whenever i run it using php artisan serve.
But without running artisan serve , when i access it from public folder for e.g. localhost/blog/public/addBlog it gives error page not found.
My routes.php has following lines
Route::get('addBlog','BlogsController');
It works fine with php artisan serve with visiting http://localhost:8000/addBlog
The solution is pretty simple. Laravel expects your public folder to be the root of the webserver / url / domain.
Using the serve command works since localhost:8000 is the root then.
Using the longer url doesn't work since your root is localhost/blog not localhost.
A fairly simple solution is to create a virtualhost, to explain how you can do this we would need to know what is running on your localhost (xampp? wamp?)
Nevertheless, the solution would be a virtualhost pointing to localhost/blog/public
Update
example for wamp virtual hosts
C:\Windows\System32\drivers\etc\hosts => open as admin and add
127.0.0.1 blog.dev
C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
ServerName blog.dev
DocumentRoot "C:\wamp\www\blog\public"
ServerAlias blog.dev
</VirtualHost>
It's basically the same for xampp, but the path to the vhosts conf is different
Don't forget to restart wamp/xampp after doing the changes. Then simply open http://blog.dev via browser and enjoy
Laravel expects the folder to be in the root of the application so set-up a virtual host and update your hosts file to match.
Use following command
sudo a2enmod rewrite
I had tried in to the ubuntu but i am not sure that will run in another os or not
I'm trying to access my Laravel app from another PC in the same network using IP address but I can't get it to work by accessing 192.168.1.101:8000 in my browser.
What should I do?
Why don't you use Laravel's artisan for it? Very simple:
sudo php artisan serve --host 192.168.1.101 --port 80
Now from other computers, you can type: http://192.168.1.101
Do not forget to replace the IP with your own local one. That's it.
Note: The sudo is only needed if you wanna serve on port 80.
Access laravel using your IP address
php artisan serve --host 0.0.0.0
Now you can access laravel server by http://laravel-server-ip-address:8000
If you want to change the port as well then
php artisan serve --host 0.0.0.0 --port 8101
Now your laravel server is http://laravel-server-ip-address:8101
Go to httpd.conf in Apache folder and find the following lines:
DocumentRoot "c:/wamp/www"
<Directory "c:/wamp/www">
# ...Stuffs in here
Options Indexes FollowSymLinks
# ...Stuffs in here
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
Then replace the last line within <Directory> tag for:
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
Allow from localhost
</Directory>
Add a virtual host for your laravel application, go to httpd-vhosts.conf and add the following lines:
<VirtualHost *:80>
DocumentRoot "D:/.../your-laravel-app-path/public"
ServerName yourservername.dev
<Directory "D:/.../your-laravel-app-path/public">
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
Restart all your apache services
This should do it, i'm using wamp on Windows and works for me.
Use this command in which ip address is ip-v4. Check ip-v4 from your wifi connection properties.
php artisan serve --host 192.168.10.15 --port 5000
Find your machine local IP:
ifconfig
Go to project folder and type following command:
sudo php artisan serve --host your_ip --port your_port
example:
sudo php artisan serve --host 192.168.1.70 --port 8080
Browse form other computer:
192.168.1.70:8080
You can do it by using laravel's built in command php artisan serve.
Follow the steps:
Go to your project's root directory within command line.
run php artisan serve
If you still can't access port 8000 or it is already in use then run:
php artisan serve --port 8383
And it should listen on new port you provided. Also you can set other options for this command. Look for the help php artisan help serve.