2

I have finished my project and I need a file to run 3 commands in terminal.

php artisan serve
php artisan migrate
php artisan queue:work --daemon --timeout=

and I need to receive database name,username,password and change .env file

This is my bash shell so far

#!/bin/bash
echo "Server Ready"
sudo php artisan serve;
echo "Migration Started";
sudo php artisan migrate;
echo "migration Finished Successfuly";
echo "Queue Started";
sudo php artisan queue:work --daemon --timeout=3000;

but I need help to make it fully work.

I run this script and after first command php artisan serve my script stopped

2
  • What do you mean by "stopped"? Is there any error message given? Additionally, the given shell script does not contain that mentioned first command, you only use that command using sudo - any reason for this? Commented Jan 22, 2020 at 13:20
  • 1
    It should be noted that php artisan serve should never be used in production. It can only handle one concurrent request, and is intended only for development/testing. Commented Jan 22, 2020 at 13:59

3 Answers 3

3

i found my awnser

#!/bin/bash

cp .env.example .env

# config name database
sed -i -e 's/DB_DATABASE=laravel//g' .env
echo -n "Enter a database name > "
read database
sed  -i "12i  DB_DATABASE=$database" .env

# config username
sed -i -e 's/DB_USERNAME=root//g' .env
echo -n "Enter a  username > "
read username
sed  -i "12i  DB_DATABASE=$username" .env

# config password
sed -i -e 's/DB_PASSWORD=//g' .env
echo -n "Enter  password > "
read password
sed  -i "12i  DB_DATABASE=$password" .env

echo "Server Ready"
sudo php artisan serve &
echo "Migration Started" 
sudo php artisan migrate &
echo "migration Finished Successfuly" 
echo "Queue Started"
sudo php artisan queue:work --daemon --timeout=3000 &

i post it for who need it in line 1 rename the .env.example to .env after that rename the database with user selected name and do it for username and password and thank to my friend @Lajos Arpad in last line we can run php artisan commands all together

Sign up to request clarification or add additional context in comments.

Comments

2

The php artisan serve command is running an internal php webserver. Which means it needs to block the current thread to listen to PHP input. You could simply run this command after all the other.

#!/bin/bash
echo "Migration Started";
sudo php artisan migrate;
echo "migration Finished Successfuly";
echo "Queue Started";
sudo php artisan queue:work --daemon --timeout=3000;
echo "Server Ready"
sudo php artisan serve;

But, as mention here you should have to use that command in order to have a running environment. You might want to use a WAMP server instead. Or maybe docker if you are feeling adventurous.

5 Comments

in second command i will stop again like artisan serve queue stop the script
@hoseininjast I've updated my question. For your .env file, it should matter because the code is retreiving environnement variables, and those variables are accessible from everywhere. Still, you should use php artisan serve.
I'm not sure what your php artisan queue:work command does, but if it blocks the thread. i suggest running php artisan serve in another terminal.
i want to give this file to my friend and when he run that artisan migrate tables and queue startet for listening to jobs and artisan for start local server
there are ways to use multithreading in bash. You could look into that.
2

You just need to put & at the end of each line which would be a blocker and you do not intend to wait for it:

#!/bin/bash
echo "Server Ready"
sudo php artisan serve &
echo "Migration Started" 
sudo php artisan migrate &
echo "migration Finished Successfuly" 
echo "Queue Started"
sudo php artisan queue:work --daemon --timeout=3000 &

As about your .env file you can implement a script in PHP that gets command line inputs and changes .env accordingly and then call this with whatever inputs you need.

1 Comment

i found my awnser thank you.i will post the full awnser now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.