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

Sep 19, 2018 am 11:17 AM
linux

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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!
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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)
Copy after login

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
Copy after login

步骤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
Copy after login

配置Composer全局使用。

# mv /root/composer.phar /usr/bin/composer
Copy after login

测试命令是否可用。

# composer -v
______
/ ____/___  ____ ___  ____  ____  ________  _____
/ /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                 /_/
Composer version 1.2.4 2016-12-06 22:00:51
Copy after login

步骤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
Copy after login

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

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

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

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

# shopt -s dotglob nullglob && mv /var/www/html/magento2/* /var/www/html/ && cd ..
Copy after login

设置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
Copy after login

运行 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
Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

git software installation git software installation Apr 17, 2025 am 11:57 AM

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

See all articles