- Amazon Linux AMI Install Linux, nginx, MySQL, PHP (LEMP)
- Amazon Linux AMI LEMP stack installation
- 1. Update your Amazon Linux AMI system
- 2. Install Nginx web server
- Open port TCP port 80
- Test it
- 3. Install MySQL database server
- Installing NGINX Plus AMIs on Amazon EC2
- Installing the NGINX Plus AMI
- What If I Need Help?
- nrollr / Commands.sh
- This comment has been minimized.
- xird commented May 6, 2019
- This comment has been minimized.
- bgbruno commented Jul 7, 2019
- This comment has been minimized.
- nrollr commented Jul 7, 2019
- This comment has been minimized.
- bgbruno commented Jul 8, 2019
- This comment has been minimized.
- eaponiente commented Jul 17, 2019
- This comment has been minimized.
- 3fonteinen commented Aug 8, 2019
- This comment has been minimized.
- ashwinsingh2007 commented Dec 28, 2019
- This comment has been minimized.
- dumim commented May 6, 2020
- This comment has been minimized.
- LosD commented May 30, 2021 •
- How To Install and Configure Nginx on Amazon ec2 RHEL and Ubuntu Instances
- Instance Setup
- Nginx Setup on RHEL/Centos/Ubuntu
- Install Nginx on RHEL & Centos
- Install Nginx on Ubuntu
- Start and Enable Nginx
- Setting up Multiple Domains Using Nginx Server Blocks
- Nginx SSL Setup
- Load balancing using Nginx
Amazon Linux AMI Install Linux, nginx, MySQL, PHP (LEMP)
Amazon Linux AMI LEMP stack installation
The procedure is as follows:
- Update Amazon Linux AMI, run sudo yum update
- Install Nginx, execute: sudo yum install nginx
- Let us install MySQL database server, execute: sudo yum install mysql57-server
- Set up PHP version 7.3, execute:
- Open port 80 using iptables firewall
- Test your LEMP stack running on Amazon AMI Linux
Let us see all steps and examples in details.
1. Update your Amazon Linux AMI system
Check for the updates using the yum command and apply security updates on Amazon Linux AMI:
yum check-update
sudo yum update -y
Reboot the Linux system powered by Amazon Linux AMI if kernel update was installed:
sudo reboot
2. Install Nginx web server
Nginx is a web server and a reverse proxy server for HTTP/HTTPS and more. It is part of LEAP stack. Simply type the following yum command to install it on Amazon Linux AMI:
sudo yum search nginx
sudo yum info nginx
sudo yum install nginx
As usual, nginx web server does not start on Amazon Linux AMI. To start nginx server running, execute the following service command:
sudo service nginx start
Enable service at boot time using the chkconfig command sudo chkconfig nginx on
Verify that nginx service is running with help of pgrep command/ss command/netstat command commands:
sudo service nginx status
pgrep nginx
ss -tlpn | grep :80
Open port TCP port 80
Edit the file:
sudo vi /etc/sysconfig/iptables
Append the following line to open TCP port 80 before final DROP rule:
Save and close the file. Restart the firewall:
sudo service iptables restart
See “Set Up a Basic Iptables Firewall on Amazon Linux AMI” for more info about IPv4 and IPv6 firewall.
Test it
Fire a web browser and type your public IPv4 address such as:
http://1.2.3.4/
http://your-domain-mapped-to-public-ip-com/
http://202.1.2.3/
3. Install MySQL database server
The first step is to search for MySQL DB version, run:
yum list mysql*-server
Sample outputs:
Источник
Installing NGINX Plus AMIs on Amazon EC2
Install NGINX Plus on Amazon Web Services (AWS), to provide sophisticated Layer 7 load balancing for your apps running on Amazon Linux, RHEL, and Ubuntu.
NGINX, Inc. participates in the Amazon Web Services (AWS) Partner Network as a Standard Technology Partner. We offer Amazon Machine Images (AMIs) for use in the Amazon Elastic Compute Cloud (EC2), available at the AWS Marketplace for several operating systems, including Amazon Linux, Red Hat Enterprise Linux, and Ubuntu.
The AMIs contain the following components:
- Latest version of NGINX Plus, optimized for use on Amazon EC2
- Pre-packaged software for building highly available (HA) NGINX Plus configurations
Installing the NGINX Plus AMI
To quickly set up an NGINX Plus environment on AWS:
Follow the instructions in Getting Started with Amazon EC2 Linux Instances to sign up on AWS and get more information about EC2 itself.
Proceed to the product page for the appropriate AMI at the AWS Marketplace, and launch the AMI.
Click the Continue to Subscribe button to proceed to the Launch on EC2 page.
Select the type of launch by clicking the appropriate tab ( 1‑Click Launch , Manual Launch, or Service Catalog). Choose the desired options for billing, instance size, and so on, and click the Accept Software Terms… button.
When configuring the firewall rules, add a rule to accept web traffic on TCP ports 80 and 443 (this happens automatically if you launch from the 1-Click Launch tab).
As soon as the new EC2 instance launches, NGINX Plus starts automatically and serves a default index.html page. To view the page, use a web browser to access the public DNS name of the new instance. You can also check the status of the NGINX Plus server by logging into the EC2 instance and running this command:
What If I Need Help?
If you encounter any problems with NGINX Plus configuration, documentation is available at nginx.org and in the NGINX Plus Admin Guide.
Customers who purchase an NGINX Plus AMI at the AWS Marketplace are eligible for the AWS support provided by the NGINX, Inc. engineering team. To activate support, submit the AMI Support Activation form (you need your AWS account number). When you request support, we’ll ask you to provide the AWS account number that you registered, along with the IDs of your EC2 instances in some cases.
Источник
nrollr / Commands.sh
# # Install NGINX |
# # when installing on Amazon Linux AMI, use: |
$ sudo yum install nginx -y |
# # when installing on Amazon Linux 2 AMI, use |
$ sudo amazon-linux-extras install nginx1.12 -y |
# # Install PHP and PHP-FPM |
# for PHP version 7.1 use php71 and php71-fpm instead |
$ sudo yum install php -y |
$ sudo yum install php-fpm -y |
# # Configure NGINX (see below) |
$ sudo nano /etc/nginx/conf.d/default.conf |
# # Configure PHP-FPM (see below) |
$ sudo nano /etc/php-fpm.d/www.conf |
# # Add NGINX and PHP-FPM service start to boot sequence |
$ sudo chkconfig nginx on |
$ sudo chkconfig php-fpm on |
# # Start NGINX and PHP-FPM service |
$ sudo service nginx start |
$ sudo service php-fpm start |
# # Add .php to /var/www/html |
# # Verify configuration via http://www.domain.com/ .php |
server < |
listen 80; |
listen [::]:80; |
server_name www.domain.com domain.com; |
location / < |
root /var/www/html; |
index index.php index.html index.htm; |
> |
location |
\.php$ <
## Config associated with PHP-FPM version 7.1 |
## Comment out the following entries (with 😉 |
;listen.acl_users = apache,nginx |
;listen.owner = nobody |
;listen.group = nobody |
;listen.mode = 0666 |
;user = apache |
;group = apache |
## Add the following values instead |
listen = /var/run/php-fpm/php-fpm.sock |
listen.owner = nginx |
listen.group = nginx |
listen.mode = 0664 |
user = nginx |
group = nginx |
This comment has been minimized.
Copy link Quote reply
xird commented May 6, 2019
This no longer works on the latest Amazon Linux images, as nginx isn’t included in the default packages. See https://stackoverflow.com/questions/37082406/how-to-install-nginx-1-9-15-on-amazon-linux-disto
This comment has been minimized.
Copy link Quote reply
bgbruno commented Jul 7, 2019
UPDATE
sudo yum install nginx -y
->
sudo amazon-linux-extras install nginx1.12 -y
This comment has been minimized.
Copy link Quote reply
nrollr commented Jul 7, 2019
@xird @bgbruno
Agree, a different command is required IF it concerns a type Amazon Linux 2 AMI .
The Amazon Linux AMI still accepts the sudo yum install nginx -y -command (tested with ami-05b93cd5a1b552734)
Added the command + some comments when installing on Amazon Linux 2 AMI
This comment has been minimized.
Copy link Quote reply
bgbruno commented Jul 8, 2019
@nrollr yap it was Amazon Linux 2 AMI
This comment has been minimized.
Copy link Quote reply
eaponiente commented Jul 17, 2019
does this work on Amazon Linux 2 AMI? I cant get it to work, although all of these commands does not return any error when I tried em
This comment has been minimized.
Copy link Quote reply
3fonteinen commented Aug 8, 2019
@eaponiente just ran a test with amzn2-ami-hvm-2.0.20190618-x86_64-gp2 (ami-0adcddd3324248c4c) and followed the procedure step-by-step, and it works fine. Make sure the security group attached to your EC2 instance allows inbound access on port 80
This comment has been minimized.
Copy link Quote reply
ashwinsingh2007 commented Dec 28, 2019
thanks for Amazon Linux 2 part
This comment has been minimized.
Copy link Quote reply
dumim commented May 6, 2020
Thanks for this mate, helped out so much!
This comment has been minimized.
Copy link Quote reply
LosD commented May 30, 2021 •
The nginx1.12 topic is WAY outdated (and marked as such by the amazon-linux-extras command, if you have the topic enabled. It’s hidden if you don’t). Use the topic nginx1 instead.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
How To Install and Configure Nginx on Amazon ec2 RHEL and Ubuntu Instances
Nginx is a web server like apache. Not only as a web server, but it can also act as a load balancer, reverse proxy, etc. Performance-wise, Nginx is considered to be better than apache. Processing request in Nginx is even based as opposed to the spanning new thread model in apache.
In this tutorial, I will explain how to install and configure Nginx on ec2 RHEL and ubuntu instances.
The process for installing & configuring Nginx on RHEL , Centos and Amazon Linux is the same.
Instance Setup
- Launch an RHEL/Centos/Ubuntu instance using the management console. While launching the instance , configure the security group to allow traffic from HTTP 80 port & HTTPS 443.
- Connect the instance using putty.
- You can also setup password authentication to the ec2 instance
Nginx Setup on RHEL/Centos/Ubuntu
In this guide, we will look in the following.
Install Nginx on RHEL & Centos
Step 1: In RHEL you cannot download and install Nginx directly. You have to setup the epel ( extra packages for enterprise Linux) repo to install Nginx. Install EPEL package repository.
For Centos, execute the following.
Step 2: Update the package list.
Step 3: Install Nginx
Install Nginx on Ubuntu
Execute the following steps to install Nginx on Ubuntu servers.
Start and Enable Nginx
Following steps are common for RHEL and Ubuntu systems.
Step 1: Check the version to make sure Nginx is installed.
Step 2: Start and enable Nginx.
Step 3: Check the status of Nginx to make sure it is running as expected.
Step 4: Visit the nginx page using the Server IP. You should be seeing
Setting up Multiple Domains Using Nginx Server Blocks
When you have one or more websites to be hosted on the same Nginx server, you need to use the Virtual Hosts configuration.
In this section I will show you how to create a virtual host configuration for a website.
Step 1: Create the website folder and a public folder to put the static assets inside /var/www
Here am going to give the name as example-one.com. Name the folder with your website name. It will be easy to identify if you have many websites running on the same server.
Step 2: Create a test index.html file if you dont have your own index file.
Copy the following contents and save the file.
Step 3: Change the ownership of the root document to the user which is managing the worker process.
For RHEL/Centos the user is nginx,
In most of the RHEL/Centos distributions, SElinux will be set to in enforcing mode. Execute the following commands for SELinux to allow accessing the nginx website files.
For Ubuntu the user is www-data,
Step 4: Create a Nginx configuration file with the websites name
Create the config gile under /etc/nginx/conf.d/ folder.
Create the config file under /etc/nginx/sites-available/ folder.
Copy the following server block configuration the conf file and save it.
Note: Replace example-one with your domain name.
Only on Ubuntu server, execute the following command to create a symbolic link to sites-enabled folder.
Step 5: Validate the server block configuration using the following command.
If should get the following success message.
Step 6: Restart the nginx server.
If you use the public DNS of the ec2 instance , the server will throw the following error when you restart the Nginx server.
Since the DNS name is pretty long , you have to add the server name bucket size to 128 to the example-one.conf file.
Now you will be able to access the website using your domain name. If you have used the test domain names, add it to your systems /etc/hosts file and try accessing the website.
To add more domains to the nginx server, follow the same steps with a different domain name and config names as explained.
Nginx SSL Setup
Optionally you can setup SSL for your Nginx websites. You can use the free SSL certificates from Letsencrpt for your SSL need.
I have written a tutorial for setting up SSL using Letsencryp. Read the tutorial here -> Nginx Letsencrypt Setup Guide Using Certbot
Load balancing using Nginx
You can use Nginx as a load balancer to balance the load between server fleets. Nginx proxies the incoming requests and sends it to the backend servers. To configure Nginx as a load balancer, you have to add two blocks of code to the nginx configuration file.
Step 1: Open nginx.conf file
Step 2: Add the upstream group under the HTTP section. The upstream group is the group of servers which comes under the load balancer. You can give any user defined name for the group. Here am going to give the name as “web_fleet”.
Note: this configuration should be present in the HTTP section of nginx.conf file.
Step 3: Now you have to set the vhost configuration to receive traffic from a particular domain name and route it to the upstream servers. Add the following lines followed by the upstream block and save the file.
Step 4: Restart the Nginx server
Step 5: Now, if you access your nginx server using the DNS, the request will be routed to the backend server fleet present in the upstream block.
Make sure some service is running on the backend servers you mention in the upstream block.
There are many other parameters and setting associated with the load balancing configuration. You can check the official Nginx documentation for more clarification.
Источник