install wordpress nginx php-fpm

Install and Manage WordPress with Nginx and PHP-FPM on AWS EC2 Micro Instance

Table of Contents

Servers that are managed are sluggish. They use old PHP versions on old Apache versions, and they become slow with the sudden influx of traffic. In this tutorial, I'll take you through the process of creating a server and that can withstand heavy traffic. This ensures that your company is visible online when it matters most—when everyone is looking.

In this post, we'll go through the steps of developing a bulletproof, super-fast custom web server for WordPress and the easy way to manage it by using the WordOps package. , Nginx, PHP-FPM, and would be our technology stack.

This guide assumes that you're familiar with the command line and editing system configuration files. It's for people who want a lot of influence over and information about their infrastructure. If you don't Google at any point, it will take about half an hour.

What is AWS?

AWS (Amazon Web Services) is a cloud hosting service that provides everything you need to run a WordPress blog. With a few variations, this is similar to a web hosting company service:

  • You have a lot of leverage over the infrastructure. You can, for example, change your php.ini file and set up a load balancer to spread load across several application servers.
  • Provisioning and resizing server resources are easy. Is it appropriate to increase the RAM on a server from 1GB to 30GB? It's not a problem.
  • You just have to pay for what you need. Don't lock yourself into a high-priced plan with additional services you might or may not need.

Creating and AWS account

Create an Amazon Web Services (AWS) account. A year of free AWS usage to a basic set of server resources is included in the Free Pricing Tier.

Logging into the AWS console

Access the AWS console, which is a browser-based administrative system for .

Create an IAM user account

The AWS programme IAM (Identity and Access Management) handles user access to other services and server resources.

If you use your main Amazon account to log into the AWS web console, you're in root user mode, which is good for our purposes.

We'll create an IAM user instead of using the root user's credentials to use the AWS command-line interface in this tutorial.

To access the IAM dashboard, go to the Administration & Security section of the AWS Console homepage and click Identity & Access Management.

Click Users to see a list of all the AWS account's registered IAM users, which should be empty. Create a user account for yourself and download the access key information by clicking Create New Users. To authenticate your device with AWS, you'll need access key credentials.

A collection of permissions is specified by an IAM Community. Users are allocated to classes, which gives them access to certain services.

While still in the IAM console, go to Groups to see a list of all the AWS account's registered IAM Groups, which should all be empty. Build a new “Administrators” IAM Community. Attach the AdministratorAccess policy to the community, which gives all resources full access.

Add your user account to the “Administrators” section in the Users list.

Install and configure the AWS command-line interface

The AWS command line interface (CLI) is a single tool for controlling services from the terminal on your device. The web console or the command line can be used to perform most AWS management tasks (for example, creating a new EC2 instance). Choosing one to use for any given task will be decided by your workflow preferences.

For your computer's terminal, instal the AWS command line interface.

Run aws configure with the access key credentials for the IAM user you just built. This helps you to log in to your computer using the user account.

During this setup, choose a default AWS zone. AWS regions are a list of data centres around the world where you can host services. Your default is most likely “us-west-2”; check the area dropdown in the web console's menu bar to confirm.

Creating an EC2 Key Pair

A cryptographic public and private key pair called an EC2 key pair is required to authorise ssh access to an EC2 case. An IAM consumer is associated with a key pair. A private key matching a public key associated with the instance exists on your device to authorise access to an EC instance.

Create the folder /.ssh if it does not already exist on your computer. The location of the ssh credential files.

mkdir ~/.ssh

Using the AWS CLI, build a key pair. Replace KEY NAME with the name of the key and the position of the private key register. “Aws-wp” was the name I gave to mine.

aws ec2 create-key-pair --key-name {{KEY_NAME}} --query 'KeyMaterial' --output text > ~/.ssh/{{KEY_NAME}}.pem

In the /.ssh directory, a new private key file is created.

Change the private key's file permissions so that only your user can read it.

chmod 400 ~/.ssh/{{KEY_NAME}}.pem

Creating an EC2 instance

EC2 (Elastic Compute Cloud) is a service for managing EC2 instances, which are generic-purpose virtual machines. We'll set up an EC2 instance to act as the web server install wordpress nginx php-fpm.

To access the EC2 console, go to the AWS console homepage and press EC2. To see a list of all EC2 instances for the account, select Instances, which should be empty.

Pick Launch Instance from the drop-down menu.

We need to select a disc image to launch an operating system onto the instance in “Step 1: Choose an AMI.” Choose the “Ubuntu 20.04 AMI” option.

Select “t2.micro” in “Step 2: Choose Instance Form.”

Using the defaults, proceed through the wizard.

Develop a new Security Group called “WordPressApplicationServer” in “Step 6: Configure Security Group.” A Protection Group is a form of firewall that controls traffic to and from a specific instance. Add a rule to allow SSH access, and only allow access from your IP address in the Source column. Build a rule that allows HTTP access from any venue. Build a rule that allows HTTPS access from any venue.

Check the instance before launching it. When prompted, select the previously generated key pair to grant access to the case. It will take a few moments to boot up. To check the state of the instance list table, go back to it.

SSH into the EC2 instance

To open an information window, select the newly launched instance in the instance list table. Login via ssh in a terminal using the Public DNS (i.e. the hostname) mentioned here.

ssh ec2-user@{{INSTANCE_PUBLIC_HOSTNAME}} -i ~/.ssh/{{PRIVATE_KEY_FILE_NAME}}

“ec2-user” is the default device user account for Amazon Linux, and it has sudo access.

Updating the system

Update any device packages in the distribution that might be out of date.

sudo apt-get update

Download WordPress on the server

The site's directory root, from which Nginx will serve files, will be located /var/www/{{SITE_DOMAIN}}.com/htdocs here. Make a folder for it using this command

sudo mkdir -p /var/www/{{SITE_DOMAIN}}.com/htdocs

Download the latest stable WordPress version into this folder.

cd /var/www/{{SITE_DOMAIN}}.com/htdocs 
sudo wget https://wordpress.org/latest.tar.gz 
sudo tar zxf latest.tar.gz 
cd wordpress 
sudo cp -rpf * ../ 
cd ../ 
sudo rm -rf wordpress/ latest.tar.gz

Installing WordOps package

We are going to use the WordOps package to manage all the behind technicalities of our . I selected this package as its lightweight, well-maintained and easy to update.

It's both easy to install and unistall different versions of PHP version with WordOps and also much easier to update nginx and php. This is the best way in my recommendation to install wordpress nginx php-fpm on any server.

One step installation of WordOps

WordOps comes with an easy to install command which installs the required dependencies, before setting-up WordOps. It can be installed with the following command:

wget -qO wo wops.cc && sudo bash wo

you can check the wo installation by this command

wo info

This should return the details of WordOps installation on the system.

Now, if you look at the WordOps package, it comes with a defualt installation command to install WordPress package as well. But in my practice, I have found that to install WordPress nginx PHP-FPM website this way decreases the performance with the increase of traffic. I might be wrong too but so far most of the cases have been this way for me.

So we will be installing just Nginx and PHP7.4 and maintaining them with the WordOps package.

Installing Nginx and PHP7.4-FPM

First, lets install Nginx using the command:

wo stack install --nginx

This installs the latest version of nginx

Now, we will install PHP7.4-FPM stack with this command:

wo stack install --php74

Just these two commands will install the two major aspects of the WordPress website on our AWS EC2 instance.

There are other packages like , redis, etc.. which can also be installed with WordOps which can be checked here.

Since we are using only the t2.micro instance of AWS EC2, we will try to keep this installation as minimal as possible.

Optimizing PHP7.4-FPM

As we are on t2.micro instance now, we need to change the default configuration of PHP-FPM. This can be done in the www.conf file.

sudo nano /etc/php/7.4/fpm/pool.d/www.conf

and put the respective values as shown below:

pm.max_children = 3
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 2

Rest everything comes already optimized with WordOps, so you dont have to worry about other details.

Setting up and optimizing Nginx


Nginx
 is a high-performance web server and reverse proxy. We have already installed it in our previous steps. Now its time to set its configurations right.

Create the Nginx configuration file for your :

sudo nano /etc/nginx/sites-available/{{SITE_DOMAIN}}.com

Input or copy these configurations in your newly created Nginx configuration file above:

server {
   listen [::]:80;
   listen 80;
 server_name starwheeler.com;
 # Include defaults for allowed SSL/TLS protocols and handshake caches.
   #include h5bp/directive-only/ssl.conf;
 # config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
   # to avoid ssl stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping
   #add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
 #ssl_certificate_key /etc/sslmate/{{SITE_DOMAIN}}.com.key;
   #ssl_certificate /etc/sslmate/{{SITE_DOMAIN}}.com.chained.crt;
 # Path for static files
   root /var/www/starwheeler.com/htdocs;
 #Specify a charset
   charset utf-8;
 # Include the basic h5bp config set
   #include h5bp/basic.conf;
 location / {
     index index.php;
     try_files $uri $uri/ /index.php?$args;
   location ~ .php$ {
     fastcgi_cache  WORDPRESS;
     fastcgi_cache_key $scheme$host$request_method$request_uri;
     fastcgi_cache_valid 200 304 10m;
     fastcgi_cache_use_stale updating;
     fastcgi_max_temp_file_size 1M;
     fastcgi_pass   unix:/var/run/php/php74-fpm.sock;
     fastcgi_index  index.php;
     fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
     include        fastcgi_params;
 
# Local variables to track whether to serve a microcached page or not. 
set $no_cache_set 0; 
set $no_cache_get 0; 

# If a request comes in with a X-Nginx-Cache-Purge: 1 header, do not grab from cache 
# But note that we will still store to cache 
# We use this to proactively update items in the cache! 
if ( $http_x_nginx_cache_purge ) {   
set $no_cache_get 1; 
} 
# If the user has a user logged-in cookie, circumvent the microcache. 
if ( $http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {   
set $no_cache_set 1;   set $no_cache_get 1; 
} 

# fastcgi_no_cache means "Do not store this proxy response in the cache" 
fastcgi_no_cache $no_cache_set; 
# fastcgi_cache_bypass means "Do not look in the cache for this request" 
fastcgi_cache_bypass $no_cache_get;
 }
 }
 }

To enable the site, symlink the configuration into the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/{{SITE_DOMAIN}}.com /etc/nginx/sites-enabled/{{SITE_DOMAIN}}.com

Testing the Nginx configuration before reloading:

sudo nginx -t

If the configurations passes, reload the stack by using the WordOps reload command:

sudo wo stack reload

Your website like RockinWordPress should be visible at {{SITE_DOMAIN}}.com now.

If any errors found, always check the logs:

tail -f /var/log/nginx/error.log

Final Words

I have tried to install the minimal stack to install WordPress Nginx PHP-FPM. This helps you to use fewer resources possible on a very small server like AWS EC2 “t2.micro” instances. You can always check the resources by using top command.

This same install can also be installed with Redis caching and WP-Rocket caching but I have found them resource hogging. So my recommendation is to use WP-Rocket plugin seperate manually inside the wordpress admin.

I have also not installed Letsencrypt SSL certificate for ease of this install as the SSL can be enabled from cloudflare and used on your website. Though, its not the recommended way, I have avoided in this tutorial to keep things simple and easy.

The MYSQL part is suggested to go with the setup on Amazon which will further reduce the load on your server.

Hope this post helps you. If any questions, do comment below.

Share This Article:
Facebook
Twitter
LinkedIn
Pinterest
WhatsApp
Email
Reddit
Related Articles:
image size reduce online
Facebook
Free Image Size Reduction Trick

Without Any Plugin Did you know that a normal website gets most of its weight from the images used in it? It is true. The majority of website size is mostly because of the images used in its pages. Optimizing images without losing quality is a difficult task for average

Read More »
free wordpress hosting
Plugins
Host Your WordPress Website For Free Forever

Hosting a WordPress website can be an expensive thing if not done properly. It can go from just a few dollars to thousands of dollars a month. Finding WordPress hosting can be a difficult task. If you own a small blog or website that you do not update often then

Read More »
free high quality backlinks
Backlinks
Get Free High Quality Backlinks The Creative Way

A backlink in the SEO world is a link from a post or a page on one website to another. If a website is linking to your content, it means you got a backlink. These backlinks are also called “inbound links”. Sometimes they are also called “incoming links”. Carrying a

Read More »
Find blog rank with free tools
Search Engine Optimization (SEO)
How To Know My Blog Rank? Answered Using Free Tools

Keywords are a cornerstone of your WordPress website’s search engine optimization approach. For search engines, keywords, and the websites that employ them as an optimization component, it’s been a long and winding ride. The regulations for keywords in search engines haven’t always been clear. The websites’ keyword practices haven’t always

Read More »
seo-terms
Search Engine Optimization (SEO)
Common SEO Terms For Beginners In Digital Marketing

Have you ever had the impression that people like lawyers and stock traders cover a lot of mundane practice behind their lingo as if they were speaking in a different language? That is partially real, but don’t be fooled: some of the fancy languages facilitate fast communication among knowledgeable professionals.

Read More »
Subscribe to our newsletter
Chat With Our SEO community members On discord
Discord SEO Community Chat
  • Just-iko avatar Just-iko Thank you very much for answering ☑️ ✨
  • ddev66 avatar ddev66 Put your content in the right HTML tags and Google will show it this way.

    In the picture that you show, the first content is put in a list with bold headings.
    The second content is a FAQ on that page.

    Put in the right HTML tags and Google will pick it up nicely.
  • Just-iko avatar Just-iko Hello, I'm a newbie in this field, any guidance would be appreciated :) some questions please, is there any idea on how to make our website could appears like that in Google search? The one that I marked..
  • ddev66 avatar ddev66 Semrush or Ahrefs will help you for spying competitors.

    I think Semrush has a trial period as well.
  • Aadhi avatar Aadhi Buy semrush, you can buy it at cheap rate by using Group buy method
  • SG.CK avatar SG.CK Any free tool for spy traffic and ranking ?
  • ddev66 avatar ddev66 Search on google “htaccess redirect rules”
    Put them in your website’s htaccess file if you are using Apache
  • BrunoAfonso avatar BrunoAfonso how should I go to solve this issue
  • BrunoAfonso avatar BrunoAfonso Can you explain a little bit more? My website is not wordpress, I use amazon web services
  • ddev66 avatar ddev66 You can make a 301 redirect to the correct page on your website.
    If you are using Wordpress then SEO plugins like rank math have this feature.
    If you don’t want to use SEO plugins then there are many good redirect plugins in the Wordpress repository.
    And if you are not using Wordpress then .htaccess file is your friend.
  • BrunoAfonso avatar BrunoAfonso For example, is this image, the second link "THU Main Event" goes to a different page that it's supposed to. How do I fix this.
  • BrunoAfonso avatar BrunoAfonso So I have a website and when you search for it, one of the hyperlinks that google provides goes to the wrong page, is there a specific way for me to change that?
  • ddev66 avatar ddev66 Need more explanation
  • BrunoAfonso avatar BrunoAfonso Hello people, does anyone know how to fix a hyperlink within a google search?
  • ddev66 avatar ddev66 Semrush shows you all the links that it considers as toxic in its domain overview dashboard. You can then use these website list to disavow in GSC.
  • rrakesharmaa avatar rrakesharmaa I want to remove high spam backlinks via Disavow tool. So i need these links.
  • ddev66 avatar ddev66 extract high spam score backlinks.
    This is little confusing for me to understand

    Do you want to remove high spam backlinks to your website or do you want to receive backlinks from websites that have a high spam score?
  • yaswanth avatar yaswanth Now I use the Search console live URL inspector. It shows the page source and screenshot with an error(If any).
    Result: The page is not mobile friendly in the screenshot. All the element's styles are broken.

    Now, I feel like, " What the hell is happening in rich result tester? The google bot shows everything is ok, and in the search console, this is happening."

    # Problem Digging Stage final stage - Solving the problem
    The easiest way to solve the problem is to compare the thing and find the difference.
    Is rich results tester a google bot? Yes!
    Is it owned by google? Yes!
    Is it have any link with the official search console crawler? No!

    Now, What is the difference between 2 crawlers?
    Their IPs are different. They work differently.

    Summary: Google bot (Offical bot) is not able to crawl all elements in the webpage. It is not able to read all styling files. All other bots(services that use crawl as Google Bot) can view/crawl the page.

    List of official google bot IPs: https://developers.google.com/search/apis/ipranges/googlebot.json

    Solution: Rather than digging into all files, we changed the hosting server located in the exact location.

    Thank you for reading this article. It takes a few mins to read this article, but It took hours to find the correct problem with a solution. If you find this article valuable, give it a like and if you have any questions, feel free to ask them.
  • yaswanth avatar yaswanth Solving Critical Indexing Problem (CASE STUDY)

    Last week I received a message from a friend he is requesting me to help him index a page of his website. I said, " Wait, sometime google will index automatically" Then he said he was getting problem with his homepage. So, I started digging. First, I want to find the problem. Then all other things were easy.

    # Problem Digging Stage 1 - Analyze the top layers
    Checking the basic things
    1) No Index tags
    2) Canonical tags
    3) Website page Age

    Result: Nothing Found

    # Problem Digging Stage 2 - Getting Deeper
    1) Checking status codes (If there is any redirects, 404 error, or soft 404 errors)
    2) Using an SEO browser to check the web page accessibility
    3) Trying with different user agents

    Result: Nothing Found

    # Problem Digging Stage 3 - Analyzing and
    comparing past and current stages of webpage
    1) Checking the Wayback machine for any spam content history
    2) Checking the search console for errors
    3) Other page's indexability

    Result: I got some clue. Search console shows "Page is not mobile friendly."

    # Problem Digging Stage 4 -Finding the reason for the search console error.
    When I checked the web page with SEO Browser, the page was mobile friendly, and I also tried "crawl as Googlebot." Everything looks good. Then where is the problem?

    One thing was confirmed google is not able to view the webpage clearly. And all other bots are not getting any problems.

    So, I decided to use only google properties in the further process (Because only the google bot gets stuck).
    I selected three tools to process further.
    1) Google page speed insights
    2) Google rich results tester
    3) Search console Live URL inspector

    First, I used page speed insights to check If the google bot can crawl/view the page or not(If there are any issues in crawling, then the tool returns a lighthouse error)
    Result: everything is ok

    Second I used Google rich results tester. It provides the page source and screenshot of the webpage.
    Result: everything is ok
  • achann avatar achann Backlink actually link that provided outside web, so if you use instagram and insert your web link that still counted as backlink.
  • achann avatar achann If you want to be free, why not using mailchimp for email blast. Or maybe you can use whatsender for whatsapp blast, there is nulled version I think.
  • achann avatar achann Um.. Maybe you can use whatsapp blast and give link? Or maybe you can use email marketing and give link to your web?
  • rrakesharmaa avatar rrakesharmaa How can I extract high spam score backlinks for my website? Is there any free tool that provides all high spam score sites HELP ME PLEASE 🙂
  • nkap avatar nkap <@211319858258771968> hey, would you be able to share the website that you want guest posts on? I’m in touch with a few fintech businesses and can ask them whether they’d be interested in putting a post on your site.
  • ddev66 avatar ddev66 <@211319858258771968> it sure will work. Make sure to write that it’s free to post as guests. A lot of websites do not mention this and writers usually think it’s paid opportunity only.

    Keep us updated of how well this goes for your website.
  • soutaraku avatar soutaraku Thank you so much for the detailed guide. I'll see if I can put up the Guest Post page to start with! I hope my email gets bombarded in a good way haha
  • ddev66 avatar ddev66 You should start putting up a page called Guest Posting on your other website where you put articles, etc.. and put all the requirements there which you are looking for in the guest posts. Make sure to leave your email as well for easier contacts.

    Build up some links to this page. Because most of the writers are looking to write for high metrics website that have good DA, TF, etc...

    Once you have a page setup it will help you get attention from people who are searching on Google.

    Next you can start sending the URL of this page to people whom you think might be interested to write for your service on social networks like twitter, linkedin, etc.

    Also list this page URL on websites that have posts like free guest posts list in SaaS, free guest posts list in "your niche", etc. Something like this: https://underwp.com/the-best-free-guest-posting-websites-list-in-2022-over-3000/

    These will get you enough traction to attract guest posts from various contributors over the time. Your email will be bombarded with emails following the above tips.
  • soutaraku avatar soutaraku I can translate guest post to Japanese and put it on our website to share stories from overseas. I thought it would be interesting for our readers and a good way for link building.
  • soutaraku avatar soutaraku It's not titled as contribute/guest posts page, but there's a website we put interview articles and such. We surely can put guest posts on that website.
  • ddev66 avatar ddev66 <@211319858258771968> does your website have contribute/guest posts page?
  • soutaraku avatar soutaraku Hi guys! I'm a Japanese SEO specialist/ content editor working for a fintech company, and looking for someone to put guest posts on our website (preferably about fintech or SaaS market). Are there any good place to look for people willing to guest post?

    In Japan, not many people write guest posts, so I'm kinda lost. Twitter trick is only guiding light to me, <@838326478924021760>. Thanks for sharing.
  • Deleted User avatar Deleted User trying it out right now
  • nkap avatar nkap Great idea! Will definitely try it out. Thanks mate.
  • ddev66 avatar ddev66 A good trick to get guest posts for your website. <@456226577798135808> <@755307075625549854>
  • Büşra avatar Büşra Thank you very much. I'll try 😊
  • nkap avatar nkap Yeah me too!!
  • naaz avatar naaz <@755307075625549854> Thank you for the detailed answer. Hope <@341197404302737408> finds the right solution for this.
  • nkap avatar nkap <@341197404302737408> Just these:

    You can try 3 things: (I suggest you try the 3rd option first)

    1. If there are any links in your coverage report that’s actually not from your domain/property, I’d recommend you use the Search Console’s removal tool to remove these from your property.

    2. If you’re using any page builders like elementor etc make sure you turn off search engine indexing for things like templates. You can find this in Yoast SEO settings. With this setting your templates and unnecessary pages won’t be indexed. Are you using elementor by any chance?

    3. It’s also possible that your site has been hacked. If random URLs are appearing in analytics and search console the first thing that you should do is check your .htaccess file to see if someone has put any rewrite rules.
  • ddev66 avatar ddev66 <@755307075625549854> got any views on this?
  • ddev66 avatar ddev66 did you change your permalinks sometime back in last few months?
  • naaz avatar naaz <@838326478924021760> bringing to your attention on this.
  • Büşra avatar Büşra hello guys! I need to help about SEO optimation. I'm using wordpress Yoast. I saw dummy link like as ``` https://myURL.com/cuisine/35/17498``` I haven't these in page. Btw ı'm using google search console. Why may be this? Is anyone has idea about that?
  • ankit662003 avatar ankit662003 does anyone know how to create seo silos?
  • ankit662003 avatar ankit662003 hi
  • ddev66 avatar ddev66 Just know that we are all here to help each other
  • ddev66 avatar ddev66 No worries mate.
  • Alex25 avatar Alex25 The thing is idk what to ask .
    I'm just stuck
  • ddev66 avatar ddev66 Drop your queries here

3 Responses

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: