在EC2实例上构建EC-CUBE4

我是Tirol,正在个人开发EC-CUBE插件。
在开发自己的插件过程中,以前使用Heroku作为测试的服务器,但从某个时候开始,插件安装失败。→参考issue。
由于本地运行也失败,所以我现在正在研究和总结在EC2实例上搭建EC-CUBE的方法。

EC2实例的规格

    t2.medium (t2.micro 以下だとメモリが足らなくてプラグインインストールに失敗します)
    Amazon Linux 2

这篇文章是我们参考的。

本文参考下述文章,总结了在同一服务器上运行数据库和应用程序所需的设置。
– 在Amazon Linux 2上安装EC-CUBE 4.0.4的步骤
– 在EC2(Amazon Linux 2)上安装mariaDB

环境搭建步骤

安装各个包。

如果您想自动执行本章中所述的命令,请复制并执行此 gist 中的 shell 脚本。

切换到根目录

$ sudo su -

日本的时间和字符编码的设置

$ timedatectl set-timezone Asia/Tokyo
$ sed -i "s/en_US\.UTF-8/ja_JP\.UTF-8/g" /etc/sysconfig/i18n

更新yum

$ yum update -y

安装每个软件包。

# Install apache
$ yum install -y httpd

# Install php
$ amazon-linux-extras install -y php7.2
$ yum install -y php-mbstring php-xml php-intl

# Install git
$ yum install -y git

# Install MySQL server and client
$ systemctl start mariadb
$ sudo systemctl enable mariadb

为了EC-CUBE的内核进行权限更改。

$ usermod -a -G apache ec2-user
$ chown -R ec2-user:apache /var/www
$ chmod 2775 /var/www
$ find /var/www -type d -exec sudo chmod 2775 {} \;
$ find /var/www -type f -exec sudo chmod 0664 {} \;

安装composer

$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php composer-setup.php
$ rm composer-setup.php
$ sudo mv composer.phar /usr/local/bin/composer

编辑各种配置文件

进行Apache和PHP的设置。

用Vim打开/etc/httpd/conf/httpd.conf文件,并进行以下设置。

<IfModule mime_module>
    AddType application/x-httpd-php .php
</IfModule>

<Directory "/var/www/html">
    AllowOverride All
</Directory>

然后,为了避免插件安装失败,可能是由于内存限制的原因,可以使用 vim 打开 /etc/php.ini 文件,并进行以下设置。

memory_limit = 512M

最后,通过以下命令重新启动 Apache,以使 php.ini 的更改生效。

$ systemctl restart httpd.service

MariaDB的配置

使用MariaDB登录,并创建在EC-CUBE中使用的数据库以及具有对该数据库的访问权限的用户。

通过运行mysql_secure_installation命令进行初始设置。

您可以选择根用户的初始密码以及是否删除测试用数据库等。请根据您的喜好进行设置。

$ mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] Y
 ... Success!

By default, MariaDB 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? [Y/n] 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? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

创建 EC-CUBE 使用的 MySQL 数据库和用户。

我将按照要求来操作。
这次我创建了一个名为ec_cube_database的数据库,并创建了一个名为ec_cube_user的用户,并赋予其对该数据库的所有操作权限。

$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE 'ec_cube_database';
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> CREATE USER 'ec_cube_user'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL on ec_cube_database.* to 'ec_cube_user'@'localhost';
Query OK, 0 rows affected (0.00 sec)

EC-CUBE 安装

$ cd /var/www/html/
$ git clone https://github.com/EC-CUBE/ec-cube.git
$ chmod 764 ec-cube/bin/console
$ cd ec-cube/
$ composer install
$ bin/console eccube:install

在执行bin/console eccube:install命令时,将要求您从标准输入中输入各个环境变量。
最低限度需要设置的是Database Url。请参考Connection URL Syntax进行设置。

在我的情况下,会是以下这样。

 Database Url [sqlite:///var/eccube.db]:
 > mysql://ec_cube_user:password@localhost/ec_cube_database

行动确认

如果访问<公共DNS>/ec-cube/后能够显示网站,则表示一切正常。

スクリーンショット 2020-09-24 18.44.53.png

bannerAds