Deploy Laminas Framework Application on AWS with EFS - session

I have developed a web application and deploy it on Amazon AWS with a load balancer. Everything works fine but too slow.
My web servers share the same files by using Amazon EFS.
I my application, I store my users'sessions by using the filesystem and saving save files in a folder.
Because sessions files are shared on the EFS, I would like to know if it a good pratice ?
Or do I need to use a Redis server to share session datas between my webservers ? (I do not have a concrete example of using redis server configuration for sessions in Zend Framework 3 or Laminas project)
And the last one question is what are the advantages (or disadvantages) of activating AWS ELB stickyness session ?
Thank you for any advice or tips.

Related

mySql Server Placement on AWS EC2 or RDS

We are currently setting up AWS hosting for our Web Application.
This Laravel Web Application will have a Schema per company that registers, meaning it will have a large sized mySql server.
I have gone through the motions of setting up a VPC with EC2 instances and and RDS for this mySql server.
However we are currently looking at using Laravel Forge as a tool to host.
What Forge does differently is that it includes the mySql Server on the EC2 instance not on an RDS.
The question I have come to ask here is, what are the implications if any of having the mySql server on the EC2 instance rather then an RDS.
Would there be performance issues?
Is it better practice to have an RDS?
Or is Forges out the box way of packaging this all together on an EC2 server fine?
By running this on an EC2 instance you will taking more of the responsibility of managing the database, not just installation but also patching, backups, recovery. Harder to maintain functionality such as replication and HA will also be on you to implement and monitor.
By running on RDS AWS is going to take the heavy lifting of this and implement a best practice version of MySQL which offers the flexibility of allowing you to run a MySQL stack in the cloud without having to really think about the implementation details under the hood other than deciding do you want it to be HA and how many replicas do you want.
In saying this by using RDS you're also giving up the ability to run it however you want, you are limited to the versions of the database that RDS supports (although this is now quite soon after release). In addition not all plugins or extensions will be active so check this functionality before deciding.

Laravel Application & Load balancer

I have hosted my application on AWS cloud and a load balancer is running on top of two instances which is being served by Nginx on top of Php7.0-fpm. Let's say that my application downloads a file and stores it locally, so that the contents can be served to the customers. With an auto scaling group, configured for two instances;
1) If my session begins with instance-1 where my file gets downloaded, and suddenly switches over to instance-2, will I be getting the same content?
Or
2) If a session is created on a single instance, will the same instance be used until I log out of my application?
Any help is much appreciated!!
For a website with more than 1 instance, which is load balanced, it is highly recommended that you store cache and sessions in 1 place and not multiple across them. For this, you can install memcached on all servers and configure them to point them to 1 server to store it all.
SESSION_DRIVER=memcached
CACHE_DRIVER= memcached
MEMCACHED_HOST=127.0.0.1 #on your memcache server, point to localhost
MEMCACHED_HOST=10.10.1.10 #on other instances, point to memcache server
MEMCACHED_PORT=11211
For file and image uploads, use S3 from AWS or dedicated storage server with FTP to store so that all the servers can access it directly and the same way. Easiest and most efficient :)
If you store them locally, your servers won't be synced with the same content, and your users will end up with 404s.

Development and production on the same vps server?

I'm currently using a vps plan at vpsdime.com as my development server. I move a lot and use different computers so didn't want to develop locally.
Soon, I'll be able to launch my webapp (approx 5-10 users to start with). Should I simply install my production app on my same vps server, or would you advise to get another server? Why?
You can safely use the same server. Just make sure everything as separated per environment:
Different Redis database
Different MySQL database
Different Elasticsearch server
Different location to store session data
Different caching location
Different queues (Redis/Beanstalk, ...)
Different AWS bucket
Different ... you get the gist.
It should be straightforward to setup different vhosts with Apache or Nginx.

amazon EC2 load balanced - how to deploy web app?

We're looking to move to amazon cloud using EC2 and RDS.
I'm looking at load balancing, which I would like to do, two servers, each in a different availability zone to protect against downtime.
My question is how to deploy web applications and updates to them? I assume there is a better way than individually updating the files on each EC2 server?
In systems past, I have used the vcs puppet module to ensure that the appropriate source code is installed on my system, in addition to using puppet to build the configuration files for the apache/nginx server that I'm using. Another possibility is to push your application in a deployable state (if you're not using a scripting language) to Amazon S3, and have your run-time scripts pull the latest build from your S3 bucket.

Should I use a regular server instead of AWS?

Reading about and using the Amazon Web Services, I'm not really able to grasp how to use it correctly. Sorry about the long question:
I have a EC2 instance which mostly does the work of a web server (apache for file sharing and Tomcat with Play Framework for the web app). As it's a web server, the instance is running 24/7.
It just came to my attention that the data on the EC2 instance is non persistent. This means I lose my database and files if it's stopped. But I guess it also means my server settings and installed applications are lost as they are just files in the same way as the other data.
This means that I will either have to rewrite the whole app to use amazon CloudDB or write some code which stores the db on S3 and make my own AMI with the correct applications installed and configured. Or can this be quick-fixed by using EBS somehow?
My question is 1. is my understanding of aws is correct? and 2. is it's worth it? It could be a possibility to just set up a regular dedicated server where everything is persistent, as you would expect. Would love to have the scaleability of aws though..
If you use an EBS volume with your EC2 instance, you can mount/dismount them to have persistent storage. You can also use Amazon RDS to handle your database too which is handy (but can be slightly on the pricier side.)
So a way to think of it is:
Your EC2 instance: Get the OS set up exactly like you'd like it along with your web application - basically, get your static stuff all in place.
EBS volume: That can be mounted and can be used for things like user uploads.
RDS instance: This is a dedicated database server with no hassles. It's nice - I use a MySQL RDS and it automatically makes two daily backups, and is scalable like EC2 instances.
Amazon Web Service is a better approach at hosting your applications Jon. You have a basic understand of AWS but you need to know that you can also launch an instance that is persistent. Just launch an instance of a persistence AMI. Also you can install you database,webs server on the instance like a regular server. There is probably just minimal differences from running an Ec2 instance and a dedicated server. If you have any other questions you can contact me.

Resources