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

Create a background / taskbar application in c# .NET

Recently, I was working on integration of two windows applications. First application will launch the second application on login and then they both will communicate using pre-defined set of instructions. There were some complications (I am not going into them) and thus we decided to have a third application which actually will act as mediator. First application will launch the mediator (third application) and it will launch the second application. For this purpose we needed to create a task bar application (which will run in background). How To ·          Create a new windows project and delete the default form (Form1). ·          In Program.cs create a new class and inherit it from Form. ·          Please refer the code below. ·          Now change the Main method. In Application.Run change the startup objec...

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...

Java 8 JMX Default Metrics

This is more of a note. Here you can find default types and attributes for JMX on top of Java 8. Code: I will clean and explain it later :( private static void WriteAttributes(final MBeanServer mBeanServer, final ObjectName http) throws InstanceNotFoundException, IntrospectionException, ReflectionException { MBeanInfo info = mBeanServer.getMBeanInfo(http); MBeanAttributeInfo[] attrInfo = info.getAttributes(); System.out.println("Attributes for object: " + http +":\n"); for (MBeanAttributeInfo attr : attrInfo) { System.out.println(" " + attr.getName() + "\n"); } } Attributes for object: java.lang:type=MemoryPool,name=Metaspace:   Name   Type   Valid   Usage   PeakUsage   MemoryManagerNames   UsageThreshold   UsageThresholdExceeded   UsageThresholdCount   UsageThresholdSupported   CollectionUsageThreshold   Collectio...