Laravel .htaccess localhost MAMP and Mac OS X

I was, like anyone, excited about the release of Laravel 4 and quickly set about following the initial installation instructions on a vanilla vhost locally to have a play around with. I quickly found that the default suggested .htaccess file was causing a server error in MAMP on OS X.

I got around it with a little trial and error and can confirm the below contents in your .htaccess file – works great for me.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]

The offending line from the suggested .htaccess contents was

RewriteRule ^ index.php [L]

Install Laravel with symlink through terminal shell function/command mamp

I’ve been throwing together a few useful mac terminal os x shell scripts lately and this was another one of those cases today. It’s not completely finished just yet but it will do a job the first time round. I’m not sure just yet how best to have lots of different symlinks to different Library bases and how to code that so that it happens.

The below code and it’s paths are relevant to me and my setup with MAMP. You can easily edit this function to include different paths as you require.

Open up your ~/.bash_profile

sym-install-laravel () {
    echo “Installing Laravel as symlink to $1″
    mkdir -p ~/Develop && cd ~/Develop
    DIR=”/Users/davidheward/Develop/Laravel”
    if [ ! -d “$DIR” ]
    then
        git clone https://github.com/laravel/laravel.git Laravel
    else
        echo “Directory already exists”
    fi
    cd /Applications/MAMP/htdocs
    ln -s ~/Develop/Laravel/public/ /Applications/MAMP/htdocs/$1
    cd /Applications/MAMP/htdocs/$1
    echo “Install complete”
}

Save it close and open a new terminal session or reload profile ./profile

Then you can simply cd into your desired directory for me it’s /Applications/MAMP/htdocs/ because i’m running MAMP on my Mac OS X machine and run the following at the terminal.

$ sym-install-laravel symlara

Visit this by just hitting http://localhost/symlara/ in your browser (if you have localhost configured in this way of course).