All Products
Search
Document Center

Elastic Compute Service:Build a Drupal website on an ECS instance that runs Alibaba Cloud Linux 2, Alibaba Cloud Linux 3, CentOS 7.x, or CentOS 8.x

Last Updated:Feb 26, 2025

Drupal is an open source content management framework (CMF) written in PHP. Drupal consists of a content management system (CMS) and a PHP development framework. You can use Drupal to build dynamic websites that provide various features and services. Drupal is commonly used in a variety of applications from personal blogs to large communities. This topic describes how to use Drupal to build an e-commerce website on an Elastic Compute Service (ECS) instance that runs Alibaba Cloud Linux 2, Alibaba Cloud Linux 3, CentOS 7.x, or CentOS 8.x.

Preparations

  1. Create an ECS instance on which you want to build a Drupal website. For information about how to create an ECS instance, see Create an instance on the Custom Launch tab.

    The ECS instance meets the following requirements:

    • The ECS instance runs Alibaba Cloud Linux 2, Alibaba Cloud Linux 3, CentOS 7.x, or CentOS 8.x.

    • The ECS instance is assigned a static public IP address (also called system-assigned or auto-assigned public IP address) or associated with an elastic IP address (EIP). For information about how to associate an EIP with an ECS instance, see the Associate one or more EIPs with an instance section of the "EIPs" topic.

    • Ports 22 and 80 are open in the inbound rules of a security group associated with the ECS instance. For information about how to add a security group rule, see Add a security group rule.

  2. Build a Linux, Apache, MySQL, and PHP (LAMP) stack.

    Important

    The Drupal version has a minimum PHP version requirement. If the PHP version does not meet the requirement, Drupal cannot be installed. For more information, see Drupal documentation. In the following example, Drupal 11.1.0 and PHP 8.4 or PHP 8.3 are installed.

    For information about how to build a LAMP stack, see Manually deploy a LAMP stack.

Procedure

  1. Connect to the ECS instance on which a LAMP stack is built.

    For more information, see Use Workbench to connect to a Linux instance over SSH.

  2. Install the required tools and related dependencies.

    # Install Composer and grant the execute permissions to Composer.
    sudo php -r "copy('https://mirrors.aliyun.com/composer/composer.phar', '/usr/local/bin/composer');"
    sudo chmod +x /usr/local/bin/composer
    # Install PHP and related extensions.
    sudo yum install -y php-gd php-pdo php-opcache php-xml php-dom php-simplexml php-zip unzip
    # Restart Apache for the extensions to take effect.
    sudo systemctl restart httpd
    # Install Git.
    sudo yum install -y git
  3. Download Drupal.

    Go to the default directory of the Apache website and use Composer to download Drupal core software. This operation creates a directory named my_site in the current directory. You can specify a Drupal version, such as 11.1.0, to download the specific version of the Drupal package.

    Important

    If your server resides in the Chinese mainland, run the following command to specify an Alibaba Cloud image repository to accelerate the download. Otherwise, skip this operation.

    sudo /usr/local/bin/composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
    # Access the default directory of the Apache website.
    cd /var/www/html
    # Download Drupal core software by using Composer.
    sudo /usr/local/bin/composer create-project drupal/recommended-project:11.1.0 "my_site"
  4. Configure Drupal.

    1. Download the Chinese language package and grant the write permissions on the directories and files required to install Drupal.

      Note
      • If you want to download another version of Drupal, replace the version number with the actual version number in the following command. For example, if you want to download the Chinese language package of Drupal 10.3.0, run the sudo wget -P sites/default/files/translations https://ftp-origin.drupal.org/files/translations/all/drupal/drupal-10.3.0-beta1.zh-hans.po command.

      • If you install Drupal and select the English language package, you do not need to download the Chinese language package.

      # Go to the my_site/web directory.
      cd /var/www/html/my_site/web
      # Create related directories.
      sudo mkdir -p sites/default/files/translations
      # Download the Chinese translation package. If you want to choose the installation language as English when you install Drupal, you do not need to download the Chinese translation package.
      sudo wget -P sites/default/files/translations https://ftp-origin.drupal.org/files/translations/all/drupal/drupal-11.1.0-beta1.zh-hans.po
      # Grant the write permissions on the sites/default/files directory.
      sudo chmod a+w sites/default/files
      # Create the sites/default/settings.php configuration file for Drupal installation and grant the write permissions on the configuration file.
      sudo cp sites/default/default.settings.php sites/default/settings.php
      sudo chmod a+w sites/default/settings.php
    2. Enable clean URLs for Apache.

      1. Open the Apache configuration file.

        sudo vim /etc/httpd/conf/httpd.conf
      2. Press the I key to enter Insert mode and add the following content to the configuration file:

        <Directory "/var/www/html/my_site/web">
            AllowOverride All
            Require all granted
        </Directory>

        Press the Esc key, enter :wq, and then press the Enter key to save and close the file.

      3. Restart Apache.

        sudo systemctl restart httpd
  5. Install Drupal.

    1. Open a web browser on your on-premises device and enter http://<Public IP address of the ECS instance>/my_site/web in the address bar to go to the Drupal installation page.

    2. Select a language that you want to use from the Choose language drop-down list and click Save and continue.

      image

    3. Select Standard and click Save and continue.

      image

    4. The system automatically checks whether the current environment meets the installation requirements.

      • If the environment meets the installation requirements, you are automatically redirected to the next step.

      • If the environment does not meet the installation requirements, a warning message appears. You can resolve the issue based on the warning content. After you resolve the issue, click retry in the lower part of the page to recheck the environment.

        For example, if the following warning message appears, you can run the yum install -y php-mbstring command to install the extension based on the warning content. After the extension is installed, run the sudo systemctl restart httpd command to allow the extension to take effect.

        image

    5. Configure the parameters of a database file and click Save and continue.

      image

    6. After Drupal is installed, enter the site information on the Configure site page and click Save and continue.

      image

      image

  6. After the installation is complete, go to the Drupal website and configure custom settings for the website based on your business requirements.

    后续操作

    Important

    After the installation is complete, we recommend that you run the following commands to remove the write permissions from the sites/default and sites/default/files directories and the sites/default/settings.php file to prevent security risks:

    sudo chmod a-w /var/www/html/sites/default
    sudo chmod a-w /var/www/html/sites/default/files
    sudo chmod a-w /var/www/html/sites/default/settings.php

FAQ

What do I do if I cannot access a Drupal website?

  1. Check whether PHP FastCGI Process Manager (PHP-FPM) and MySQL are started.

    1. Run the following command to query the status of PHP-FPM:

      sudo systemctl status php-fpm
      • If the status is Running, PHP-FPM is started. Proceed to the next step.

      • If the status is not Running, PHP-FPM is not started. Run the following command to start PHP-FPM:

        sudo systemctl start php-fpm
    2. Run the following command to query the status of MySQL:

      sudo systemctl status mysqld
      • If the status is Running, MySQL is started. Proceed to the next step.

      • If the status is not Running, MySQL is not started. Run the following command to start MySQL:

        sudo systemctl start mysqld
  2. Check whether the Drupal version and the PHP version match.

    The Drupal version has a minimum PHP version requirement. If the PHP version does not meet the requirement, Drupal cannot be installed. For more information, see Drupal documentation.

    If the PHP version that you installed is incompatible with the Drupal version, uninstall the PHP version and then install a matching PHP version.