Magento 2.4 切り替え方法
magento用ユーザに切り替え、magentoのRootに移動
$ su - magento_user
Password:
$ cd /var/www/html
以下のコマンドを発行した後、cache flushする
php bin/magento setup:store-config:set --base-url="http://<URL which you change to>"
php bin/magento cache:flush
参考:https://blog.netgloo.com/2016/05/13/magento-2-change-base-url-using-the-command-line/
Magento2.3.5
Magento2.4は上記の方法で切り替えられたが、Magento2.3.5ではうまくいかなかった。仕方がないのでMagentoのuninstall & install で行ってみる。
Uninstall
$ php bin/magento setup:uninstall
Are you sure you want to uninstall Magento?[y/N]Y
Starting Magento uninstallation:
Cache cleared successfully
Cleaning up database `magento2`
File system cleanup:
/var/www/html/var/backups
/var/www/html/var/cache
/var/www/html/var/composer_home
/var/www/html/var/log
/var/www/html/var/page_cache
/var/www/html/var/resource_config.json
/var/www/html/var/tmp
/var/www/html/var/view_preprocessed
/var/www/html/app/etc/config.php
/var/www/html/app/etc/env.php
[SUCCESS]: Magento uninstallation complete.
Install
続いてインストール。要はこの記事のセットアップ以降を実施することとなる。
$ php bin/magento setup:install \
--base-url="http://<your url>/" \
--db-host=localhost \
--db-name=magento2 \
--db-user=magentip \
--db-password="<your password>"
Starting Magento installation:
File permissions check...
[Progress: 1 / 1068]
Required extensions check...
[Progress: 2 / 1068]
Enabling Maintenance Mode...
[Progress: 3 / 1068]
Installing deployment conf
(途中略)
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_109e6q
Sample Data is installed with errors. See log file for details
Nothing to import.
最後に表示されている/admin_109e6q
が管理用URLとなる。
管理者の追加
Magento2のAdmin関係の設定をまだ行っていないため、設定を追加する
$ $ php bin/magento admin:user:create
Admin user: admin
Admin password: <admin-password>
Admin email: <your-e-mail-address>
Admin first name: <your-first-name>
Admin last name: <your-last-name>
Created Magento administrator user named admin
ファイルのPermission変更
DocumentRoot配下に作成されたフォルダ・ファイルのオーナーとパーミッションを変更します。
$ cd /var/www/html
$ sudo chown -R magento_user:www-data .
$ find . -type d -exec chmod 770 {} \;
$ find . -type f -exec chmod 660 {} \;
$ chmod 770 bin/magento
Deploy
これを行わないとMagento上のコンテンツがコンパイルされない。
$ php bin/magento deploy:mode:set production
Enabling maintenance mode
Starting compilation
Compilation was started.
%message% 0/8 [>---------------------------] 0% < 1 sec 76.5 MiBProxies code generation... 0/8 [>---------------------------] 0% < 1 sec 76.5 MiB
Proxies code generation... 1/8 [===>------------------------] 12% 1 sec 78.5 MiB
Repositories code generation... 1/8 [===>------------------------] 12% 1 sec 78.5 MiB
Repositories code generation... 2/8 [=======>--------------------] 25% 10 secs 205.0 MiB
Service data attributes generation... 2/8 [=======>--------------------] 25% 10 secs 205.0 MiB
Application code generator... 3/8 [==========>-----------------] 37% 10 secs 205.0 MiB
Application code generator... 4/8 [==============>-------------] 50% 17 secs 229.0 MiB
Interceptors generation... 4/8 [==============>-------------] 50% 17 secs 229.0 MiB
Interceptors generation... 5/8 [=================>----------] 62% 31 secs 259.0 MiB
Area configuration aggregation... 5/8 [=================>----------] 62% 31 secs 259.0 MiB
Area configuration aggregation... 6/8 [=====================>------] 75% 39 secs 351.0 MiB
Interception cache generation... 6/8 [=====================>------] 75% 39 secs 351.0 MiB
Interception cache generation... 7/8 [========================>---] 87% 45 secs 351.0 MiB
App action list generation... 7/8 [========================>---] 87% 45 secs 351.0 MiB
App action list generation... 8/8 [============================] 100% 45 secs 351.0 MiB
Generated code and dependency injection configuration successfully.
Compilation complete
Starting deployment of static content
Deploy using quick strategy
frontend/Magento/blank/en_US 2345/2345 ============================ 100% 9 secs
adminhtml/Magento/backend/en_US 2438/2438 ============================ 100% 8 secs
frontend/Magento/luma/en_US 2362/2362 ============================ 100% 12 secs
Execution time: 34.016122102737
Deployment of static content complete
Disabling maintenance mode
Enabled production mode.
この段階で、変更後のURLでアクセスすることができる。