1
2

More than 3 years have passed since last update.

Macに(L)AMP環境を構築してlaravelを動かした時のメモ

Posted at

LAMP環境とは

Linux + Mysql + Apache + PHP の、webの一般的な構成。今回はLinux以外をインストールした。

参考

https://qiita.com/moroya/items/a0b7881c4b3d809c6f21
http://vdeep.net/homebrew-php-apache-mysql
https://qiita.com/kyosuke5_20/items/c5f68fc9d89b84c0df09

Homebrew

基本的に今回は全てhomebrewでインストールした。
入ってない方はこちらから→ https://brew.sh/

PHPのインストール

$ brew install php

Apacheのインストール

$ brew install httpd
$ which apachectl
/usr/local/bin/apachectl

このパスが返ってこれば大丈夫。

Apacheの設定

$ vi /usr/local/etc/httpd/httpd.conf 

ポート番号を指定(80がデフォルトなのでそれに合わせる)

httpd.conf
Listen 80

ホストも合わせる。(コメントアウトされていれば外す)

httpd.conf
ServerName localhost:80 

ドキュメントルートを変更する。

httpd.conf
DocumentRoot "{フォルダパス}"

そのすぐ下も書き換える

httpd.conf
<Directory "{フォルダパス}"> #ドキュメントルートに合わせる。
Options FollowSymLinks
AllowOverride All #追加
Order deny,allow
Deny from all
</Directory>

mod_rewriteが効くようにする。下のコメントアウトを外す。

httpd.conf
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

index.phpを実行できるようにする。

httpd.conf
DirectoryIndex index.php index.html

phpを実行できるようにする。
<IfModule mime_module>内に追記。

httpd.conf
AddType application/x-httpd-php .php

phpを使えるようにする。末尾に追記。
httpd.conf
LoadModule php7_module /usr/local/Cellar/php/7.4.1/lib/httpd/modules/libphp7.so

MySQLのインストール

$ brew install mysql

MySQLの設定

MySQLを起動

$ mysql.server start

パスワードを変更

$ mysqladmin -u root password 'パスワード'

セキュリティ設定

$ mysql_secure_installation

Y/nで選択する。1つ目(パスワードチェック)、2つ目(rootのパスワード)以外はY。

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: n
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n 
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

つかいかた

Apache

$ apachectl start
$ apachectl stop
$ apachectl restart

Mysql

mysql.server status
mysql.server start
mysql.server reload
mysql.server stop

mysql -u root -p #コンソール

おまけ:nodeのインストール

laravelでjs・sassをコンパイルするために。

nodeをインストールする nodebrew をインストールする。

$ brew install nodebrew
$ mkdir -p ~/.nodebrew/src #行わないと次がエラーになる
$ nodebrew install-binary stable
$ nodebrew ls #インストールされているnodeを表示
$ nodebrew use {使いたいバージョン} #有効化

あとは、 $HOME/.nodebrew/current/bin にパスを通して終わり。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2