Skip to main content

Setting Up Laravel 4.x on Mac OSX 10.8+ with XAMPP installed

I am new to PHP and have coded earlier with CodeIgniter. It is really easy to get started with CodeIgniter as it is light but powerful and has less features. As CodeIgniter is slowly phasing out I thought of moving to Laravel. Yes, it is powerful and AWESOME!!! 

Lets get down to business. 


1. Install composer


I was doing it for the first time and faced issues:

Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

The detect_unicode setting must be disabled.
Add the following to the end of your `php.ini`:
detect_unicode = Off
A php.ini file does not exist. You will have to create one.
I was clueless at this moment and started to search. After some search I found an article which tells about setting up AMP (Apache, My SQL and PHP) environment. 
While going through it I realized that I have Apache already installed on my system (I am new to Mac too). I followed the steps to configure it (took related path accidentally :D).
While doing this I found out that I am working in a system folder /etc. To check it out I jumped into it and to my surprise I found my missing php.ini.default.I created a copy of it, renamed it and opened it up in vim editor.
sudo vi php.ini
I added the line 
detect_unicode = Off 
at the end.
I tried to setup composer again and it worked.
2. Install Laravel
composer create-project laravel/laravel --prefer-dist
No surprises, I got another issue :D
Script php artisan optimize handling the post-update-cmd event returned with an error:


  [InvalidArgumentException]
  Command "optimize" is not defined.
I found out that mcrypt is not available. I searched again and realized that PHP version which I am using is old. I check it using "php -v" and checked the path of PHP which is being used using "which php". PHP version was 5.3.x.
3. Update PHP (Laravel needs a recent version)
I used this link (It is awesome, thanks to author).
#2. Go back to step 2.
Try again. I thought of using my XAMPP's Apache and tried creating project there. I faced the same issue. Why now :(. I thought it is something to do with PHP version that I am using. I checked the version again and found out that I am still using wrong version and php binaries from wrong path were being used.
I searched to find out how to use the right PHP version and found this Laravel forum link.
I am pasting the suggestion here for ready reference but all the credit goes to the contributor in forum.
You are using the built in version of PHP, did you install PHP-OSX for 5.4 installation? If so you need to overwrite it's path
from terminal:

sudo vi ~/.bash_profile
enter password
when file loads press A to access writing

paste this line:

export PATH=/usr/local/php5/bin:${PATH}

press ESC key

hold SHIFT and Press ZZ (z twice)

now do which php again it should say:

/usr/local/php5/bin/php

now install home brew and you can do stuff like like 
brew install php54-mcrypt

restart apache in between steps

you may also be able to do other stuff like "brew search php54-module" or php54-* to see whats available.. always install with php54 to avoid conflicts.
My setup just worked. I did not need to install homebrew and perform rest of the steps.
For setting up mcrypt you can also refer this link I did not tried it though.
4. Tried http://localhost/laravel/public/ - did not work.
I got Laravel 4 blank screen issue (as people call it famously). I recalled that I need to set storage directory present in app directory of laravel setup as writable. 
$ sudo chmod -R 7777 app/storage
As, I am the only user of my machine and this is my home machine I gave all permissions. Please provide appropriate permissions in your case.
5. Happy Ending!!! It worked. :D

Comments

Popular posts from this blog

Laravel XAMPP MySQL artisan migrate install error mysql.sock

In my previous post I wrote about setting up Laravel 4 on Mac with XAMPP . When I tried to use migrations (using artisan) I faced some issue. I will also post about Laravel migrations soon.    php artisan migrate:install Error :                                                     [PDOException]                                       SQLSTATE[HY000] [2002] No such file or directory                                              Solution : We need to tell artisan which mysql we want it to use. For this to work we need to porivde it with mysql.sock which we want it to use. So change your database settings like this: 'mysql' => array( 'driver'    => 'mysql', 'host'      => 'localhost',     'unix_socket' => '/Applications/xampp/xamppfiles/var/mysql/mysql.sock', 'database'  => 'wedding', 'username'  => 'root', 'password'  => '', '

Add (Drop) a new article (table) at publisher in merge replication

Let us add the article using the GUI first. First of all create the table on publisher database. Now right click on the publisher and select properties from the menu. Click on articles. Uncheck the - "Show only checked articles in the list" checkbox, in order to see the newly added table. Select the table as shown in the figure below. Press ok The article has now been added to the publisher We now need to recreate the snapshot Right click the publication and select – “View snapshot agent status”. Click start to regenerate snapshot. Now right click on the subscription (I have both on same server you may have on different servers) and select “View synchronization status” Click on start on the agent. The schema changes will propagate to the client if you have "Replicate schema changes" property set to true in the publisher.

Check SQL Server Job status (State) using sp_help_job and xp_sqlagent_enum_jobs

This article is about checking the status of a SQL job. In our work place we have lot of SQL jobs. These jobs will run whole day and are business critical. They will load the data and generate extracts which will be used by business people. Thus, it becomes quite essential to support the system efficiently so that the job finishes in time and as desired. Also, while designing a new system sometimes we need to check the dependency of one job over another. In such scenario we need to check whether a particular job has finished or not. All this can be achieved in SQL Server by using the procedures:- sp_help_job xp_sqlagent_enum_jobs Note: xp_sqlagent_enum_jobs is an undocumented proc inside of sp_help_job and is used extensively to get SQL agent job information. sp_help_job: This procedure gives some insight into the status, and information, about a job. This stored procedure provides information such as last start time, job status etc. Syntax sp_help_job { [ @job_id= ] jo