id like to know :
Where Laravel php artisan serve command logs stored ?
How to automatically start php artisan serve when sever (Apache) starts ?
Laravel logs are stored at storage/logs
You don't need artisan serve, if you have Apache handling your HTTP traffic.
To the first question
Where Laravel php artisan serve command logs stored ?
Laravel server logs are stored in storage/logs folder ,which contains files for the server logs
To the second question
How to automatically start php artisan serve when sever (Apache) starts ?
If you need to automatically ,A very simple way to do this would be to use use laravel scheduling Artisan Commands using cron
Ensure cron is installed yum install vixie-cron (assuming you use centos). Start it with service crond start
Add laravel Schedule object vi /etc/crontab and add * * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1 ,to the cron schedule file .
Go to app/Console/Kernel.php file and add $schedule->command('foo')->withoutOverlapping(); where foo is the artisan command you would like to run in this case serve , so it should be $schedule->command('serve')->withoutOverlapping();
Restart cron deamon with service crond restart.
See this related question https://stackoverflow.com/a/34096590/1226748
I would definitely recommend NOT using artisan's server in production like EVER, it's for testing only. -- You would be WAY better off to use nginx as a reverse proxy and you can set whatever port you want that way, and have your angular app still connect to it.
Related
I am working with task scheduling in laravel. It's working well by using artisan command in cmd. But what's the problem with automatically calling the task on server. It's not running every minute.
https://laravel.com/docs/8.x/scheduling#running-the-scheduler
You will need to setup a cron job on your server that calls your scheduler
If you using Laravel Scheduler, you have to access in your server via ssh.
ssh user#<IP-address>
edit crontab file to call every minute php artisan schedule:run artisan command.
So:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
If it not start,try to restart the web server. If you are using nginx, for ex.: sudo systemctl restart nginx
My new project is based on Laravel framework, and developers need to run php artisan commands to do their requirements. On the other hand, server configuration disabled shell_exec for security purposes.
What should I do for this case? Is there any secure way for developers considering server security issues?
There are three ways to run php artisan command.Below i have mention all of them :
1) Use Terminal which is on server.Through that you can execute the php artisan command.
2) Use "putty" software to access the server.In that you can connect putty with server.For connection to the server you require "SSH credential" which you can create on server.
3) Using route you can execute artisan command.But for that every time you need to add/modify route and execute that in the browser so that artisan command will execute.Below i have given an example of it.You just have to put it in the routes file:
Route::get('command', function () {
/* php artisan migrate */
\Artisan::call('migrate');
dd("Done");
});
The above route you need to call through browser.This route will execute command of "php artisan migrate".
I have a strange issue where I can run my Laravel project that uses mysql perfectly when using xamp php 7.2 , So normally if it runs well in xampp it should run well if I just decide to use php artisan serve and access it via http://127.0.0.1:8000/ But to my surprise it doesn't'.
If I use php artisan serve the debug message I get from my Laravel project is
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Maximum execution time of 60 seconds exceeded
I tried giving full permissions to all folders as well as run the following commands:
composer update
composer dump-auto-load
php artisan serve
Any one else experience this strange issue? Where it works perfect in xampp but if you cd to the project directory and run php artisan serve, it just times out.
If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after any changing your php.ini file values.
Try to run in a different port.
php artisan serve --port=8080
and if still doesn't work, set time limit to your controller, in __contruct function,
public function __construct()
{
set_time_limit(300);
}
This problem is occering due to maximum execution time defined on php configuration. As common factor please use following:
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
Add the above lines at the top of your server.php file.
I want to access my laravel project.I run php artisan serve and access the 127.0.0.1:8000 in browser.
But i learned that I can also check my project using the localhost/laravelproject/public url whithout running php artisan serve.
Question: What is the point of using php artisan serve?
No point in two different methods like you mentioned run laravel by "php artisan serve" and by "project url" followed by localhost. But advantage of "php artisan serve" is you can run you laravel project without putting in htdocs/www directory i.e servers root directory. You can put laravel project anywhere where you want and run through the artisan command.
I found some information you may find interesting:
https://www.quora.com/How-can-I-use-php-artisan-serve
But in simple words, php artisan serve is an easy way to create a php server and that is what laravel needs to run.
You could do the same with "php -S 8080 (which would start a php web server (single threaded) in the current directory on port 8080)"
Also if you have already a php server running with apache or nginx it would not be necessary any of the commands.
Hope you find this helpful.
The `Serve command is just a shortcut for the PHP Builtin 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.
To run one laravel project we only need to type "php artisan serve". and it will be available on port 8000.
But sometimes we need to run multiple projects at the same time. How can we do this?
tl;dr one cannot have more than one listener per TCP port at the same time. If you need more web server instances: try another port:
php artisan serve --port=8001
then go to http://localhost:8001
References:
Can two applications listen to the same port?
https://laravel.com/docs/8.x
You can also run web server on multiple port in PHP application by the following command.
php -S localhost:8000
php -S localhost:8080
First run your first laravel project blog as follows:
Open your command prompt and go to your drive where your laravel project exist.
And type php artisan serve
C:\xampp\htdocs\blog>php artisan serve
Now type http://localhost:8000 in browser and your blog project will run.
Again open another command prompt and again go to your another laravel project bloganother
C:\xampp\htdocs\bloganother>php artisan serve --port=8080
Now go to your browser and type http://localhost:8080 in your browser your another project will also run.
1- First thing you need to mention port number in .env file.
APP_URL=http://127.0.0.1:8001
2- Run php artisan serve --port=8001
Run first laravel project (with url: http://localhost:8000)
php artisan serve
Run another laravel project (with port specific url: http://localhost:8001)
php artisan serve --port=8001
Run one more laravel project (with port specific url: http://localhost:8002)
php artisan serve --port=8002