Please Help me Host/Manage my PHP MySQL website

Please Help me Host/Manage my PHP MySQL website
0

Hey there!
This September, I was learning PHP and as a side project, I made a small PHP website. This PHP website is kind of VIRAL nowadays and I am having a tough time managing it.

I even got a job opportunity because of it -

Here’s the link - Quizprank
Previously I used a free hosting service googihost, but it could not handle much traffic 300+ Realtime users would result in 503 error.

So I switched it to Digitalocean because I got 50$ free credit.
Current server configuration - Shared CPU 4 vCPUs 8 GB RAM 50 GB Storage 5 TB Data Transfer

I am running Apache2 server and MySQL server on it.

The RAM utilisation is like 10%
but
The CPU utilisation is like 95%+

Currently, my website can never go past 250 page views per minute, Any more request will probably Overload my server. The main problem is every request require at least one SELECT query to run in MySQL and MySQL can’t handle much stress.

Can anyone help if I show you exact config file for MySQL and Apache2?

I tried using a config from StackOverflow into MySQL but it reduced the performance further.

I am currently using Cloudflare to cache most of the static content to reduce the load on my server. And Cloudflare firewall is also helping me to block all the known bots like - Googlebot, Applebot, Twitterbot etc. because they also overwhelm my server during the peak hours.

But these things don’t help.

I’m not web server expert, but have some experience building scalable web services.

When it comes to dealing with any issue, its good to first understand the problem as much as possible. In this case it sounds like your bottleneck is your database and web server CPU utilization once the server is scaled.

Digital ocean is awesome in that you can do anything with it, but then the question comes up of what you should. It sounds like your Apache server is having a tough time scaling to meet demand for higher. There could be any number of reasons why this is an issue, from your code to apache not being able to keep up with all the connections. The easiest problem is your code doesn’t scale well enough, this leads to the other problem you already state. Your database sounds like a bottleneck. You have a few choices when it comes to optimizing your database.

  1. Optimize your database queries if they aren’t optimal. Having multiple joins and or loading large amounts of data will result in the DB slowing down as its performing too much work.
  2. Your database needs to be scaled vertically (adding more power/CPU to the same machine). I’m not sure what size/scale your currently running at or how, if you should scale horizontally but it is an option.
  3. Optimize your code to not call the DB as much. I’m not sure why you need to call the DB ever single request, but if your checking something that doesn’t change often, like the user’s credentials or something, you might be able to get-away with an in-memory cache, in code or using something like redis

Its hard to provide magic configs/code that solves any problem for any given situation when the problem is broad. If you provide more details, and or isolate the problem to more specific areas of the code/setup you might be able to get more help. I believe focusing on what you already know about the pain point should be good enough to get you going on fixing those problems. :slight_smile:

Good luck!

PS. I talked with someone that was able to handled several thousand requests per minute on the smallest Digital Ocean droplet. This was possible due to not having a database to connect to, and building it in such a way it could handle a lot of concurrent connections.

I personally would use nginx over apache, but I also don’t use PHP so I’m not sure if this would be a potential pain point.

Thanks a lot brad! I will try optimizing my PHP code and use Redis to cache everything!

Thanks again