Tools/MacOS

macOS 에서 웹서버(아파치)서버 설치 및 실행시키기

에그티비 2023. 10. 15. 05:20

내장 아파치 서버

macOS 에는 기본적으로 내장 아파치 웹서버가 설치되어 있다.

 

버전확인

apachectl -v

 

내장 아파치 실행

sudo apachectl start

브라우저에서 localhost 로 접속해 본다.

 

폴더확인

cd /Library/WebServer/Documents

 

Homebrew 를 이용한 아파치 웹서버 설치

내장 아파치의 실행 종료 및 자동 로드 스크립트 제거

sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null

 

설치하기

brew install httpd

 

실행 및 중지

brew services start httpd

brew services stop httpd

brew services restart httpd

 

httpd 상태 확인

httpd -V

 

httpd 설정 변경하기

 

httpd.conf 의 위치

- Intel Mac : /usr/local/etc/httpd

- M2 Mac : /opt/homebrew/etc/httpd

vi /opt/homebrew/etc/httpd/httpd.conf

 

httpd 에러 관련

homebrew 실행 폴더

# Intel CPU
cd /usr/local/bin

# Apple Silcon
cd /opt/homebrew/bin

homebrew 설치 폴더

# Intel CPU
cd /usr/local/Cellar

# Apple Silicon
cd /opt/homebrew/Cellar

 

 

httpd 가 계속해서 실행이 안되고 중지된 상태에서 다음과 같은 에러가 발생한 경우

Bootstrap failed: 5: Input/output error

Try re-running the command as root for richer errors.

Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/UserID/Library/LaunchAgents/homebrew.mxcl.httpd.plist` exited with 5.

brew services stop httpd

sudo apachectl -k stop

brew services start httpd

brew services list