LoginSignup
1
1

More than 5 years have passed since last update.

Magento2を動かす

Last updated at Posted at 2017-07-20

Magento2をMacのPHPで動かしたい。

なんかDockerで動くやつとかはある。
とはいえ諸々面倒だったり、自分でディレクトリとかハンドルしづらい。

MySQLを起動させる

普通にSupervisordで起動する。

[program:mysql]
command=/usr/local/mysql/bin/mysqld
stdout_logfile=/var/log/supervisor/mysql/access.txt
stdout_logfile_maxbytes=1MB  
stdout_logfile_backups=10    
stderr_logfile=/var/log/supervisor/mysql/error.txt
stderr_logfile_maxbytes=1MB  
stderr_logfile_backups=10    
autostart=true
autorestart=true
user=mysql

インストールとかその辺はまあいい感じにやる。

PHP7を入れる

この辺はまあ別の記事で適当に。

Magentoの初期化をする

# DBを作って
$ mysql -uroot -e "CREATE DATABASE magento";
# Magentoの初期設定をCLIでやる
$ php bin/magento setup:install --base-url=http://localhost:9070 --db-host=localhost --db-name=magento --db-user=root --admin-firstname=Magento --admin-lastname=User --admin-email=user@example.com --admin-user=admin --admin-password=******** --language=ja_JP --currency=JPY --timezone=Asia/Tokyo --use-rewrites=0

こんな感じ。

Magentoの起動をする

Supervisordでやる。

supervisord.conf
[program:php-fpm]
command=/usr/local/sbin/php-fpm
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/fpm/access.txt
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stderr_logfile=/var/log/supervisor/fpm/error.txt
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
user=*****

[program:nginx]
command=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
user=root
autostart=true
autorestart=true
nginx.conf
location ~ ^/static/ {
    rewrite (.*/)version\d+/(.*$) $1$2; 
    root    /path/to/magento2/pub/;
}

location ~ ^/pub/static/ {
    rewrite (.*/)version\d+/(.*$) $1$2; 
    root    /path/to/magento2/;
}

location ~ ^/pub/media/ {
    root    /path/to/magento2/;
}

location / {
    rewrite (.*) /index.php/$1 break;
    root html;
    fastcgi_pass   127.0.0.1:9070;
    fastcgi_index  index.php;
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME /path/to/magento2/$fastcgi_script_name;
}

CompileとかUpgradeとかする

静的ファイルにversiond¥d+なキャッシュブレーカー的なURLが挟まれている。
Apacheとかnginxとかを挟んでいればRewriteすればいいがスタンドアロンサーバなのでできない。
MySQLのレコードを変更することで、オプションを外せるので外す。
レコードがあったらUpdate、なかったら Insertで対応

$ mysql -uroot magento -e "INSERT INTO core_config_data (scope , scope_id , path , value) VALUES ('default',0,'dev/static/sign','0');
;"
$ mysql -uroot magento -e "update core_config_data set value = "0" WHERE path='dev/static/sign'";

コンテンツを作ったりDIのコンパイルをしたりする。

php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
php bin/magento setup:static-content:deploy ja_JP
php bin/magento cache:flush;
php bin/magento cache:clean

$ open http://localhost/

enjoy!

1
1
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
1