Manually Setting Up a Magento E-Commerce Website (Linux)
Overview
The section guides you through the manual setup of a Magento e-commerce website on a Linux ECS. Magento is an open source e-commerce system that features flexible design, modular architecture, and rich functions. It is suitable for building medium- and large-sized sites. Magento is written in PHP and employs the MySQL database management system for data storage.
Prerequisites
- You have purchased an ECS and bound an EIP to it.
- The rules listed in the following table have been added to the security group which the target ECS belongs to. For details, see Adding a Security Group Rule.
Table 1 Security group rules Direction
Protocol/Application
Port/Range
Mandatory
Source IP Address
Inbound
TCP(22)
22
Yes
IP address of the client that is allowed to remotely connect to Linux ECSs using SSH. If the source IP is set to 0.0.0.0/0, access from all IP addresses is allowed. For security purposes, 0.0.0.0/0 is not recommended.
Inbound
HTTP(80)
80
Yes
IP address of the client that is allowed to access Magento. If the source IP is set to 0.0.0.0/0, access from all IP addresses is allowed.
Inbound
MySQL(3306)
3306
No
IP address of the client that is allowed to remotely access MySQL databases. If the source IP is set to 0.0.0.0/0, access from all IP addresses is allowed. For security purposes, 0.0.0.0/0 is not recommended.
Resource Planning
Table 2 lists the resource configuration and software versions used in this practice. The commands and parameters may vary according to the hardware specifications or software versions you would use.
Resource |
Type |
Specification/Version |
---|---|---|
ECS configuration |
Flavor |
c6s.large.2 |
vCPUs |
2 vCPUs |
|
Memory |
4 GiB |
|
OS |
CentOS 7.2 |
|
Software resources |
Apache |
2.4.6 |
MySQL |
5.7 Download URL: http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm |
|
PHP |
7.0.33 Download URL: |
|
Composer |
1.10.19 Download URL: |
|
Magento |
2.1.0 Download URL: |
![](https://support.huaweicloud.com/intl/en-us/bestpractice-ecs/public_sys-resources/note_3.0-en-us.png)
To make sure that the website works properly, use an ECS whose memory is 2 GiB or higher.
Step 1: Install and Configure Apache
- Remotely log in to the ECS by referring to Logging In to a Linux ECS.
- To obtain and update the system and software, update the image source to a Huawei Cloud image source. For details, see How Can I Use an Automated Tool to Configure a Huawei Cloud Image Source (x86_64 and Arm)?
- Run the following commands as user root to update the software package and install Apache:
yum -y update yum -y install httpd
If an error message is displayed, indicating that the domain name cannot be resolved, add a DNS server to the /etc/resolv.conf file.
- Open the Apache configuration file.
vim /etc/httpd/conf/httpd.conf
If vim is not installed, run the yum install -y vim* command to install it.
- Press i to enter insert mode and modify the file as follows:
- Change AllowOverride None to AllowOverride all.
- Add the following parameters to the end of the configuration file:
LoadModule rewrite_module modules/mod_rewrite.so
- Change AllowOverride None to AllowOverride all.
- Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
- Run the following commands in sequence to start Apache and enable it to start automatically upon ECS startup:
systemctl start httpd systemctl enable httpd
Step 2: Install and Configure MySQL
- Run the following command as the root user to add a yum repository:
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
- Run the following command to Install MySQL:
yum -y install mysql-community-server --nogpgcheck
- Run the following commands in sequence to start MySQL and enable it to start automatically upon ECS startup:
systemctl start mysqld systemctl enable mysqld
- Run the following command to obtain the root user's password that is automatically set during MySQL installation:
grep 'temporary password' /var/log/mysqld.log
Information similar to the following is displayed, in which (n?K7jP#cirM is the temporary password.2019-05-09T11:29:42.365419Z 1 [Note] A temporary password is generated for root@localhost: (n?K7jP#cirM
- Run the following command to harden MySQL:
mysql_secure_installation
Perform operations as prompted.
Securing the MySQL server deployment. Enter password for user root: #Enter the obtained password of user root. The existing password for the user account root has expired. Please set a new password. New password: #Set a new password for user root. Re-enter new password: #Enter the new password again. 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 #Press Y to change the password of user root. New password: #Enter a new password that consists of 8 to 30 characters, including letters, digits, and special characters (` ~!@#$%^&*-+=|(){}[]:;'<>,.?/). Re-enter new password: #Enter the new password again. 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 #Press 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 #Press Y to remove anonymous users. 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 #Press Y to disallow remote logins of user root. 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 #Press Y to delete the test database and remove access to it. - 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 #Press Y to reload privilege tables. Success. All done!
- Log in to the MySQL database as the root user.
mysql -u root -p
- Run the following command to create a database named magento.
CREATE DATABASE magento;
- Run the following command to create a user for the database and assign full permissions to the user:
GRANT ALL ON magento.* TO magentouser@localhost IDENTIFIED BY 'xxxxx';
In this command, magento is the name of the database created in the previous step, magentouser is the name of the database user, and xxxxx is the password of the database user.
- Run the following command to exit the MySQL CLI:
exit
- (Optional) Perform the following operations to check whether the database and account have been created and then exit the MySQL CLI:
- Run the following command to log in to the MySQL CLI as user magentouser:
mysql -u magentouser -p
- Run the following command to view the created database:
SHOW DATABASES;
In the displayed information, magento is the newly created database.
+--------------------+ | Database | +--------------------+ | information_schema | | magento | +--------------------+ 2 rows in set (0.00 sec)
- Run the following command to exit the MySQL CLI:
exit
- Run the following command to log in to the MySQL CLI as user magentouser:
Step 3: Install and Configure PHP
- Run the following command to add the IUS and EPEL repositories:
yum install \ https://repo.ius.io/ius-release-el7.rpm \ https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- Run the following command to add a webtatic repository:
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
- Run the following command to install PHP7 and required PHP extensions for Magento:
yum -y install php70w php70w-pdo php70w-mysqlnd php70w-opcache php70w-xml php70w-gd php70w-mcrypt php70w-devel php70w-intl php70w-mbstring php70w-bcmath php70w-json php70w-iconv
- Run the following command to check the version of the installed PHP:
php -v
Information similar to the following is displayed:
PHP 7.0.33 (cli) (built: Dec 6 2018 22:30:44) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.33, Copyright (c) 1999-2017, by Zend Technologies
- Run the following command to open the PHP configuration file php.ini:
vim /etc/php.ini
- Press i to enter insert mode and modify the file as follows:
- Set memory_limit to a proper value.
- Uncomment and set date.timezone.
- Set memory_limit to a proper value.
- Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
- Run the following command to restart the web service process:
systemctl restart httpd
Step 4: Install Composer
Composer is a package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries.
- Install composer 1.x for the dependency of Magento 2.
Run the following commands to install the Composer of the specified version and set the installation path to /usr/bin/ for global use:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php --install-dir=/usr/bin/ --filename=composer --version=1.10.19
The command output is as follows:
All settings correct for using Composer Downloading... Composer (version 1.10.19) successfully installed to: /usr/bin/composer Use it: php /usr/bin/composer
- Run the following command to check whether the Composer is successfully installed:
composer -v
The command output is as follows:
______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.10.19 2020-12-04 09:14:16 ...
Step 5: Install Magento
When installing Magento, you can determine whether to install sample data. If Magento is only used for testing, it is optional for you to install sample data. If Magento is used in production environments, you are advised to perform initial configuration instead of installing sample data.
- Run the following command to install git:
yum -y install git
- Run the following commands to go to the default root directory /var/www/html/ of the web server and use git to download Magento:
cd /var/www/html/ git clone https://github.com/magento/magento2.git
- Switch Magento to a stable version.
By default, Magento of the latest version is installed. In the production environment, you are advised to switch to a stable version.
cd magento2 && git checkout tags/2.1.0 -b 2.1.0
The command output is as follows:
Switched to a new branch '2.1.0'
- Run the following command to move the installation file to the root directory /var/www/html/ of the web server. /var/www/html/magento2/ is the directory where Magento is installed.
shopt -s dotglob nullglob && mv /var/www/html/magento2/* /var/www/html/ && cd ..
Then, you can access the Magento site from http://magento server IP address. If you do not move the installation file to the root directory, you can access the Magento site only from http://magento server IP address/magento2.
- Run the following commands to set file permissions for Magento:
chown -R apache: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
- Run the following command to install unzip and zip.
yum install -y unzip zip
- Run the following commands to go to the default root directory /var/www/html/ of the web server and use Composer to install Magento:
cd /var/www/html/ composer install
- After the installation is complete, enter http://magento server IP address in the address bar of a browser to visit Magento. If the following page is displayed, Magento is installed successfully.
Step 6: Configure Magento
- Visit http://magento server IP address and click Agree and Setup Magento to start the configuration.
- Click Start Readiness Check to check the environment. After the check is passed, click Next.
- Enter the MySQL database user magentouser, the password of the database user, and the database magento created in Step 2: Install and Configure MySQL, and click Next.
- Set the website access address and background management address, and click Next.
The background management address can be customized.
- Set the time zone and language, and click Next.
- Set the admin account and click Next.
- Click Install Now and wait until the installation is complete.
If the following information is displayed, the installation is successful.
- Log in to the Magento server and set up cron jobs.
crontab -u apache -e
- Press i to enter insert mode and add the following content:
*/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
Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
For more information about running Magento cron jobs, see Magento Documentation.
- Enter http://magento server IP address in the address bar of a browser. The following page is displayed by default.
- Enter http://magento background management address in the address bar of a browser and use the admin account to log in. After the login is successful, the following page is displayed.
If the message "One or more indexers are invalid. Make sure your Magento cron job is running" is displayed, run the php bin/magento indexer:reindex command in Magento root directory /var/www/html.
For more information about Magento configuration, see Magento Documentation.
Step 7: Other Operations
- Purchase a domain name.
Configure a unique domain name for website access. You need to obtain an authorized domain name from the domain name registrar first.
- Configure DNS records.
Your website can be visited using the registered domain name only after DNS records are configured. For details, see Routing Internet Traffic to a Website.
For example, if the domain name is www.example.com, enter http://www.example.com in the address bar of the browser to access the website.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot