Home >Operation and Maintenance >Linux Operation and Maintenance >How to build a Magento e-commerce website on a Linux instance

How to build a Magento e-commerce website on a Linux instance

坏嘻嘻
坏嘻嘻Original
2018-09-19 11:17:242752browse

The content of this article is about how to build a Magento e-commerce website on a Linux instance. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Build a Magento e-commerce website on a Linux instance


Magento is an open source e-commerce website framework with rich modular architecture and expanded functions Can provide solutions for large and medium-sized sites. It is developed using PHP, supports versions ranging from PHP 5.6 to PHP 7.1, and uses MySQL to store data. This article mainly explains how to build a Magento e-commerce website on an Alibaba Cloud ECS instance. The operating system used is Linux CentOS 7.2 64-bit.

Applicable objects

Applicable to users who are familiar with ECS and Linux systems and have just started using Alibaba Cloud to build websites.

Resources

The Linux ECS instance configuration involved in the operations described in this article includes: 2 vCPU, 4 GiB memory, Cent OS 7.2 64-bit operating system, VPC network, and assigned public IP address.

Instructions: Used to build a server for Magento 2, the memory must not be less than 2 GiB.

The Magento e-commerce website built based on this article uses the following software version information:

MySQL 5.7

PHP 7.0

Magento 2.1

Prerequisites

You have created a VPC network type Linux ECS instance. For detailed operations, see Creating an ECS instance. Configuration includes: 2 vCPU, 4 GiB memory, Cent OS 7.2 64-bit operating system, VPC network, and allocated public IP address.

The security group rules shown in the following table have been added to the security group where the ECS instance is located. For detailed operations, see Creating an ECS Instance and Adding Security Group Rules.

How to build a Magento e-commerce website on a Linux instance

Operation steps

The steps to build a Magento website using cloud server ECS are as follows:

Step 1. Install and configure the LAMP platform

Step 2. Create database

Step 3. Install and configure Composer

Step 4. Install and configure Magento

Step 5. Add cron job

Step 1. Install and configure the LAMP platform

This section explains how to manually install the LAMP platform. You can also purchase a LAMP image in the cloud market to directly start an ECS instance to quickly build a website.

Run the following commands in sequence to update the package and repository, and install the Apache web server and MySQL server.

# 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

Start the HTTP and MySQL services and set them to start automatically at boot.

# systemctl start httpd
# systemctl enable httpd
# systemctl start mysqld
# systemctl enable mysqld

Edit the Apache configuration file:

Run the command vim /etc/httpd/conf/httpd.conf.

Press the i key to enter edit mode.

Make the following modifications:

Add LoadModule rewrite_module modules/mod_rewrite.so after Include conf.modules.d/*.conf.

Change the following content from AllowOverride None to 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

Press the Esc key to exit editing, and enter :wq to save and exit.

View the /var/log/mysqld.log file to obtain the root user password automatically set when installing 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

Running the following command can improve the security of MySQL from the following four aspects:

Set root account password

Prohibit root account remote login

Delete the anonymous user account

Delete the test library and access permissions to the test library

Please refer to the official documentation for detailed instructions.

# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: #输入第4步中获取的root用户密码
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 #是否更改root用户密码,输入Y
New password: #输入密码
Re-enter new password: #再次输入密码
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 #是否删除匿名用户,输入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 #禁止root远程登录,输入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 #是否删除test库和对它的访问权限,输入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 #是否重新加载授权表,输入Y
Success.
All done!

Run the following commands in order to install PHP 7 and some additional required PHP extensions.

# 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

Check the PHP version to verify whether PHP has been successfully installed.

# 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

Edit the configuration file /etc/php.ini:

Run the command vim /etc/php.ini.

Press i to enter edit mode.

Add the following configuration at the end of the file:

memory_limit = 128M #Increase the memory limit according to the actual situation

date.timezone = Asia/Shanghai #Set the time zone to Shanghai.

Restart the Web service process.

# systemctl restart httpd

Step 2. Create database

Follow the following steps to create a database.

Create database and user: Create a database and a database user for Magento data. The database and user name can be modified according to the actual situation.

# mysql -u root -p
Enter password: 
mysql> CREATE DATABASE magento; #根据实例情况替换magento
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL ON magento.* TO YourUser@localhost IDENTIFIED BY 'YourPass'; #根据实际情况替换YourUser和YourPass
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Run exit to exit MySQL.

(可选)验证新建的Magento数据库和用户是否可用。

# mysql -u YourUser -p
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| magento            |
+--------------------+
2 rows in set (0.00 sec)
mysql> exit

步骤3. 安装配置Composer

Composer是PHP一个包管理和包依赖管理的工具。按以下步骤安装配置Composer。

安装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 -v
______
/ ____/___  ____ ___  ____  ____  ________  _____
/ /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                 /_/
Composer version 1.2.4 2016-12-06 22:00:51

步骤4. 安装配置Magento

您可以使用不同的方法安装Magento,也可以选择是否安装示例数据。如果安装Magento仅用于测试,您可以选择安装示例数据。如果是在生产环境中安装Magento,建议您安装全新的Magento,从头开始配置。

本部分介绍如何使用git下载Magento,然后使用Composer安装Magento。

依次运行以下命令,通过 git clone 下载Magento。

# yum -y install git
# cd /var/www/html/
# git clone https://github.com/magento/magento2.git

(可选)将Magento切换到稳定版本。

默认情况git下载安装Magento是一个最新的开发版本。如果您在生产环境中使用,建议切换到稳定版本,否则未来将无法升级安装。

# cd magento2 &&  git checkout tags/2.1.0 -b 2.1.0
Switched to a new branch '2.1.0'

将安装文件移到Web服务器根目录下。否则,您只能通过 http://[ECS实例公网IP地址]/magento2 访问您的Magento站点。

# 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安装成功。

How to build a Magento e-commerce website on a Linux instance

单击 Agree and Setup Magento 开始配置Magento:按实际情况填写连接数据库信息、Web访问设置、定制商店、创建管理员账号。出现如下图所示的界面时,说明Magento配置完成

How to build a Magento e-commerce website on a Linux instance

步骤5. 添加cron作业

运行 crontab -u apache -e 设置cron运行调度工作。

添加以下内容。

*/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

The above is the detailed content of How to build a Magento e-commerce website on a Linux instance. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn