Magento は PHP で書かれたオープンソースの E コマースプラットフォームです。 B2B や B2C の E コマースプラットフォーム構築によく使われています。 このチュートリアルでは、単一の ECS インスタンス上に Magento プラットフォームを構築する方法を説明します。
このチュートリアルでは、次のツールをインストールします。
- MySQL バージョン: 5.7
- PHP バージョン: 7.0
- Magento バージョン: 2.2
前提条件
ECS インスタンスを作成します。 そのインスタンスは次の条件を満たすものとします: オペレーティングシステム: CentOS 7.2 64ビット。 最低限のスペックとして、2コア CPU、4 GBのメモリ、40 GBの Ultra Cloud Disk をシステムディスクとして使用。 VPC 接続。 VPC ネットワークがない場合は、ECS インスタンスの作成時に作成されます。 インスタンスにアサインされたパブリック IP アドレス。
ECS インスタンスの TCP ポート 80 に対するインバウンドトラフィックが許可されています。 詳細は、「ECS インスタンスの作成」と「セキュリティグループ ルールの追加」をご参照ください。
サービス | ルールの方向 | 権限付与ポリシー | プロトコルタイプ | ポート範囲 | 権限付与タイプ | 権限付与オブジェクト | 優先度 |
---|---|---|---|---|---|---|---|
HTTP | インバウンド | 許可 | ユーザー定義の TCP | 80/80 | アドレスフィールドアクセス | 0.0.0.0/0 | 1 |
MySQL | インバウンド | 許可 | ユーザー定義の TCP | 3306/3306 | アドレスフィールドアクセス | 0.0.0.0/0 | 1 |
手順
次のステップで、ECS を使用して Magentoの Web サイトを構築します。
ステップ 1: LAMP を ECS にインストールする
ステップ 2: データベースを設定する
ステップ 3: Composer をインストールして設定する
ステップ 4: Magento をインストールして設定する
ステップ 5: インストールをテストする
このセクションでは、LAMP プラットフォームを手動でインストールする方法を説明しま す。 LAMP イメージを購入してクラウドマーケットから直接 ECS インスタンスを起動することで、すぐに Web サイトを構築することもできます。
- ECS インスタンスに接続し、Apache と MySQL をインストールします。
# yum -y update # yum -y install httpd # rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm # yum -y install mysql-community-server
- Apach e と MySQL をサービスとして起動し、起動時に有効にします。
# systemctl start httpd # systemctl enable httpd # systemctl start mysqld # systemctl enable mysqld
- Apacheの設定ファイル /etc/httpd/conf/httpd.conf を設定します。
vim /etc/httpd/conf/httpd.conf
を実行します。i
キーを押します。Include conf.modules.d/*.conf
の下に、conf.modules.d/*.conf
を追加しま す。そして次のセクションのAllowOverride None
をAllowOverride all
に置き換えます。Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None
Esc
キーを押し、「wq:
」と入力してファイルを保存して終了します。
- 次のコマンドで、MySQL のインストール時に、ルートアカウントの一時パスワードを取得します。
# grep 'temporary password' /var/log/mysqld.log. 2016-12-13T14:57:47.535748Z 1 [Note] A temporary password is generated for root@localhost: p0/G28g>lsHD
- 次のとおり、MySQL のセキュリティ設定を完了します。
- ルートアカウントのパスワードのリセット
- リモートのルートログインの無効化
- 匿名ユーザーの削除
-
テストのデータベースとテストのデータベースに対するアクセスの削除
詳細については、公式情報をご参照ください。
# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: # Enter your temporary root password that is recorded in the previous step The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 100 Change the password for root? (Press y|Y for Yes, any other key for No): Y New password: # Enter a new strong password. The password can be [8, 30] characters in length. It must contain uppercase letters, lowercase letters, and numbers. The following special characters are allowed: ()`~! @#$%^&*-+=|{}[]:;‘<>,.? / Re-enter new password: # Repeat the new password to confirm it Estimated strength of the password: 100 Do you wish to continue with the password provided?( Press y|Y for Yes, any other key for No) : Y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No): Y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No): Y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No): Y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No): Y Success. All done!
- PHP 7をインストールします。
# yum install -y http://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-14.ius.centos7.noarch.rpm # yum -y update # yum -y install php70u php70u-pdo php70u-mysqlnd php70u-opcache php70u-xml php70u-gd php70u-mcrypt php70u-devel php70u-intl php70u-mbstring php70u-bcmath php70u-json php70u-iconv
- PHP のインストールを検証します。
# php -v PHP 7.0.13 (cli) (built: Nov 10 2016 08:44:18) (NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.13, Copyright (c) 1999-2016, by Zend Technologies
- /etc/php.ini ファイルを編集してタイムゾーンを設定します。
vim/etc/php.ini
を実行します。i
キーを押します。- date.timezone で始まる行を見つけます。
which is commented out by default, and add the correct time zone. If your site is in China, add date.timezone = Asia/Shanghai.
- httpb を下記のコマンドで再起動します。
systemctl restart httpd.
次のような手順でデータベースを設定します:
- データーベースとユーザーを作成します。 次のコマンドを実行します (mysql> プロンプトの後のコマンドも含めてください)。
# mysql -u root -p Enter password: mysql> CREATE DATABASE magento; Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL ON magento. * TO YourUser@localhost IDENTIFIED BY 'YourPass'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
exit
を実行して MySQL を終了します。- 新しいユーザーをテストします。
# mysql -u YourUser -p mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | magento | +--------------------+ 2 rows in set (0.00 sec) mysql> exit
- Composer をインストールします。
# curl -sS https://getcomposer.org/installer | php All settings correct for using Composer Downloading 1.2.4... Composer successfully installed to: /root/composer.phar Use it: php composer.phar
- Composer を設定します。
# mv /root/composer.phar /usr/bin/composer
- Composer をテストします。
# composer -v ______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ . ___/\____/____/\___/_/ /_/ Composer version 1.2.4 2016-12-06 22:00:51
- 以下の
gitclone
までのコマンドを使用して、Magento を github からインストールします。# yum -y install gitsiyousite # cd /var/www/html/ # git clone https://github.com/magento/magento2.git
- Magento のバージョンを、安定した本番バージョンに切り替えます。
# cd magento2 && git checkout tags/2.1.0 -b 2.1.0 Switched to a new branch '2.1.0'
- インストールファイルを Apache のルートディレクトリに移動します。 このステップをスキップ すると、Magento サービスは、
http://your-server-ip /magento2
でのみアクセスできるよ うになります。.# shopt -s dotglob nullglob && mv /var/www/html/magento2/* /var/www/html/ && cd ..
- Magento のファイルのアクセス許可を以下のように設定します。
# chown -R :apache /var/www/html # find /var/www/html -type f -print0 | xargs -r0 chmod 640 # find /var/www/html -type d -print0 | xargs -r0 chmod 750 # chmod -R g+w /var/www/html/{pub,var} # chmod -R g+w /var/www/html/{app/etc,vendor} # chmod 750 /var/www/html/bin/magento
composer install
を実行して Magento をインストールします。- ブラウザーでサーバー (
http://ECS インスタンスのパブリック IP アドレス
) にアクセスします。 下のような、画面が表示されます。 - [同意して Magento を設定] をクリックし、データベース情報、Web 設定、アカウントを次のように入力します。 以下のような画面が表示されれば、インストールは成功です。
crontab -u apache -e
を実行します。- /etc/crontab ファイルに以下を追記します。
*/10 * * * * php -c /etc /var/www/html/bin/magento cron:run */10 * * * * php -c /etc /var/www/html/update/cron.php */10 * * * * php -c /etc /var/www/html/bin/magento setup:cron:run
詳細は、公式ドキュメントをご参照ください。
次にすること
http://ECS インスタンスのパブリック IP アドレス
にアクセスして、デフォルトのホームページを表示します。
http://ECS インスタンスのパブリック IP アドレス/admin
にアクセスして、インストール時に設定したユーザー名とパスワードを使用して、ダッシュボードにログインします。
Magento の設定について詳しくは、公式ドキュメントを参照してください。