This is the first time I've used a PHP framework.
I've been following the Laravel documentation to install Composer and Laravel, and everything seems to have gone smoothly.
But now I've finished the installation/configure instructions, and I have created a project, I can't see any instructions on how to serve my application so it's viewable via a browser?
I have used Ruby on Rails before, which came with an easy way to get an instance of the application running via a built-in web server.
Is there something similar with Laravel, or do I need to somehow configure my standard Apache instance to serve the application?
I'm guessing there is something I've overlooked or misunderstood in the documentation.
yes, you can do it by using following in your terminal.
open your terminal, and navigate to directory where you have your project abc
and fire following command
php artisan serve
Now you can access it in browser by going to http://localhost:8000
hope you get it
I just want to add to the answer of Mubin Khalid . You can choose your own port number like
php artisan serve --port=8080
This is helpful when running two or more project.
You can also serve with you ip address
php artisan serve --host=ip_of_computer_running_laravel --port=8080
works to access server with in same network.
if you are accessing from same laptop you can just browse to ip_of_computer_running_laravel:8080 but if you are browsing from other computer in the network ip_of_computer_running_laravel:8080
Related
I have install Laravel in my pc using composer.
I used gitbash and started xampp control server
First I've changed my directory.
Then I've ran a command composer create-project laravel/laravel project_1. After the command had run, it installed laravel and all necessary file and key was successfully set.
Then I again changed my directory to project_1
Then I ran another command php artisan serve. After running this command Laravel development server started and 127.0.0.1:8000 this ip has genrated.
I copied the id and paste it in my browser url bar.(I copied and pasted it without using keyboard. I only used mouse)
but when I provided the ip the project_1 starting page did not open.
The page was loading and it is still loading.
what can I do? Please help
logs folder
Here is my contribution, I cannot say what is the cause but I have a solution for it; because I have such as a challenge.
run
php -S 127.0.0.1:8000 -t public
Note that the 8000 is your port, and this could be any 4-digit number.
I hope this helps
Every thing you did seems right to me in terms of Laravel requirements, so lets check some other possible issues:
make sure that your internet connection isn't configured to use
proxy, if so make sure you excluded your local address.
if you are using Internet security suite software, make sure it doesn't block your requests, this vary from software to another but you might test this by deactivating the software for a while until you try.
now that's what I have in mind, I hope it help.
First, stop the php artisan serve
After changing directory go to inside your project folder, you can run php artisan serve. Then a localhost URL will be generated for you where you can see your project in the browser
If you have PHP installed locally and you would like to use PHP's built-in development server will start a development server at http://localhost:8000
Please try to install Laragon and forget about Xampp for now. This is really cool tool and you'll start much quicker. I did try to resolve few issues with Xampp myself and always wasted a lot of time. You can google tutorials later for it as well. Plenty of info out there.
As well it comes with in house installer for Laravel ;) and more :).
Make sure that you are not coping the url from Git Bash through command, it will stop running the project
Make sure that you are not using antivirus specially avast antivirus.
I have created a react-laravel project using laravel-mix. Right now I am run project using
npm run watch
php artisan serve
So by this, I access project by : http://localhost:8000
I have also worked in laravel. In laravel, if we want to access project without php artisan serve then we can access using : http://localhost/project_name/public.
Now my question is, how can I access/execute react-laravel project without php artisan serve? Is there any kind of way to access/execute project without port? Because I want to set up react-laravel on live server and I don't want to continue open terminal on server after code uploading.
I will really appreciate your feedbacks.
There are a multitude of ways to set up a laravel project. and it has nothing to do with the frontend suite you use whether its React or Vue, I will give you 2 options here to run a laravel application.
1. vagrant/homestead
Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes!
Doc Link
2. XAMPP/WAMP/ or any LAMP stack
XAMPP is a completely free, easy to install Apache distribution containing MariaDB, PHP, and Perl. The XAMPP open source package has been set up to be incredibly easy to install and to use.
Link
Personally I prefer Laravel Homestead since it contains everything out of the box for laravel Development. like PHP, Nginx, MariaDB, Node, etc...
I need to understand this behavior.
I use xampp for web development. I start to apache server in the xampp gui and then I can start my projects in the browser via localhost...
Since yesterday I have added laravel to my mac book. My project is in the xampp htdocs folder and I want to use it witch xampp. But when the xampp apache server instance is running, nothing is happened to my laravel project until I run php artisan serve in the cmd.
How can I combine larael with xampp?
And what exactly does php artisan serve do? Start another apache server instance?
The artisan command is just a command line utility for laravel. The serve command just starts up the PHP server.
to run it without artisan you can Configure a server virtual-host (Apache or Nginx) which have the public directory of your project as root directory. Since you are using a MAC I can't exactly instruct you to how to do that.
NOTE
this will help to create the virtual host. but i haven't tried that
sorry i can't comment due to reputation :/ i use lumen (rest api of laravel) with xampp and it works fine. Can you provide somemore details?
I also think the path is the problem. Which path you use to access it via a browser? for lumen its /htdocs/project/public/ so in browser: http://localhost/project/public/
there i can access the api. should be similar for full laravel project?
Create virtual host and point it to laravel_directory/public/index.php and restart apache.
Creating apache virtual host:
http://laravel-recipes.com/recipes/25/creating-an-apache-virtualhost
If you don't want to do that load, localhost/lara_dir/public/index.php
index.php is where all the requests go through.
I dont seem to understand why we need to run a Laravel app with php artisan serve vs just running it with Apache or nginx. I know that under development, we use artisan to fire up the site and after deployment to a server, you use the webserver to load up the site.
Whats the use of running the app in artisan in the first place?
The serve command is just a shortcut for the PHP Built-in Webserver, something PHP has out of the box, so the point of using it is to start testing your application as fast as you could, you just need to install PHP, Composer and your application is up (if you don't need anything else, of course). But if you already have Nginx installed, there is no point at all, just use it.
It's not wise to use the Builtin Webserver in production.
One advantage of using php artisan serve over a typical webserver during development is you can use Psysh as a debugger (Laravel Tinker) to set a breakpoint.
For example, at the line of code I want to break at I type:
eval(\Psy\sh());
Then I hit the page that will run that section of code and when it gets to that line it will break into a Psy Shell repl (in the commandline window where I started php artisan serve). Then I can inspect variables, etc. at that point of execution. It's very useful for debugging. As far as I know, you can't do this running Apache/Nginx. It has to be with artisan serve (or running automated tests).
More info here:
https://tighten.co/blog/supercharge-your-laravel-tinker-workflow
http://psysh.org/
Purpose: The purpose of using Php artisan serve (PHP builtin server) is just for testing and easy starting your project it should not be used in real website deployment.
Asset Not working: Always put your index file in public it's the beauty and security of Laravel framework and your assets will always working. if you are bore to use your custom URL like C:/wamp/www/pym/server.php then use Virtual host locally but don't but don't put your index outside the Public folder.
if you really want to use index at your Root directory then you should customize your all asset() and url() helper functions and should put your exact url Example asset('/login') should be changed to asset('localhost/yourprojectroot/login').
php artisan serve --host your_server_ip --port 8000
copy that http://your_server_ip:8000 and run it into the browser
Aside from the best answer here.
You can see the logs directly where you execute the php artisan serve, so useful in debugging.
Well, was looking for the same answer but couldn't find any that is satisfying so , if your also unsatisfied just like me try running the link returned when you run
php artisan serve
it returns
Laravel development server started: <http://127.0.0.1:8000>
copy that /http://127.0.0.1:8000 and run it into the browser , guess what it returns );the page that u first got when you installed laravel for the first time or i guess it will return the page in the routes folder which was set as /home directory or file(default home page).
In brief:
php artisan serve
starts the serve,forexample its like when your going to drive a car and you start the engine before driving whereby you can start the engine and drive at the same time ,its not neccessary to do so but depends.So to me that's php artisan serve CLI.
I installed Symfony2 on Windows 8.1. The files are stored under IIS in wwwroot.
Everything runs very well when I use the internal built-in PHP server. I can access the site through localhost:8000/app_dev.php.
When I try to access the site straight through localhost (localhost/test_project/web/app.php), I can get to the site, but it doesn't update with my changes even after I close the browser and completely reload the site. I have the same problem on the internal PHP server when I try localhost:8000/app.php - my changes aren't there.
Questions:
1. Why are my app and app_dev showing different content?
2. How can I set up Symfony to run on IIS and not need the internal server?
Because app.php uses cached files and you need to clear framework cache to see your changes. It is production version of your web.
php app/console cache:clear --env=prod --no-debug
localhost/test_project/web/app_dev.php
Please look at official Symfony documentation for explanation.