Laravel Install และการเริ่ม Project

เริ่มจาก install Composer


ต่อด้วย Install Laravel

เริ่มจาก Install Laravel ด้วย Composer

composer global require "laravel/installer=~1.1"

ดูให้แน่ใจว่า Laravel ถูกติดตั้งลงไปอยู่ที่ ~/.composer/vendor/bin


cd ~/.composer/vendor/bin

ถ้าหากสำเร็จให้ลองใช้ command



Laravel Installer version 1.2.0

 [options] command [arguments]

 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question

Available commands:
 help   Displays help for a command
 list   Lists commands
 new    Create a new Laravel application.

จากนั้นเพื่อให้ระบบรู้จักกับ Laravel ให้เพิ่ม ~/.composer/vendor/bin/ เข้าไปใน ~/.bash_profile โดยใช้คำสั่ง

sudo vi ~/.bash_profile


export PATH="/opt/local/bin:/opt/local/sbin:$PATH"


export PATH="/opt/local/bin:/opt/local/sbin:~/.composer/vendor/bin:$PATH"

เมื่อเพิ่มเรียบร้อยแล้วให้ save และออกจาก vi จากนั้นให้ใช้คำสั่ง

source ~/.bash_profile

และ reload Terminal ใหม่ เราจะสามารถใช้คำสั่ง laravel ได้ แทนที่จะต้องพิมพ์ยาวๆ


การสร้าง project ใหม่นั้นง่ายมากให้ใช้คำสั่ง

cd path-to-root-of-project
laravel new your-project-name

Crafting application...
Generating optimized class loader
Compiling common classes
Application key [lCdkrEvwiFtXfRxslefITL1f43tC6gPP] set successfully.
Application ready! Build something amazing.

การทดลอง run project

php artisan serve



Laravel development server started on http://localhost:8000/

จากนั้นให้ลองเข้าไปที่ http://localhost:8000/


Screen Shot 2558-03-15 at 9.40.09 PM





How to create ~/.bash_profile and ~/.profile on Mac OSX

You can use the touch command.

For instance,

cd ~

to go to the home directory.

Now we will create a file called .bash_profile (the dot means that it will be hidden).

Then use nano or vi in the Terminal. Unless you know what vi is, just use nano. To open up these files, you would use:

sudo nano .bash_profile

sudo makes sure that you will be able to save these files. Here, you can add aliases. nano or vi will automatically create a new file if it does not exist in your current directory in Terminal.

After you are finished, press Ctrl + O, Enter, and Ctrl + X to save and quit. Finally, use

source ~/.bash_profile

to reload the Terminal and it will read what you put in those files.

Of course, you can alias that too if you want. 🙂

To answer your final question, these files will automatically be read every time you open the Terminal. However, if there is an error (For instance, don’t put spaces between aliases), it will tell you.

More Information

As George pointed out, .bash_profile will run only on login shells. For non-login shells, you would need to create a .bashrc file with:

sudo nano .bashrc