# Mongrel

**URL:** <https://www.ruby-forum.com/t/mongrel/113239>\
**Category:** Rails\
**Created:** [August 29, 2007, 5:48am UTC](https://www.ruby-forum.com/t/mongrel/113239 "2007-08-29T05:48:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@rgreen](https://www.ruby-forum.com/u/rgreen)\
**Post date:** [August 29, 2007, 5:48am UTC](https://www.ruby-forum.com/t/mongrel/113239/1 "2007-08-29T05:48:18Z")

</div>

Since Mongrel is now built into Rails, Is it possible to change the  
default port from 3000 to something else?

---

<div class="post-metadata">

**Author:** ![rgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@rgreen](https://www.ruby-forum.com/u/rgreen)\
**Post date:** [August 29, 2007, 5:56am UTC](https://www.ruby-forum.com/t/mongrel/113239/2 "2007-08-29T05:56:19Z")

</div>

On Aug 28, 2007, at 22:47 , RonGreen wrote:

> Since Mongrel is now built into Rails, Is it possible to change the  
> default port from 3000 to something else?

I’ve searched for a convenient way to configure the default port per  
app myself (other than using a command line switch). I’ve settled on  
creating a one-line shell script in RAILS\_ROOT:

$ cat server  
script/server -p 3101

I change the port number for each app and can start it with a cd  
and ./server

Not perfect, but it works.

Michael G.  
grzm seespotcode net

---

<div class="post-metadata">

**Author:** ![rgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@rgreen](https://www.ruby-forum.com/u/rgreen)\
**Post date:** [August 29, 2007, 10:11am UTC](https://www.ruby-forum.com/t/mongrel/113239/3 "2007-08-29T10:11:43Z")

</div>

On 29 Aug 2007, at 05:55, Michael G. wrote:

> I change the port number for each app and can start it with a cd  
> and ./server
> 
> Not perfect, but it works.

If you want to host your server on the same port every time (but not  
the default 3000 one), you can add the following lines to  
~/.bash\_login (don’t forget to quit the session and start a new one  
afterwards):  
alias serverd=‘sudo script/server -p 80’ # start up the beast on port  
80 (privileged port, so needs sudo)  
alias serverp=‘sudo script/server -p 80 -e production’ # start up in  
production

You can then just use “serverd” en “serverp” in your Rails app folder  
to start your server.

Now for Michael’s method: you could write a bash script that loops  
through ports checking for the first available one, then use that to  
start up a mongrel on that available port. The method described at  
[http://www.bhaskarvk.info/content/unix/bash\_tricks.html](http://www.bhaskarvk.info/content/unix/bash_tricks.html) is a good  
start, maybe someone with a bit more bash experience on the list can  
tell you how to write the loop and start a mongrel on an available port.

Best regards

Peter De Berdt
