官术网_书友最值得收藏!

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:

  1. Go to the Amazon AWS homepage at https://aws.amazon.com/. It will look something like this:
  2. Click on Create an AWS Account.
  3. Add your e-mail or phone number and select I am a new user.:
  4. Click on Sign in using our secure server.
  5. 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:

  1. Go to the Amazon EC2 landing page, that is, https://aws.amazon.com/ec2/, which will look something like this:
  2. 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.
  3. On the AWS Management Console, search for ec2 in the AWS services search box:
  4. 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:

  5. Instance Setup Wizard:

    1. 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:
    2. 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:
    3. 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.
    4. 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).
    5. 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.
    6. 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.
    7. Review: In this step, you can review the configuration for your Amazon instance. Click on Launch at the bottom-right of the screen:

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:

  1. Go to the https://console.aws.amazon.com/ec2/ AWS EC2 Management Console.
  2. 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:
  3. 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:

  1. Update all the existing packages in the server:
     apt-get update
    
  2. 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

  3. 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
    
  4. 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
  5. Open the apache2.conf file and set AllowOverride all to grant the right permissions to the document root.
  6. 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>
  7. Restart the Apache server to apply the changes:
     sudo service apache2 restart
    
  8. Create a sample phpinfo.php file in the document root:
     cd /var/www/html 
     rm index.html 
     echo "<?php echo phpinfo();" > phpinfo.php
    
  9. 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:

  10. If phpinfo.php is displayed properly, remove the phpinfo.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.

主站蜘蛛池模板: 哈巴河县| 信阳市| 东至县| 崇阳县| 筠连县| 出国| 遂溪县| 永康市| 赣榆县| 伊吾县| 兖州市| 津南区| 达日县| 南郑县| 高阳县| 门头沟区| 城市| 宜宾市| 崇明县| 宽甸| 察雅县| 德保县| 泾源县| 徐水县| 云梦县| 潼关县| 兴安盟| 莆田市| 黔江区| 新河县| 仪征市| 新兴县| 长顺县| 龙山县| 绵竹市| 福州市| 海阳市| 志丹县| 青铜峡市| 泰来县| 五台县|