Skip to content

Instantly share code, notes, and snippets.

@yupmin
Last active November 25, 2019 00:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save yupmin/4fb5d3eb0aeb4fd353cbc993a60be7b4 to your computer and use it in GitHub Desktop.
Save yupmin/4fb5d3eb0aeb4fd353cbc993a60be7b4 to your computer and use it in GitHub Desktop.
Install Laravel Valet with Phpstorm For Mac OSX

Laravel Valet 은 PHP or Laravel 개발하는데에 거의 필수 툴이 되어가는 듯 합니다. Laravel Valet 제대로 설치하시고 정신건강을 보존하시길 바랍니다.

좀 보강할 내용은 댓글로 남겨주세요.

"Web development that doesn't hurt"

On Mac OSX

0. 참고 링크

1. Cleanup

  • 설치시 되도록이면 Mac 에 설치되어있는 웹서버류(apache, nginx)는 정지 및 삭제 합니다.
  • brew install php 로 설치 하지 않은 php 는 삭제 합니다.(Mac 에는 기본 /usr/bin/php 가 설치는 되어있씁니다. 이건 삭제 하면 안됩니다.)
  • Xcode 가 미리 깔려있어야 합니다.

2. Install Brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew --version

3. Install PHP

brew install php
# or brew install php@7.2

4. Install composer

mkdir -p ~/bin
curl -sS https://getcomposer.org/installer | php -- && mv composer.phar ~/bin/composer
composer --version

composer 버젼이 제대로 안나올때에는 echo $PATH 로 path 를 확인합니다. 되도록이면 ~/bin 을 활용하도록 합니다.

  • /usr/bin 보다 /usr/local/bin 이 먼저여야 합니다.(brew 설정확인)
  • /usr/local/bin 보다 ~/bin 이 먼저여야 합니다.

저는 보통 이렇게 .profile 을 구성합니다.

export COMPOSER_HOME=$HOME/.config/composer/
export PATH=vendor/bin:$HOME/bin:/usr/local/bin:/usr/local/sbin:$HOME/.config/composer/vendor/bin:$PATH

5. Install Valet

composer global require laravel/valet
valet --version
valet install

이렇게 하면 brew 로 nginx 와 dnsmasq 가 깔립니다. 그리고 php, nginx, dnsmasq 가 데몬으로 돕니다.

제대로 돌아가는 것 확인을 위해선 다음과 같이 합니다.

brew services list

Name    Status  User   Plist
dnsmasq started root   /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
nginx   started root   /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php     started root   /Library/LaunchDaemons/homebrew.mxcl.php.plist

혹시 Xcode 관련 오류가 있을때에는 다음과 같이 해줍니다.

# Error: You have not agreed to the Xcode license. Please resolve this by running:
  sudo xcodebuild -license accept

도메인 테스트를 합니다.

ping blog.test

PING blog.test (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.035 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.101 ms

127.0.0.1 이 안나오면 dnsmasq 가 제대로 돌지 않는 것입니다.

6. Valet Park

Phpstorm 을 사용하면 프로젝트 폴더인 ~/PhpstormProjects 에서 park 합니다.

composer global require laravel/installer
cd ~/PhpstormProjects
laravel new blog
valet park

park 된 리스트는 다음과 같이 확인합니다.

valet paths

[
    "/Users/user/.config/valet/Sites",
    "/Users/user/Sites",
    "/Users/user/PhpstormProjects"
]

http://blog.test 브라우저에서 테스트 합니다. 도메인은 소문자 - 로만 구성되니 git 프로젝트 폴더 생성에 유의

7. 문제 해결

보통 php or valet 버젼 문제등으로 동작하지 않을때가 있습니다. 재설치 합니다.

valet uninstall
valet install

그래도 페이지가 안나올 경우 nginx, php 의 sock 파일 path 를 비교해서 맞춥니다.

cat /usr/local/etc/nginx/valet/valet.conf | grep fastcgi_pass
fastcgi_pass unix:/Users/user/.config/valet/valet.sock;

cat /usr/local/etc/php/7.3/php-fpm.d/www.conf | grep 'listen ='
listen = /Users/user/.config/valet/valet.sock

각각 맞춘 뒤 nginx, php-fpm 을 리스타팅 합니다.

brew services restart nginx
brew services restart php

8. 유용한 명령어

  • park : 폴더 안의 폴더들을 서비스 하게 됩니다. 되도록이면 도메인 규칙에 맞게 소문자,- 정도만 써서 git repository 명으로 해주는게 좋습니다.
  • forget : park 한 것을 취소 합니다.
  • link : 폴더 안에서 valet link 를 하면 해당 폴더의 웹루트로 서비스 됩니다.
  • links : link 를 통해서 링크들입니다.
  • unlink : link 한 것을 삭제 합니다.
  • secure : https 처리로 접속하게 셋팅합니다.
  • share : ngrok(https://ngrok.com/) 로 외부네트워크에 접속하게 통로를 만들어 줍니다. 다른 팀원이 개발 내용을 확인한다거나, 모바일로 api 접근할때 유용합니다. 한국의 경우 valet share --region=ap 로 접속하는게 좋습니다.

9. Init Laravel

laravel new blog
cd $_
git init
git add .
git commit -m "First Commit"
touch databases/database.sqlite

Edit .env

# DB_CONNECTION=mysql
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=homestead
# DB_USERNAME=homestead
# DB_PASSWORD=secret
DB_CONNECTION=sqlite

# for 5.8 below
php artisan make:auth
# for 6.0 above
# reference : https://laravel-news.com/running-make-auth-in-laravel-6
composer require laravel/ui
php artisan ui vue --auth

npm install
npm run prod
# or
yarn install
yarn run prod

php artisan migrate
php artisan tinker

Psy Shell v0.8.17 (PHP 7.1.6 — cli) by Justin Hileman
>>> $user = new App\User
>>> $user->name = 'admin'
>>> $user->email = 'admin@blog.test'
>>> $user->password = bcrypt('admin')
>>> $user->save()

http://blog.test 접속해서 로그인 테스트 하면 됩니다.

@sungjoo-moon-kurly
Copy link

sungjoo-moon-kurly commented Sep 17, 2019

npm install
npm run prod
# or
yarn install
yarn run prod

이 부분은 어떤 역할인가요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment