Build a Magento e-commerce website with an Alibaba Cloud Marketplace image

Updated at:

Deploy a Magento e-commerce website on a Linux ECS instance with a pre-configured Alibaba Cloud Marketplace image.

Background

The Alibaba Cloud Marketplace image Magento on LAMP CentOS7.2 64bits powered by IGS 1.0 integrates Apache 2.4, PHP 7.0, MySQL 5.6, Magento 2.1.1, and phpMyAdmin. See Magento on LAMP CentOS7.2 64bits powered by IGS.

The default site root directory of the Magento e-commerce website is /yjdata/www/wwwroot. The software installation paths are listed below. See Magento official documentation.

Software

Path

Apache 2.4.6

/etc/httpd

PHP 7.0

/usr/local/php

MySQL 5.6

/var/lib/mysql

Magento2.1.1

/yjdata/www/wwwroot

You can also build a Magento2 e-commerce website on an Ubuntu instance manually.

Step 1: Build a Magento e-commerce website

Create an ECS instance with the Magento on LAMP CentOS7.2 64bits powered by IGS 1.0 Marketplace image.

  1. Go to the Magento on LAMP CentOS7.2 64bits powered by IGS image details page.

  2. Click Purchase Now.

  3. On the Custom Launch tab in the ECS console, configure the parameters.

    Note the following parameters. For other parameters, see Create an instance with Custom Launch.

    • Image: The selected Marketplace image is automatically displayed in the Image section.

    • Public IP Address: Select Assign Public IPv4 Address.

    • Security Group: Specify a security group that allows traffic on ports 22, 80, 443, and 3306.

Step 2: Configure a Magento client

  1. Obtain the database username, password, and name.

    1. Connect to the Magento server.

    2. Obtain the database username, password, and name:

      cat default.pass

      Sample output:

      [root@iZbp1h2mquu8nb0jz99**** ~]# cat default.pass
      +----------------------------------------------------------------------
      | YJCOM [ EASY CLOUD EASY WEBSITE]
      +----------------------------------------------------------------------
      | Copyright (c) 2016 http://yjcom.com All rights reserved.
      +----------------------------------------------------------------------
      
      MySQL database name: magento
      MySQL user: root
      MySQL password: KMmnUTeg****
      FTP account: www
      FTP password: 3hrfJuu4****
  2. Enter http://<Public IP address of the ECS instance> in your browser.

    The following page indicates that Magento is installed.

    The Magento installation wizard welcome page (Version 2.1.1) appears. Read the welcome information and click Agree and Setup Magento to begin configuration.

  3. Click Agree and Setup Magento to start configuring Magento.

    1. Click Start Readiness Check to begin the environment check.

    2. After the check completes, click Next.

    3. Enter the database username, password, and name, and click Next.

      For the database credentials, see the Obtain the username, password, and name of the database step. Parameters:

      • Database Server Host: Enter 127.0.0.1.

      • Database Server Username: Default value: root.

      • Database Server Password: The database password.

      • Database Name: Default value: magento.

    4. Set Your Store Address to the public IP address of the ECS instance, specify a Magento Admin Address, and click Next.

      Set Your Store Address to the public IP address of the ECS instance.

      Note

      Record the custom Magento Admin Address for later use.

    5. Configure the store default settings and click Next:

      • Store Default Time Zone: Set to GMT (UTC)

      • Store Default Currency: Set to Chinese Yuan (CNY)

      • Store Default Language: Set to Chinese (China)

    6. Enter the administrator account information and click Next. Required fields include:

      • New Username: Administrator username, set to admin in this example

      • New Email: Administrator email address

      • New Password: Administrator password

      • Confirm Password: Confirm the password

    7. Click Install Now to install Magento.

      After installation completes, the page displays a Success message with the following key information:

      • Magento Admin Info: Username is admin, along with Email, Password, Store Address, and Magento Admin Address

      • A yellow notice reminds you to bookmark the unique admin URL and record it offline

      • Encryption Key: Save the encryption key securely

      • Database Info: Database Name is magento, Username is root

      • Security notice: Remove write permissions from the /yjdata/www/wwwroot/app/etc directory

      Click Launch Magento Admin to access the admin panel.

Step 3: Add a cron job

Magento relies on cron jobs for features such as reindexing, email generation, newsletter distribution, and sitemap creation.

  1. Connect to the Magento server.

  2. Configure a cron job:

    crontab -u apache -e
  3. Press the I key to enter Insert mode and add the following content 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 the Esc key, enter :wq, and then press the Enter key to save and close the file.

  5. Enter http://<Public IP address of the ECS instance> in your browser. The Magento LUMA theme default homepage appears with the title Home Page and placeholder text CMS homepage content goes here., indicating that Magento is successfully installed.

  6. Enter http://<Public IP address of the ECS instance>/admin in your browser. Log on with the admin credentials you configured. After successful login, the Magento 2 admin Dashboard page appears. The left navigation contains DASHBOARD, SALES, PRODUCTS, CUSTOMERS, and other menu items. The main content area shows Lifetime Sales and Average Order statistics (initial zero values are normal). The footer displays Magento ver. 2.1.1, confirming successful deployment.

    Note

    If the "One or more indexers are invalid. Make sure your Magento Cron job is running." error appears after you log on, see the FAQ section.

See Official Magento documentation for cron job usage.

(Optional) Step 4: Bind a domain name and configure resolution settings for the domain name

Bind a domain name to your ECS instance so users can access the website by domain name.

  1. Register a domain name.

    See Register a domain name on Alibaba Cloud. Skip this step if you already have a domain name.

    Sample domain name: example.com.

  2. If the website is hosted on an ECS instance in a region inside the Chinese mainland, apply for an ICP filing for the domain name.

    For a first-time filing, see ICP Filing for the first time. For other scenarios, see ICP filing process.

  3. (Optional) Map the domain name to the public IP address of the ECS instance.

    • If your domain name is registered with Alibaba Cloud, skip this step. The system automatically resolves the domain name after binding.

    • If your domain name is not registered with Alibaba Cloud or resolved by Alibaba Cloud DNS, add it in the Alibaba Cloud DNS console. See Manage domain names. You can also contact your domain name service provider, create an A record pointing to the Magento server IP address, and bind the domain name.

FAQ

If the "One or more indexers are invalid. Make sure your Magento cron job is running." error appears when you access http://<Public IP address of the ECS instance>/admin, follow these steps. The Magento admin panel displays a warning in the System messages panel: One or more indexers are invalid. Make sure your Magento cron job is running.

  1. Connect to the Magento server.

    See Log on to a Linux instance using Workbench.

  2. Create a symbolic link from the PHP installation path to /usr/sbin/php:

    ln -s /usr/local/php/bin/php /usr/sbin/php
  3. Perform reindexing:

    cd /yjdata/www/wwwroot
    php bin/magento indexer:reindex

    Output similar to the following indicates that reindexing is complete.

    Design Config Grid index has been rebuilt successfully in 00:00:00
    Customer Grid index has been rebuilt successfully in 00:00:00
    Category Products index has been rebuilt successfully in 00:00:00
    Product Categories index has been rebuilt successfully in 00:00:00
    Product Price index has been rebuilt successfully in 00:00:00
    Product EAV index has been rebuilt successfully in 00:00:00
    Stock index has been rebuilt successfully in 00:00:00
    Catalog Rule Product index has been rebuilt successfully in 00:00:00
    Catalog Product Rule index has been rebuilt successfully in 00:00:00
    Catalog Search index has been rebuilt successfully in 00:00:00
  4. Refresh the page. A cache invalidation warning appears at the top of the page indicating that the Page Cache is invalidated. Click the Cache Management link in the warning to go to the cache management page.

  5. On the Cache Management page, select the Page Cache with status INVALIDATED, choose Refresh from the action dropdown, and click Submit to refresh the cache.

    The page displays a success message 1 cache type(s) refreshed., indicating the cache was refreshed successfully.