How to Install Craft CMS with a LEMP Stack

Alibaba Cloud
4 min readMay 30, 2019

There are many PHP based Content Management Systems (CMS) that you can run on an Alibaba Cloud ECS Instance with a LEMP stack. Of these, Craft CMS is probably one of the slickest.

As Craft is built using the Yii high performance PHP framework, and adheres to modern PHP standards, it is also a very scalable and stable platform.


  1. Nginx installed
  2. MariaDB installed and secured

Install PHP7

The final part of the LEMP stack we need to run Craft CMS is PHP. Although Craft will run on PHP5.3 and upwards, it is not advisable to use old and unsupported versions. PHP7 is much more secure and provides incredibly superior performance.

As Nginx doesn’t natively process dynamic content, such as PHP scripts, we will need to install PHP-FPM. This will install all the core PHP packages we need to run with an NGINX server. Let’s also install the PHP extension for MySQL at the same time:

# apt-get install php-fpm php-mysql

Craft CMS requires a few other PHP packages that aren’t included in PHP-FPM, so we need to install them separately:

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

You will need to enter yes to continue when prompted:

And since CraftCMS is a modern PHP application, as such its workflow uses both ‘git’ and the ‘composer’ php package manager during development.

Install these next:

# apt-get install composer git

We will need a root directory for the CraftCMS files and sub-directories. We will create this in the ‘/var/www/’ directory:

# mkdir /var/www/

Change directory to your newly created route directory:

# cd /var/www/

Download and Prepare the CraftCMS files

Now download the latest zip archive containing the CraftCMS files:

# wget -O --no-check-certificate

We will need to unzip the archive, but first we need to install a package to do that:

# apt-get install unzip

We can now unzip the archive:

# unzip

When you unzip the archive it will create two directories within your root directory, ‘craft’ and ‘public’, you can see them if you list out the directory:

# ls

Craft has a very modern directory structure, its public directory only includes the ‘index.php’ file required to run the application, this is the file our Nginx virtual host points to in order to serve the site. All of the nuts and bolts of the CraftCMS are run securely from a directory one level above the index.php file.

When you listed out the root directory contents, you will see that the ‘’ archive is still there, we need to delete it:

# rm

We also need to check ownerships of our directories:

# ls -l

Make the server user ‘www-data’ the owner of both directories, then recheck:

# chown -R www-data:www-data /var/www/
# ls -l

You should now be able to confirm that ‘www-data’ user and group owns both directories. After you have set the files successfully, you can configure domain and DNS, and then create Nginx virtual host files, add a Let’s Encrypt SSL certificate, create a Database and finalize the installation and configuration of CraftCMS. For details, you can go to Install Craft CMS on a LEMP Stack on Alibaba Cloud.

Related Blog Posts

How to Install Redis Object Caching on WordPress

Caching allows us to store data in RAM so that any future request for that data can be served faster, without any needing to query the database or process any PHP. In this tutorial, we will install a Redis server as an object cache for DB queries, and configure WordPress to use it.

How to Install LibreNMS on Ubuntu 16.04

LibreNMS is a free and open source auto-discovering network monitoring tool for servers and network hardware. It supports wide range of network hardware and operating systems including Cisco, Linux, Juniper, Foundry, Windows, Brocade and many more.

LibreNMS runs on the web server, written in PHP and uses MariaDB for database. So you will need to install Apache, PHP and MariaDB to your system.

Related Market Products

LEMP on Ubuntu 14.04 64bits powered by IGS

Ubuntu 14.04 integrated with the lightweight yet powerful Nginx web server. We, IGS, provide a list of images pre-integrated with most popular software for web solution. It includes ready-to-run versions of Apache/Nginx, MySQL, PHP, phpMyAdmin and all of the other software required to run each of those components. IGS image greatly simplifies the development and deployment of web applications.

Related Documentation

Unable to access the websites running on ECS Instances

If any error occurs while you access your website, we recommend searching for the error code and view the description first. A list of error codes is provided, at the end of this document.

Related Products

Elastic Compute Service

Alibaba Cloud Elastic Compute Service (ECS) provides fast memory and the latest Intel CPUs to help you to power your cloud applications and achieve faster results with low latency. All ECS instances come with Anti-DDoS protection to safeguard your data and applications from DDoS and Trojan attacks.

ApsaraDB RDS for MySQL

MySQL is one of the most popular open-source databases in the world. As a key component of the open-source software bundle LAMP (Linux, Apache, MySQL, and Perl/PHP/Python), MySQL has been widely applied to different scenarios.

Related Course

Mysql Database Concepts and Operations

After learning this MySQL series courses, the trainees will master the MySQL relevant basic concept, deployment procedure, HA solution, commonly used backup and recovery method and daily inspection skills, thus having a comprehensive understanding of MySQL database.




Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website: