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/example.com
# cd /var/www/example.com

Step 6. Download and Prepare the CraftCMS files

# wget -O craft.zip https://buildwithcraft.com/latest.zip?accept_license=yes --no-check-certificate
# apt-get install unzip
# unzip craft.zip
# ls
# rm craft.zip
# ls -l
# chown -R www-data:www-data /var/www/example.com
# ls -l

Step 7. Configure Domain & DNS

Step 8. Create Nginx Virtual Host files

# nano /etc/nginx/sites-available/example.com
server {
listen 80;
listen [::]:80;
root /var/www/example.com/current/public;
index index.php index.html index.htm;
server_name example.com www.example.com; 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/example.com /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 example.com -d www.domain.com
sudo certbot --authenticator standalone --installer nginx -d example.com -d www.example.com --pre-hook "service nginx stop" --post-hook "service nginx start"

Step 10. Create a Database

# mysql -u root -p
CREATE DATABASE craft  DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON craft.* TO 'new_user'@'localhost' IDENTIFIED BY 'new_users-password';
FLUSH PRIVILEGES;
EXIT;
# nano /var/www/example.com/craft/config/db.php
return array(    // The database server name or IP address. Usually this is 'localhost' or '127.0.0.1'.
'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

https://example.com

--

--

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