Michael Dyrynda
Home Blog Podcasts
serve.sh in Homestead fails to restart nginx March 16th, 2015

The problem

You want to add a new domain and you find that the serve command fails to restart nginx.

1dos2unix: converting file /vagrant/scripts/serve.sh to Unix format ...
2 * Restarting nginx
3 ...fail!
4php5-fpm stop/waiting
5php5-fpm start/running, process 2798

What happened?

Back in February 2015, a commit was made to the Homestead repository which would allow setting of the listen port when creating serving a new domain, rather than defaulting to port 80. A little while ago, Taylor fixed the aliases stub file.

This is perfect for a brand new Homestead VM or update the VM, or (maybe?) if you run homestead provision again.

What if you have a homestead kicking around already? Glad you asked!

The solution

It's a simple fix, really. If you have a look in the /home/vagrant/.bash_aliases file, you'll find the serve() function. All you need to do is find the following line:

1sudo bash /vagrant/scripts/serve.sh "$1" "$2"

And add the default port - 80 - to the end of it:

1sudo bash /vagrant/scripts/serve.sh "$1" "$2" 80

If you're feeling adventurous, and you want the ability to specify the port, you can update the serve function to accept a third parameter and reference it as follows:

1function serve() {
2 if [[ "$1" && "$2" && "$3" ]]
3 then
4 sudo dos2unix /vagrant/scripts/serve.sh
5 sudo bash /vagrant/scripts/serve.sh "$1" "$2" "$3"
6 else
7 echo "Error: missing required parameters."
8 echo "Usage: "
9 echo " serve domain path port"
10 fi

Update: As Ortwin van Vessem points out in the comments, don't forget to update the ~/.homestead/aliases file on your host machine, which will preserve the changes if you provision a new environment.

I'm a real developer ™
Michael Dyrynda


I am a software developer specialising in PHP and the Laravel Framework, and a freelancer, blogger, and podcaster by night.

Proudly hosted with Vultr

Syntax highlighting by Torchlight