Install Composer + Laravel on MAC OS

The Laravel framework uses Composer to manage its dependencies

install composer

Download using curl command:

curl -sS https://getcomposer.org/installer | php

Or if you don't have curl installed, you can also use the php command to download:

php -r "readfile('https://getcomposer.org/installer');" | php 

After you download composer.phar, you can put it in the directory, but every time you create a new directory, you have to make a copy to the new directory, which is more troublesome. So the best practice is to put it in the usr/local/bin directory as a global directive. (An error will be reported here, because of permission problems, there are solutions below) This allows you to use the composer command directly in the terminal.
mv composer.phar /usr/local/bin/composer 

Create a Laravel project

  1. To use the terminal, we enter the folder where the project is stored. 
    cd XXXXXXX (you can know the path by dragging the file directly into the terminal)
  2. composer create-project laravel/laravel projectName ( projectName: you name whatever you want )

If you follow the above steps and report the following error, you can only continue to toss down

Question 1: 

The terminal displays the following error after execution:  This problem has been a headache for a while. First, there is no read and write permission when writing to usr/local/bin. Even if sudo is added, it still prompts that there is no permission to enter. So first find the hidden folder of usr (com + shift + G, just enter directly), right-click and click to display the introduction, then there is a small lock in the lower right corner of the introduction, enter the password to open the small lock to change the permissions of everyone, and find that it is still Even an administrator cannot change this permission. Later, it was found that the mac kernel protection mechanism Rootless was at fault, so I closed Rootless by the following method, and then changed the permission of everyone in usr to read and write.mv composer.phar /usr/local/bin/composer 

mv: rename composer.phar to /usr/local/bin/composer: No such file or directory 

  1. Press and hold the command+R key to turn on the computer to put the computer into recovery mode (don't worry, it will not affect the computer data)
  2. 打开终端,在终端输入:csrutil disable 然后按回车键 (开机后,不要乱点,小心恢复出厂设置,屏幕上侧一栏应该有工具什么的,记不太清了,里面有终端)
  3. 重新开启电脑然后设置usr文件的everyone权限为读写发现可以设置了。

接下来就是将composer折腾进去就行,我是直接拖拽进去的,最后再将composer.phar格式更改为composer(此处可以手动直接更改,也就是去掉.phar后缀即可,为什么更改呢,应该是为了更好的全局应用吧)。

问题2: 
好的,那么第二个坑来了composer create-project laravel/laravel projectName --prefer-dist这个命令不好使了,报错了。错误如下:

[UnexpectedValueException] 
Could not parse version constraint –prefer-dist: Invalid version string "–prefer-dist"
 

更新composer为最新命令为composer self-update  
composer create-project laravel/laravel projectName
然后OK了。。。。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325797562&siteId=291194637