3

I have never used Node or Redis before, however in the app that I am building I am using node and Redis to run socket.io.js for some live updating features.

Currently in order for me to make this work, I have to open terminal and run

$ cd project/nodejs/Redis/lib/src
$ ./redis-server

Then I am not able to use that terminal window anymore. So I open a new terminal window and run

$ cd project/nodejs
$ node server.js

Once again I am also not able to use this terminal window any more.

Then I open another window and run

$ cd project 
$ php artisan serve

How can I combine all of this and run it when some one navigates to the app URL?

Do I need to build a commands in the commands directory? I've done some research, but I am still confused. I had never used terminal until I started using laravel, so I really have no idea what I need to research.

duellsy
  • 8,497
  • 2
  • 36
  • 60
user3095721
  • 51
  • 1
  • 5

2 Answers2

2

You can create one script file (myserver.sh), with all your commands in sequence:

cd /your/www/folder/project/nodejs/Redis/lib/src
./redis-server &

cd /your/www/folder/project/nodejs
node server.js &

cd /your/www/folder/project 
php artisan serve &

Note that I added an & at the end of each command, this will make that command run in background.

Then you run it by running:

bash myserver.sh

Or you can make it executable

chmod +x myserver.sh

And then just run

./myserver.sh

This will work for development, but it's not a really good option for production. You should use a real web server, like Apache 2 or NGINX and not PHP builtin server. But this is just my opinion.

Don't think about creating Laravel commands to execute Node nor your Redis server, it's not what it serves for, take a look at their own wiki and see how people run those applications in production servers.

Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
  • I was considering using MAMP for production. Will this work with MAMP? – user3095721 Jan 03 '14 at 08:03
  • The `&` works on any Mac or Linux system, so it will work on MAMP. – Antonio Carlos Ribeiro Jan 03 '14 at 11:04
  • OK well I have one more question. When you say combine.. or to make it executable? I am not quite sure what that means? I do know I can make an alias in my ./bash_profile is this the same type thing? Sorry, like I said I am new to using terminal. – user3095721 Jan 03 '14 at 14:28
  • Combine = create one file with all commands. Make it executable, is basically tell the operating system that this is a script and so you can execute it without having to add `bash` before it. Running `bash myserver.sh` is the same as make it executable and then just execute the file. Answer edited to clarify the 'combine'. – Antonio Carlos Ribeiro Jan 03 '14 at 14:34
  • I managed to use automator to automatically run the executable upon opening the app. – user3095721 Jan 03 '14 at 15:47
  • ok I have a another question. Where do I put this myserver.sh It worked for a little bit, but when I changed environments it doesn't seam to recognize the directories. right now I have this -project --nodejs --myserver.sh --server.js --redis ---lib ----src do I need to have myserver.sh in a certain directory. Ive tried moving it around, and changing the CD in the .sh, but it doesnt seam to work – user3095721 Jan 04 '14 at 17:26
  • In your example directories were all relative to some directory we don't know, if you need to call this thing from anywhere, they must be relative to your root (/) folder and it will work from any place. Just edited it to show you how. – Antonio Carlos Ribeiro Jan 04 '14 at 18:12
1

Oh NVM. I added the full path to both CD in myserver.sh cd /Applications/MAMP/htdocs/work/nodejs/Redis/src ./redis-server &

cd /Applications/MAMP/htdocs/work/nodejs node server.js &

user3095721
  • 51
  • 1
  • 5