Scaling Apache, MySQL & PHP

Overview of Scaling your Apache PHP MySQL Hosted website

This is a short post on the basic principles of scaling your Apache PHP MySQL based hosted website.

Scaling your website isn’t as simple as introducing a new web server.  It is easy to upgrade the hardware however, there are the issues associated with migrating the website to the new hardware, such as coding for new versions of software and coordinating an IP address change.  Your Apache PHP MySQL host may not be able to provide the same IP address.

There are several routes one can take when considering scaling PHP MySQL hosting websites.

Step 1: Split the Apache PHP and MySQL functions

If your current server is running both Apache PHP and MySQL, the first step is to split them onto their own dedicated server. This should have the effect of reducing load on the Apache PHP web server by about 50% depending on the amount of work the MySQL server is performing. To do this will require a change of the MySQL connection parameters (as long as you have coded your website this way). Having a cross over cable between to two servers provides a dedicated 1Gb interface rather than running across a LAN switch.
Total number of servers 2.

Step 2: Load balance the Apache PHP Web front end

Introducing a hardware load balancer to the solution will provide a method of distributing web traffic to two or more web servers.  The load balancer should take care of persistence and redundancy. If one Apache PHP web server crashes, the load balancer will only direct traffic to the remaining live Apache PHP servers.  In this scenario,  you will have to ensure the remaining web server(s) can adequately cope with the traffic.
Additional web servers will need to be configured to mirror existing web servers.  Static files, user account, web configuration files and software versions must match, otherwise you will have inconsistency which will be difficult to troubleshoot.
Total number of servers 4 – Load balancer, 2 web servers, 1 database.

Step 3: Network File Server

If additional web servers are required then the management of static files across multiple web server becomes unmanageable.  A network file server provides a single point for the static assets of your website. Using a NFS (Network File System) server you are able to “mount” the NFS partition on to each web server. This provides a method for your web servers to read and write to a central location.  There are generally two types of solution for the file server – NAS and SAN. A NAS (Network Attached Storage) is a server with more than 2 drives, configured as large disk.  A SAN (Storage Attached Network) is a more complex device with space for many disks and no single points of failure. As such a SAN is more expensive than a NAS.
Total number of servers 6 – Load balancer, 3 web servers, 1 database, 1 NFS

Step 4: Additional Database servers

By this stage the web servers are managing the web traffic.  However, the database server may start to have performance problems. One solution is to increase the server specification. Installing additional RAM is the first solution, but this is only a temporary measure and the database is still a single point of failure.  There are several options at this stage for scaling the database.

i) Add a replicated MASTER/SLAVE MySQL server and change your code to perform reads from the SLAVE and writes to the MASTER. This has the affect of reducing overall load on the database but doesn’t help if there is a failure of the MASTER unless the application takes this into consideration and switches to the SLAVE (which then becomes a single MASTER).

ii) Add a replicated MASTER/MASTER MySQL server and change your database structure to have odd and even indexes.  In a Master/Master set up, both servers are able to function for reads and writes. However, as data is replicated between the server you cannot have duplicate records, hence changing the database structure to prevent this.

iii) Add a MemCache server. Not exactly a database solution, but this would ease the pressure from the database and therefore give you more time to decide on the final solution.

iv) MySQL Cluster.  With this solution, no code changes are required but the database table types will need to change which can cause complications.

Total number of servers 7-9 – Load balancer, 3 web servers,  2-4 database server, 1 NFS

« | Home | »

  • Call us

    Switchboard:
    Tel: 0845 4210444

    Sales:
    Tel: 0845 4210440
  • Get in touch

    Your Name (required)

    Your Email (required)

    I am interested in
     Hosting Support Training

    Your Message

  • Join our mailing list

    To receive our latest Whitepapers free of charge and direct to your inbox on a fortnightly basis, sign up to our mailing list.
  • Training offer

Xen solution meets e-commerce demand

“A lot of hosting companies talk about 99.999% SLA, this means nothing if their support fails to deliver but with ForLinux’s support you know you’re in good hands. I’ve just checked one of our older servers that’s due to be replaced this year, it’s uptime is 902 Days! Needless to say ForLinux will be handling the upgrade.” Ashley Peake, Technical Director, Rapid Web Ltd.

Proactive monitoring service is crucial

“The proactive monitoring service that ForLinux provide is crucial to our business. When a problem occurs, the ForLinux team ring us with a potential solution, which they are ready to work on straight away”. Sam Phillips, Technical Director, Setfire Media.

“The level of support ForLinux offer is very high”

“The ForLinux team are very knowledgeable and there is always someone who can deal with the problems and errors we incur. I wouldn’t dream of hosting my dedicated server alone, without that extra support”. Chris Chaplow, Managing Director, Andalucia.com

“ForLinux are a world apart”

“Compared to other hosting and support companies we have dealt with, ForLinux are a world apart. In our experience the level of service provided by ForLinux is very high”. Alan Taylor, Managing Director, Blue Chip Vacations

Understanding “Support”

“Thanks for your help. If only all the companies we deal with understood what “support” means as well as you do.” – Mike Busuttili, Webmaster, Eaton Publications.

“Five year partnership speaks for itself”

“They’re very good at being proactive rather than reactive. The five years of partnership pretty much speaks for itself. And it has been improving all the time, so satisfaction levels are still high. The price is surprisingly good as well for the kind of industry they’re in, so that’s another plus point. ” Danny Ramdenee, Head of IT, Insurancewide

“Application uptime is above 99.98%”

“The ForLinux organisation appears the perfect size to perform its function well, it is large enough not be reliant on one or two people but small enough to ensure that, as the customer, you know the technical staff and they know you. I have great confidence in the technical competence of the ForLinux team.” – John Latham, Managing Director, Cognovi.

“Customer service is phenomenal”

“I respect the service that the company provide & it is nice to finally find a hosting company that operates in the same way as we do, in terms of ethos. It sounds like a cliché but the Customer service really is phenomenal!” – Stafford Sumner, Managing Director, Jarrang.

Deploying virtual servers on Amazon

Creating a Linux Server in the Cloud
Technical Director of ForLinux Ltd, Steve Nice, recently wrote an article for .Net Magazine, which demonstrates how to set up an Amazon Web Services EC2 Instance, running Linux and Apache.
The feature contains a step by step tutorial guide to installing and deploying virtual servers on the Amazon EC2 network [...]

Scaling Apache, MySQL & PHP

Overview of Scaling your Apache PHP MySQL Hosted website
This is a short post on the basic principles of scaling your Apache PHP MySQL based hosted website.
Scaling your website isn’t as simple as introducing a new web server.  It is easy to upgrade the hardware however, there are the issues associated with migrating the website to [...]

Amazon Cloud EC2 Pricing Summary

Amazon Cloud EC2 Pricing Summary
Amazon Web Services (aka EC2, Amazon Cloud Computing, AWS) provide you with the ability to create virtual servers and only pay for them while they are in use. The virtual servers (known as Instances) can be various sizes ,in terms of CPU, RAM and temporary disk space. Disk space is temporary, [...]

Tomcat Apache

ForLinux Dedicated servers are supported by Linux Professionals who will be able to assist you in configuration and installation of Tomcat.  Complete the contact form on the right to discuss the best options for your hosting.