- Magento 2 Beginners Guide
- Gabriel Guarino
- 1275字
- 2021-07-09 19:21:29
Installing Magento in Amazon EC2
In this section, we will set up a server in Amazon from scratch. The server will be ready for Magento with all the requirements and dependencies installed, so you can manage your first Magento development server.
Setting up the Amazon AWS account
The first step is setting up your Amazon AWS account to create the server instance in Amazon EC2.
In order to do this, you should follow these steps:
- Go to the Amazon AWS homepage at https://aws.amazon.com/. It will look something like this:
- Click on Create an AWS Account.
- Add your e-mail or phone number and select I am a new user.:
- Click on Sign in using our secure server.
- Complete the form with your personal information and click on Create account:
Creating the Amazon EC2 instance
After verifying the Amazon AWS account, you can create your first Amazon EC2 instance. Instances are virtual servers that can run web applications. Let's go through the steps to create the Amazon EC2 instance:
- Go to the Amazon EC2 landing page, that is, https://aws.amazon.com/ec2/, which will look something like this:
- Click on My Account in the top-right of the screen, then click on AWS Management Console and, finally, sign in using your Amazon account.
- On the AWS Management Console, search for
ec2
in the AWS services search box: - You will be redirected to the EC2 dashboard. This will be the place to control and monitor your Amazon instances. Next, you click on Launch Instance in the middle of the page:
Choose an Instance Type: On this page, you can see the different instance types that you can choose depending on the size of the Magento store. For now, we will choose the t2.micro Free tier eligible instance type:
- Instance Setup Wizard:
- Choose an Amazon Machine Image (AMI): In this step, you can choose the software configuration for the Amazon instance. For this guide, we will choose Ubuntu Server:
- Choose an Instance Type: On this page, you can see the different instance types that you can choose depending on the size of the Magento store. For now, we will choose the t2.micro Free tier eligible instance type:
- Configure Instance: You can set advanced options for your instance in this step. We will keep the configuration by default in this step to proceed to step 4 of the Setup Wizard.
- Add Storage: In this step, you can specify the storage for your instance. Since the size of the Magento 2 code base with sample data is 530 MB, we will keep the default size for the volume (8 GB).
- Add Tags: This step is helpful when you have multiple Amazon instances since you can add tags to categorize the resources in your Amazon account.
- Configure Security Group: The security group is a set of rules that controls the traffic of the Amazon instance. The default rule port is SSH, which allows the user to access the instance from the terminal. In order to allow Internet traffic for the Magento store, you should enable the HTTP and HTTPS ports. You can add these ports by clicking on Add Rule and then selecting HTTP and HTTPS from the Custom TCP Rule dropdown.
- Review: In this step, you can review the configuration for your Amazon instance. Click on Launch at the bottom-right of the screen:
- Choose an Amazon Machine Image (AMI): In this step, you can choose the software configuration for the Amazon instance. For this guide, we will choose Ubuntu Server:
This is a really important part of the process. You can access the Amazon instance by using a private key file.
The only way to access the new instance is using the key pair, which is a combination of the public key that AWS stores and your private key file.
Choose Create a new key pair and then set the key pair name and click on Download Key Pair. Never lose the private key file since that is the master key to access your Amazon instance.
Finally, click on Launch Instance to finish the Setup Wizard.
Preparing the Amazon instance for Magento 2
Now that you created the Amazon instance, we are ready to install all the packages and dependencies to prepare the instance for Magento 2.
The first step is to log in to the server using the private key file that you downloaded from the Setup Wizard.
To log in, you need to know the public DNS or the public IP for the instance. You can get those values from the AWS EC2 Management Console:
- Go to the
https://console.aws.amazon.com/ec2/
AWS EC2 Management Console. - You will see the instance that we just created in the list. Scroll to the right in the table to find the Public DNS and the Public IP for the instance:
- Before logging in to the server, we should give the right permissions to the private key file. Locate the file in the Terminal and run the following command:
chmod 400 ~/Key Pairs/sample.pem
Now we are ready to log in to the AWS instance using the following command:
ssh -i ~/sample.pem ubuntu@107.20.106.201
We can alternatively use this command:
ssh -i ~/sample.pem ubuntu@ec2-107-20-106-201.compute-1.amazonaws.com
Once you log in to the development server, you should get sudo
privileges to proceed with the installation of all the dependencies without problems:
sudo su
Now, it is time to set up all the dependencies for Magento 2:
- Update all the existing packages in the server:
apt-get update
- We will install Apache, PHP, and the required PHP modules and composer using the following commands:
apt-get install sudo apt-get install apache2 sudo apt-get install php7.0 sudo apt-get install libapache2-mod-php sudo apt-get install php7.0-simplexml sudo apt-get install php7.0-curl sudo apt-get install php7.0-intl sudo apt-get install php7.0-xsl sudo apt-get install php7.0-zip sudo apt-get install php7.0-xml sudo apt-get install php7.0-curl sudo apt-get install php7.0-gd sudo apt-get install php7.0-mcrypt sudo apt-get install php7.0-dom sudo apt-get install php7.0-mbstring sudo apt-get install composer
Tip
You can run the installation for all the dependencies in one command, like this:
sudo apt-get install apache2 php7.0 libapache2-mod-php php7.0-dom php7.0-simplexml php7.0-curl php7.0-intl php7.0-xsl php-mbstring php7.0-zip php7.0-xml php7.0-curl php7.0-gd php7.0-mcrypt php7.0-dom php7.0-mbstring composer
- Next, we will install MySQL. Note that the installer will ask you to set the password for the root user:
sudo apt-get install mysql-server sudo apt-get install php-mysql
- Secure the MySQL installation. To do this, run the following command:
mysql_secure_installation
It will ask for the MySQL password you configured previously:
- Remove anonymous users: Yes
- Disallow login remotely: Yes
- Remove test database and access to it: Yes
- Reload privilege tables now?: Yes
- Open the
apache2.conf
file and setAllowOverride all
to grant the right permissions to the document root. - Find the following block of code:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride none Require all granted </Directory>
Replace it with the following code:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride all Require all granted </Directory>
- Restart the Apache server to apply the changes:
sudo service apache2 restart
- Create a sample
phpinfo.php
file in the document root:cd /var/www/html rm index.html echo "<?php echo phpinfo();" > phpinfo.php
- Then, you can access the document root and see the output for the
phpinfo.php
file in the browser. For example,<Public IP>/phpinfo.php
.You should see the following page in the browser:
- If
phpinfo.php
is displayed properly, remove thephpinfo.php
file and create a custom MySQL user and database to import Magento (create the same username as the old server):mysql -u root -p CREATE USER '<username>'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO '<username>'@'localhost'; FLUSH PRIVILEGES; CREATE DATABASE <databasename>;
The Amazon instance is now ready for Magento 2 and you can proceed with the Setup Wizard or the command-line installation method that we saw in the previous section.
- Implementing Modern DevOps
- Java范例大全
- Visual FoxPro程序設計教程(第3版)
- C# 從入門到項目實踐(超值版)
- Unity 5.x By Example
- Python完全自學教程
- jQuery炫酷應用實例集錦
- Hands-On Kubernetes on Windows
- Swift語言實戰晉級
- Deep Learning for Natural Language Processing
- Puppet 5 Beginner's Guide(Third Edition)
- CryENGINE Game Programming with C++,C#,and Lua
- Implementing Splunk(Second Edition)
- Python GUI設計tkinter菜鳥編程(增強版)
- Computer Vision with Python 3