Code Optimization

Interesting things about software development and code optimization

AWS Route 53 and existing subdomain traffic routing to EC2 and EBL

Hello friends,


I would like to share my experience in configuring DNS records under your already existing DNS (outside of AWS) for a sub-domain and routing traffic to your EC2 instance for Elastic Beanstalk application using Route 53 of Amazone, phh :P

So you will need:

- EC2 up and running

- Elastic Beanstalk if you use it

- Route 53 (seems paid feature)

- Access to your current DNS records usually your hosting provided or DNS hosting service provide you with access to it


First thing you need is to allocate Elastic IP Address to your EC2 instance (something like Static IP address)

Go to Network & Security > Elastic IPs



Click the Allocate Elastic Ip address and assign it to your EC2 instance.

Now we need to configure Route 53 - go to Route 53 > Hosted Zones and create new zone and name it 

as your sub-domain like sub.maindomain.com

Go inside of the zone and create a new record, select Type A - IPv4 address, set Alias to Yes and set your Alias Target to your ElastikBeanstalk instance name  and click the Save Record Set button.


Now you need to goe to your hosting or DNS provider and add all NS records that you see under the Route 53 NS type (created by default by AWS).

In my case it was XXXHosting provider that hosted servers and DNS. On the Control Panel I found DNS management 

and added a new DNS records for sub.maindomain.com with Type NS and pointing to the NS servers.


Give it some time from 30 minutes to a few hours to propagate through the world and now your subdomain will direct all traffic to your AWS instance.


Thank you








1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



AWS, WordPress and File Uploading issue

Some time ago I had a need to modify some small things here and there under WordPress that was deployed under AWS EC2 instance.

As I had never worked with PHP, AWS and WordPress it was just simple step-by-step steps that I did take to get its done.

At some point when i started uploading images I faced with the error like:

The uploaded file could not be moved to wp-content/uploads/2019/02

Sure, it was not hard to understand that something wrong with permissions, access, folders, files, etc. But where and why? Do not forget I had never worked with all of that before.

I did try everything I knew on that time about it but with no luck.

I did google and try to gather everything by pieces, I also did contact AWS support and they did help me a lot as well.

This was due to a permissions/ownership problem. 

Apache httpd serves files that are kept in a directory called the Apache document root. The Amazon Linux Apache document root was /var/www/html, which by default was owned by root.

Below is an example on how to modify the ownership and permissions of this directory. In this example my user was ec2-user but it may be different in your environment. You would replace ec2-user with whatever your user is.

To allow the ec2-user account to manipulate files in this directory, you must modify the ownership and permissions of the directory. There are many ways to accomplish this task. Here we will add ec2-user to the apache group, to give the apache group ownership of the /var/www directory and assign write permissions to the group.


So finally here are steps that did solve my problem with file uploading:



1. Add your user (in this case, ec2-user) to the apache group. [ec2-user ~]$ sudo usermod -a -G apache ec2-user 
 2.Log out and then log back in again to pick up the new group, and then verify your membership. 
                    a. Log out (use the exit command or close the terminal window): [ec2-user ~]$ exit 
                    b. To verify your membership in the apache group, reconnect to your instance, and then run the following command: [ec2-user ~]$ groups ec2-user adm wheel apache systemd-journal 
 3. Change the group ownership of /var/www and its contents to the apache group. [ec2-user ~]$ sudo chown -R ec2-user:apache /var/www 
 4. To add group write permissions and to set the group ID on future subdirectories, change the directory permissions of /var/www and its subdirectories. [ec2-user ~]$ sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \; 
 5. To add group write permissions, recursively change the file permissions of /var/www and its subdirectories: [ec2-user ~]$ find /var/www -type f -exec sudo chmod 0664 {} \;


Now, ec2-user (and any future members of the apache group) can add, delete, and edit files in the Apache document root, enabling you to add content, such as a static website or a PHP application.


I have to mention that this did not solve my problem with plugin updating

An error occurred while updating Akismet Anti-Spam: Could not create directory


but this is different story and hopefully we will see solution as well :)


Thank you


1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y