Install Craft CMS on a LEMP Stack on Alibaba Cloud

Step 1. Install Nginx

$ ssh root@your_instance_ip
# apt-get update
# apt-get install nginx

Step 2. Install and Secure MariaDB

# apt-get install mariadb-server
# systemctl enable mysql
# systemctl status mysql
# mysql_secure_installation

Step 3. Install PHP7

# apt-get install php-fpm php-mysql
# apt-get install php7.0-curl php7.0-mbstring php7.0-mcrypt php-imagick php7.0-xml

Step 4. Install other dependencies

# apt-get install composer git

Step 5. Create a Root Directory

# mkdir /var/www/
# cd /var/www/

Step 6. Download and Prepare the CraftCMS files

# wget -O --no-check-certificate
# apt-get install unzip
# unzip
# ls
# rm
# ls -l
# chown -R www-data:www-data /var/www/
# ls -l

Step 7. Configure Domain & DNS

Step 8. Create Nginx Virtual Host files

# nano /etc/nginx/sites-available/
server {
listen 80;
listen [::]:80;
root /var/www/;
index index.php index.html index.htm;
server_name; location / {
try_files $uri $uri/ @rewrites;
location @rewrites {
rewrite ^(.*) /index.php?p=$1 last;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
expires off;
error_page 404 /index.php;
client_max_body_size 300M;
# ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
# cd /etc/nginx/sites-enabled && ls
# nginx -t
# service nginx restart

Step 9. Add a Let’s Encrypt SSL certificate

# apt-get install -y software-properties-common
# add-apt-repository ppa:certbot/certbot
# apt-get update
# apt-get install python-certbot-nginx

Make sure port 443 is open

Obtain a Let’s Encrypt SSL Certificate

# certbot --nginx -d -d
sudo certbot --authenticator standalone --installer nginx -d -d --pre-hook "service nginx stop" --post-hook "service nginx start"

Step 10. Create a Database

# mysql -u root -p
GRANT ALL ON craft.* TO 'new_user'@'localhost' IDENTIFIED BY 'new_users-password';
# nano /var/www/
return array(    // The database server name or IP address. Usually this is 'localhost' or ''.
'server' => 'localhost',
// The name of the database to select.
'database' => 'craft',
// The database username to connect with.
'user' => 'new_user',
// The database password to connect with.
'password' => 'new_users_password',
// The prefix to use when naming tables. This can be no more than 5 characters.
'tablePrefix' => 'craft',

Step 12. Install and Configure CraftCMS



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store