My Best Practices for Deploying a Web Application on Alibaba Cloud
Original Source: https://www.sitepoint.com/my-best-practices-for-deploying-a-web-application-on-alibaba-cloud/
This article was originally published on Alibaba Cloud. Thank you for supporting the partners who make SitePoint possible.
In this article, I want to share the best practices I use when deploying a web application to Alibaba Cloud. I work as a freelancer and recently one of my clients asked me to setup SuiteCRM for his small organization. Since I frequently write tutorials for Alibaba Cloud, I recommended that the client use the same cloud platform. For nearly 100 users and at least 30 concurrent users, here's the configuration I recommended.
ECS instance of 2 vCPUs and 4GB RAM to install Nginx with PHP-FPM.
ApsaraDB for RDS instance for MySQL with 1GB core, 1 GB RAM, and 10 GB storage.
Direct Mail for sending emails.
The steps I followed are very simple and can be adopted for nearly all PHP based applications.
If you are new to Alibaba Cloud, you can use this link to sign up to Alibaba Cloud. You will get new user credit worth US$300 for free, which you can use to try out different Alibaba Cloud products.
Creating an ECS Instance
Alibaba Cloud has documented nearly everything you will require to get started with the cloud platform. You can use the Getting Started Tutorials or the Tech Share Blog to learn how to start using Alibaba Cloud. You can find the most obvious steps in the Quick Start Guide and let me walk you through the best practices to use when creating the ECS instance.
Log in to your Alibaba Cloud console and go to Elastic Compute Service interface. You can easily create the instance by clicking the Create Instance button. Things to keep in mind are:
Region: Since Alibaba Cloud has data centers all around the globe, always choose the region which is geographically closer to the users of the application. As the data center is closer to the user, the website will load very fast due to the low latency of the network. In my case, I chose Mumbai region, as the organization was based in Mumbai itself.
Billing Method: If you are planning to continuously run the instance 24/7, you should always choose the monthly subscription as it will cut down the price to less than half compared to Pay-As-You-Go. For example, the monthly subscription cost of a shared type ECS instance of 2 vCPUs and 4GB RAM is $23 USD but the same instance in Pay-As-You-Go costs $0.103 USD per Hour. Monthly cost becomes $0.103*24*30 = $74.16 USD.
Instance Type: Choose the instance type according to your requirements. Resources can be increased later on demand.
Image: You may find the application you wish to install on your ECS instance on a Marketplace image but it is always recommended to install it yourself in a clean official image. Later, if your application encounters some error, you will know where to look.
Storage: System disks are deleted when the ECS instance is released. Use data disk when possible as your disk will be retained even after the instance is accidentally deleted.
Here's the configuration I used.
You can choose the VPC which is created by default. You can add as many as 4092 instances in it. I use a different security group for each ECS instance so that I can configure individually and make sure that no unused port is opened.
Another important thing is to use key-based authentication rather than using passwords. If you already have a key-pair, you can add the public key to Alibaba Cloud. If not, you can use Alibaba Cloud to create one. Make sure that key is stored in a very secure place, and the key itself is encrypted by a passphrase.
That's all the things to keep in mind while creating the ECS instance.
Setting Up the ECS Instance
Once you have created your instance and logged into the terminal, there are few things I suggest you should consider before you set up your website.
Rather than using the root account for executing the commands, set up a sudo user on the first connection and always use the sudo user for running the commands. You can also set key based authentication for the sudo user, and disable root login entirely.
Always keep your base image updated.
Alibaba base images do not have any extra package which is not required. Do not install any package that’s not required.
If things go bad during installation, you can always reset the instance by changing the system disk. You don't need to delete the instance and recreate it.
I created the sudo user and configured key based auth in it. I updated the base image and set up unattended system upgrades. I followed a tutorial to install Nginx web server, which is a lightweight production-grade web server. Further, I installed PHP 7.2 with PHP-FPM. PHP 7.2 is the latest available version of PHP as of now. Using the latest software will ensure that the system is free from all the bugs and we will also get a faster processing and more stability. Finally, I downloaded the SuiteCRM archive from its official website and deployed the files into Nginx.
You can use the getting started tutorials or the tutorials written by Tech Share authors to install the applications.
Configuring Security Group Rules
It is very important to leave no unused port open in the security group of the ECS instance. Have a look at the security group rules I used for the SuiteCRM instance.
You can see that I have allowed only the ports 22, 80 and 443 along with all ICMP packets. Port 22 is used for SSH connection. Port 80 is the unsecured HTTP port, which in my case just redirects to the port 443 on HTTPS. ICMP packets are used to ping the host to check if it is alive or not. It's perfectly okay if you want to drop the ICMP packets as well — you just won't be able to ping your instance.
Creating the RDS Instance
The first question to ask before we create the RDS instance is why exactly we need it. We could install any open source database server such as MySQL, MariaDB, PostgreSQL or MongoDB server on the ECS instance itself.
The answer to the question is that ApsaraDB for RDS is optimized for speed and security. By default, the instance we create is only accessible to the whitelisted instances only.
Let's look at the things to keep in mind when we create the ECS instance.
Region: Always choose the same region for the database instance and the ECS instance. Also, make sure that they both are in the same VPC. This will enable you to leverage the free intranet data transfer between the hosts in the same network. Another advantage is that you will need to whitelist only the private IP address of the ECS instance. This increases the security of the database to a great extent.
Billing: Again, the cost of monthly subscription is less than that of the Pay-As-You-Go method. Choose according to your needs.
Capacity: You can start with a low-end configuration such as 1 Core, 1 GB instance, and 5 GB storage. Later on you can increase resources.
Accounts: Never create the Master account for the MySQL 5.6 instance unless required. You can create a database and a database user for each database.
Here's the RDS configuration I used for SuiteCRM.
The post My Best Practices for Deploying a Web Application on Alibaba Cloud appeared first on SitePoint.
Leave a Reply
Want to join the discussion?Feel free to contribute!