Help Center > > Best Practices> Manually Setting Up a Magento E-Commerce Website (Linux)

Manually Setting Up a Magento E-Commerce Website (Linux)

Updated at: Mar 11, 2019 19:50

Overview

The best practices for HUAWEI CLOUD ECS guide you through the 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 provides solutions for medium- and large-sized sites. Magento uses PHP for developing and MySQL for data storage. The CentOS 7.2 64bit OS is used as an example in this section.

Prerequisites

The rule listed in the following table has been added to the security group to which the target ECS belongs. For details, see section Adding a Security Group Rule.

Table 1 Security group rules

Transfer Direction

Protocol/Application

Port/Range

Source End

Inbound

HTTP (80)

80

0.0.0.0/0

Inbound

MySQL (3306)

3306

0.0.0.0/0

Procedure

  1. Install and configure the LAMP platform.

    1. Log in to the ECS.
    2. Run the following commands to update the software package and install Apache and 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

      NOTE:

      During command execution, if an error message is displayed indicating a domain name resolution failure, add a DNS server to the /etc/resolv.conf configuration file.

  2. Run the following commands to start HTTP and MySQL and configure automatic HTTP and MySQL enabling upon ECS startup:

    systemctl start httpd

    systemctl enable httpd

    systemctl start mysqld

    systemctl enable mysqld

    1. Modify the Apache configuration file.
      1. Run the following command to open the httpd.conf file:

        vim /etc/httpd/conf/httpd.conf

      2. Press i to enter editing mode.
      3. Modify the httpd.conf file.
        • Change the AllowOverride value from None to all.

        • Add LoadModule rewrite_module modules/mod_rewrite.so to the end of the configuration file.

      4. Press Esc to exit the editing mode. Then, enter :wq to save the settings and exit the configuration file.
    2. Run the following command to obtain the password of user root that is automatically set during MySQL installation:

      grep 'temporary password' /var/log/mysqld.log

      Information similar to the following is displayed:
      2016-12-13T14:57:47.535748Z 1 [Note] A temporary password is generated for root@localhost: p0/G28g>lsHD
    3. Run the following command and perform operations as prompted to harden MySQL:

      mysql_secure_installation

      Securing the MySQL server deployment.
      
      Enter password for user root:    #Enter the obtained password of user 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   #Asks you whether to change the password of user root. Press y.
      
      New password:    #Enter the new password.
      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   #Asks you whether to remove anonymous users. Press 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   #Asks you whether to forbid remote login of user root. Press 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   #Asks you whether to delete the test database and cancel access permissions to it. Press 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   #Asks you whether to reload privilege tables. Press y.
      Success.
      
      All done!
    4. Run the following commands to install PHP 7 and PHP extensions required for installing Magento:

      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

    5. Run the following command to check the PHP installation:

      php -v

      If information similar to the following is displayed, PHP has been installed:

      PHP 7.0.30 (cli) (built: Apr 26 2018 13:30:35) ( NTS )
      Copyright (c) 1997-2017 The PHP Group
      Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
          with Zend OPcache v7.0.30, Copyright (c) 1999-2017, by Zend Technologies
    6. Modify the PHP configuration file.
      1. Run the following command to open the php.ini file:

        vim /etc/php.ini

      2. Press i to enter editing mode.
      3. Modify the php.ini file.
        • Change the memory_limit value based on site requirements for memory limit.

        • Comment out the following content and set date.timezone for the PHP time zone.

      4. Press Esc to exit the editing mode. Then, enter :wq to save the settings and exit the configuration file.
    7. Run the following command to restart the web process:

      systemctl restart httpd

  3. Create a database.

    1. Run the following command and enter the user root password of MySQL as prompted to log in to the MySQL CLI:

      mysql -u root -p

    2. Run the following command to create a new database:

      CREATE DATABASE magento;

      In the preceding command, magento is the database name, which is configurable.

    3. Run the following command to create a user for the database and assign the full-access permission to the user:

      GRANT ALL ON magento.* TO magentouser@localhost IDENTIFIED BY 'BLOck@123' ;

      In the preceding command, magentouser is the username for logging in to the database, and BLOck@123 is the configurable user password.

    4. Run the following command to exit the MySQL CLI:

      exit

    5. (Optional) Run the following commands to verify the creation of the database and account and exit the MySQL CLI:

      mysql -u magentouser -p

      SHOW DATABASES;

      exit

      In the preceding command, magentouser is the created username for logging in to the database.

  4. Install and configure Composer.

    Composer is a package manager for the PHP programming language. It manages PHP software dependencies and provides standard formats for dependent libraries.

    1. Run the following command to install Composer:

      curl -sS https://getcomposer.org/installer | php

      Information similar to the following is displayed:

      All settings correct for using Composer
      Downloading...
      
      Composer (version 1.6.5) successfully installed to: /root/composer.phar
      Use it: php composer.phar
    2. Run the following command to globally enable Composer:

      mv /root/composer.phar /usr/bin/composer

    3. Run the following command to check whether Composer has been installed:

      composer -v

      If information similar to the following is displayed, Composer has been installed:

         ______
        / ____/___  ____ ___  ____  ____  ________  _____
       / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
      / /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
      \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                          /_/
      Composer version 1.6.5 2018-05-04 11:44:59

  5. Install Magento.

    When installing Magento, you can determine whether to configure example data. If Magento is only used for testing, it is optional for you to configure example data. If Magento is installed in a production environment, you are advised to install the latest Magento version and perform initial configurations.

    1. Run the following command to download git:

      yum -y install git

    2. Run the following commands to download Magento using git:

      cd /var/www/html/

      git clone https://github.com/magento/magento2.git

    3. Switch Magento to a stable version.

      By default, the latest Magento version is installed. If Magento running in a production environment is not stable, switch it to a stable version. Otherwise, Magento will not be able to upgrade.

      cd magento2 && git checkout tags/2.1.0 -b 2.1.0

      Information similar to the following is displayed:

      Switched to a new branch '2.1.0'
    4. Move the installation files to the root directory of the web server.

      After the files are moved, enter http://IP address of the Magento server in the address bar to visit the Magento website. If the files are not moved, enter http://IP address of the Magento server/magento2 in the address bar to visit the Magento website.

      shopt -s dotglob nullglob && mv /var/www/html/magento2/* /var/www/html/ && cd ..

    5. Run the following commands to assign permissions to the Magento files:

      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

    6. Run the following command to install Magento:

      composer install

    7. Enter http://IP address of the Magento server in the address bar to visit Magento. If the following page is displayed, Magento has been installed.

  6. Configure Magento.

    1. Click Agree and Setup Magento and configure Magento.
    2. Click Start Readiness Check to check the environment. After the environment is ready, click Next.
    3. Specify parameters, such as the database name and the root account for logging in to the MySQL database, and click Next.

      The following figure shows an example.

    4. Set the website URL and server management address. Then, click Next.

      The following figure shows an example.

      Securely keep the server management address.

    5. Set the language and time zone. Then, click Next.

      The following figure shows an example.

    6. Set the management account. Then, click Next.

      The following figure shows an example.

    7. Click Install Now.

      If the following page is displayed, Magento has been installed.

  7. Set cron to run scheduled jobs.

    1. Run the following command to configure a cron job:

      crontab -u apache -e

    2. Press i to enter editing mode.
    3. Add the following data to the file:

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

    4. Press Esc to exit the editing mode. Then, enter :wq to save the settings and exit the configuration file.

      For more information about how to run cron jobs on Magento, see official Magento documents.

  8. Test the Magento website.

    1. In the address bar of the computer with client installed, enter http://IP address of the Magento server. The default page shown in the following figure is displayed.

    2. Visit http://IP address of the Magento server/admin and use the configured management account to log in to Magento. The following figure is displayed after a successful login.

      NOTE:

      After the login, if the system displays error message "One or more indexers are invalid. Make sure your Magento cron job is running", run the php bin/magento indexer:reindex command in Magento root directory /var/www/html.

      For more information about Magento configurations, see official Magento documents.

  9. Purchase a domain name.

    To facilitate website access and use, configure a unique domain name for the website. You are required to obtain an authorized domain name from the domain name registrar for the website.

  10. Enable domain name resolution.

    Your website can be visited using the registered domain name only after domain name resolution is enabled. For details, see section Configuring a Public Zone.

    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.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel