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
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.
Build a Linux, Apache, MySQL, and PHP (LAMP) stack.
ImportantThe 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
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.
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
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 as11.1.0
, to download the specific version of the Drupal package.ImportantIf 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"
Configure Drupal.
Download the Chinese language package and grant the write permissions on the directories and files required to install Drupal.
NoteIf 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
Enable clean URLs for Apache.
Open the Apache configuration file.
sudo vim /etc/httpd/conf/httpd.conf
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 theEnter
key to save and close the file.Restart Apache.
sudo systemctl restart httpd
Install Drupal.
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.Select a language that you want to use from the Choose language drop-down list and click Save and continue.
Select Standard and click Save and continue.
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 thesudo systemctl restart httpd
command to allow the extension to take effect.
Configure the parameters of a database file and click Save and continue.
After Drupal is installed, enter the site information on the Configure site page and click Save and continue.
After the installation is complete, go to the Drupal website and configure custom settings for the website based on your business requirements.
ImportantAfter the installation is complete, we recommend that you run the following commands to remove the write permissions from the
sites/default
andsites/default/files
directories and thesites/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