This time, we will build an environment for launching applications in AWS EC2 instances.
You can log in to your EC2 instance by making an SSH connection between your computer and your EC2 instance.
First, use the command yum to update the original program on this server. Such a program is called a package.
It is a software management mechanism in Linux. It plays the same role as Homebrew for MacOS. By using the yum command, you can manage the versions of programs under the control of yum and update them in a batch.
A set of programs with a certain role / function under LinuxOS. It can be called software or library. In Linux OS, a set of programs with a certain role / function is called a package.
We will carry it out in the production environment.
[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y update
Install various other packages required for environment construction.
[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y install git make gcc-c++ patch libyaml-devel libffi-devel libicu-devel zlib-devel readline-devel libxml2-devel libxslt-devel ImageMagick ImageMagick-devel openssl-devel libcurl libcurl-devel curl
The -y command is a command that sets all questions to be answered automatically with Yes.
Next, install Node.js to run JavaScript on EC2.
[ec2-user@ip-172-31-25-189 ~]$ sudo curl -sL https://rpm.nodesource.com/setup_6.x | sudo bash -
[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y install nodejs
Node.js A JavaScript package that runs on the server side. It will be used when compressing CSS and images in the work for future deployment.
I used it when building the Mac environment, but I will explain it briefly again. rbenv and ruby-build are tools that are used in combination when managing Ruby versions. These need to be installed before installing Ruby. ruby-build is a plugin for rbenv that allows you to install different versions of Ruby (such as 2.0.0) with ruby-build. You can switch the ruby version by using rbenv.
#Install rbenv
[ec2-user@ip-172-31-25-189 ~]$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
#Pass through
[ec2-user@ip-172-31-25-189 ~]$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
#Description for calling rbenv
[ec2-user@ip-172-31-25-189 ~]$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
#.bash_Load profile
[ec2-user@ip-172-31-25-189 ~]$ source .bash_profile
#ruby-install build
[ec2-user@ip-172-31-25-189 ~]$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
#Do rehash
[ec2-user@ip-172-31-25-189 ~]$ rbenv rehash
The second and third commands are the commands you need to pass through the path. Passing the path means making the application callable from any directory. Then, with the fourth command, the set path is read. The last command is the command you need to be able to use gem commands in your version of Ruby.
Please change the command group to be executed below according to the version of Ruby to be installed and the version of Ruby used in your application.
#Ruby 2.5.Install version 1
[ec2-user@ip-172-31-25-189 ~]$ rbenv install 2.5.1
#Decide which version of Ruby to use within your EC2 instance
[ec2-user@ip-172-31-25-189 ~]$ rbenv global 2.5.1
#Do rehash
[ec2-user@ip-172-31-25-189 ~]$ rbenv rehash
[ec2-user@ip-172-31-25-189 ~]$ ruby -v
This time, we will use MySQL, which is a typical RDBMS (relational database management system). The image of the system configuration this time is as follows.
MySQL An RDBMS developed and provided by Oracle. You can create, edit, delete, etc. the database. It is released as open source software and anyone can use it free of charge.
If you are using Amazon Linux, you can install MySQL from the yum command. This time I will install MySQL version 5.6.
[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y install mysql56-server mysql56-devel mysql56
Use the service command to start MySQL. This is included in Amazon Linux and CentOS, and is a tool that allows you to start the installed software all at once.
[ec2-user@ip-172-31-25-189 ~]$ sudo service mysqld start
The d in mysqld is an acronym for "daemon" which means "server" in Linux terms.
You can check if it can be started with the following.
[ec2-user@ip-172-31-25-189 ~]$ sudo service mysqld status
mysqld (pid 15692) is running...
By default, MySQL installed with yum can be accessed by the user root, but no password is set.
Therefore, let's set a password with the following command. For the part of'password you want to set', for example, if you set the character string password0000, write'password0000'. Avoid passwords that start with 0, as they often do not read. (For example, '0331higuchi')
[ec2-user@ip-172-31-25-189 ~]$ sudo /usr/libexec/mysql56/mysqladmin -u root password 'Please change this to the password you want to set and then execute the command.'
[ec2-user@ip-172-31-25-189 ~]$ mysql -u root -p
After entering the above command, you will be prompted to enter the password you set earlier, so you can connect by entering it.
The settings of the Web server and Application server for publishing the application will be described in the next article.
Recommended Posts