Php Artisan serve command not serving Laravel 5.8 - php

I installed a new Laravel instance, using version 5.8. Along the way, I found out that I can't serve the project using the normal Laravel php artisan serve command.
After some research with lots of trial and error, I came across this answer on StackOverflow that helped me with this method php -S localhost:8000 -t public/ with which I followed to change the port to port 9000, and it served the project perfectly.
Now my question is how can I go about getting the artisan command to be the default command to serve and rum my Laravel 5.8 on Windows just like before? I don't know anything about configuring Laravel core commands.

I tried this command.
php -S 127.0.0.1:9000 -t public/
after running this its works fine.
and also php artisan serve command works fine.
hope it will help.

You should open ServeCommand.php file (Illuminate\Console) and then change getOptions method
protected function getOptions()
{
$host = env('SERVE_HOST', '127.0.0.1');
$port = env('SERVE_PORT', 8080);
return [
['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on.', $host],
['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on.', $port],
];
}
when create a SERVE_HOST and SERVE_PORT in your .env file
SERVE_HOST=localhost
SERVE_PORT=9000
source

You can run the project on port 80. If you are using Linux simply run the command from the embedded server with root user permission.
Example: sudo php -S localhost: 80 -t public /

Related

PHP fails to access the docker socket via curl

My Code fails to reach the Docker Socket
$client = new GuzzleHttp\Client();
$test = $client->request('GET','http://v1.40/containers/json',[
'curl' => [CURLOPT_UNIX_SOCKET_PATH => '/var/run/docker.sock']
]);
I only get a generic cURL error 7 from that and I´ve checked that the socket is available and working inside the Container with the cURL command from the cmd. Its only when i try to connect via PHP it fails ominously and frankly im out of ideas.
So just in case someone stumbles upon this in the future and has the same or a similar problem.
Guzzle was not the problem in this case but phpfpm. I did not realize that the phpfpm workers in the official php docker image used the www-data user by default. The way I used is to change the user in the www.conf (default /usr/local/etc/php-fpm.d/www.conf in docker)
user = root
group = root
you will have to append the -R flag to the run command to allow running the workers as root.

Php artisan serve require fatal error after upgrading php7

After upgrading php from 7.0.14 to 7.0.26 php artisan serve throws this error
Warning: Unknown: failed to open stream: No such file or directory in
Unknown on line 0
Fatal error: Unknown: Failed opening required '/Applications/XAMPP/xamppfiles/htdocs/school-dashboard/public/server.php'
(include_path='.:') in Unknown on line 0
Ok, after hours of pulling my hair out I finally found out what the issue was.
In laravel 4 php artisan serve does this under the hood
<?php
namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
class ServeCommand extends Command {
public function fire()
{
$this->checkPhpVersion();
chdir($this->laravel['path.base']);
$host = $this->input->getOption('host');
$port = $this->input->getOption('port');
$public = $this->laravel['path.public'];
$this->info("Laravel development server started on http://{$host}:{$port}");
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" server.php");
}
}
That is essentially this in plain php:
php -S 127.0.0.1:8000 -t public serve.php - see the docs for php built in server for more info.
And this worked well and dandy before php 7.0.26, where the last parameter for the php -S built in server was changed to a flag as well, so you have to call it like this php -S 127.0.0.1:8000 -t public -f serve.php.
If you want to serve it with php artisan serve you will have to override the ServeCommand and change the last line of the fire() method to this:
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" -f server.php");
Or you can change it directly in the ServeCommand, but if you do a composer update or install you will have to do it again.
That's what it happened to me today running a Laravel project. After i have tried all the possible solutions finally i got one that it's work for me . So first of all check that your anti-virus block your server.php and it also deleting it . Then check if you server.php is missing from your project, and I think that is probably yes . Just copy it (server.php) from other project (build also from laravel) but before that just turn off your anti-virus until your next restart and make you sure that you will stop it every time before running. I hope that it helps you.

How to change default url from localhost:8000 to other Ip in laravel when we run "php artisan serve"

I am running php artisan serve command
by default the result is :
Laravel development server started: http://127.0.0.1:8000
I want to change pointing to other ip
You can use the following solution to solve your problem:
php artisan serve --host 127.0.0.1 --port 80
# php artisan serve --help
Usage:
serve [options]
Options:
--host[=HOST] The host address to serve the application on. [default: "127.0.0.1"]
--port[=PORT] The port to serve the application on. [default: 8000]
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Help:
Serve the application on the PHP development server
To change default host and/or port for the artisan serve command, you need to edit the ServeCommand.php file:
$ sudo nano vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php
At the end of it you will find were they are configured:
protected function getOptions()
{
return [
['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on', '127.0.0.1'],
['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on', '8000'],
];
}
Just change de default value of the host 127.0.0.1 for the ip of your desired host. And 8000 for the number of your desired port.
My case:
I have an UbuntuServer 18.04 VM running over GoogleCloud - ComputeEngine, I was unable to see the Laravel execution until I changed the host to 0.0.0.0, of course I changed the port as well to have the 80 as default.
The alternative was executing every time:
$ sudo php artisan serve --host=0.0.0.0 --port=80
in order to obtain the same result.
On Laravel 6 you can create a variable SERVER_PORT in your .env file
Example:
SERVER_PORT=80
Will produce:
$ php artisan serve
Laravel development server started: http://127.0.0.1:80
As an addition to #Macr1408 answer, since Laravel at this date does not offer a host name/ip config setting (like the SERVER_PORT one), you could extend the ServeCommand class and just redefine what parent getOptions method returns. Here is an example that allows you to set a SERVER_HOST env config value that will change your IP/host name when you run artisan serve:
namespace App\Console\Commands;
use Illuminate\Foundation\Console\ServeCommand as LaraServe;
class ServeCommand extends LaraServe
{
protected function getOptions()
{
$options = parent::getOptions();
$options[0][4] = env('SERVER_HOST');
return $options;
}
}
The above answers are acceptable.
I am replying to the question "which file have to make changes". If you want to run php artisan serve without --port={port_number}, you can change the port number in ServeCommand.php under port() method.

NotFoundHttpException in RouteCollection.php line 161 laravel 5.2

I'm new on laravel , I didn't write any code yet but when I open my project it gives me this error , anyone can help me to solve it ?
[
Just try http://localhost:8000 since it seems like you already started development server in your local machine using php artisan serve while you were on your project root via terminal.
Or you can try from begining:
Go to your project root from terminal / cmd
Run php artisan serve
Now try http://localhost:8000 which is equivalent to http://localhost/laravel/public , considering laravel is your project folder name.

Laravel looking for path on my localhost instead of deployed server

I have Laravel installed on my localhost. And when I try to deploy it to the server, it throws an error: View [frontend.layouts.login] not found.
And I can see that it is looking at my local file path when on my machine aka:
/Applications/MAMP/htdocs/personal/project_name/resources/views
Instead of the server's file path.
If I try and copy the project outside of the personal folder (on my local machine), so make the file path:
/Applications/MAMP/htdocs/project_name/resources/views
It gives the same issue?
Is it something with caching the views?
The other error on the same page is:
file_put_contents(/Applications/MAMP/htdocs/personal/project_name/storage/framework/sessions/7a0aaa6c977031111312b785c7b7e22a659b6a36): failed to open stream: No such file or directory
And again, the server has nothing to do with my local machine.
What could be going on?
This issue is due to the Laravel Configuration Caching.I suggest you
Remove the configuration cache file
Flush the application cache
Create a cache file for faster configuration loading
To do this, run the following Artisan commands on your command line
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Where you don't have access to the command line on your server, you can programmatically execute commands like this:
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('config:clear');
$exitCode = Artisan::call('cache:clear');
$exitCode = Artisan::call('config:cache');
return 'DONE'; //Return anything
});
I hope this is helpful.
I think this might fix it
Go to config/app.php
and change the url to your production url
'url' => 'http://localhost',
I had the same issue so i tried many things including all the solutions in this question, but it didn't work.
What worked for me is that i just deleted this file bootstrap/cache/config.php and it worked.

Categories