In simple terms, to horizontally scale a PHP application means adding more servers instead of upgrading the existing servers.

However, to technically achieve that, your PHP application must be ready for the scale. In this article, we share 3 rules of thumb to make your PHP application ready for a horizontal scale.

Table Of Content

  1. Remote database connection
  2. Centralised file storage
  3. Centralized session storage
  4. The end
Remote database connection

When the database server is sitting independently, we do not have to worry about breaking our database while upgrading our web servers. Hence our PHP application must allow remote database connection.

It is recommended to use PDO when working with a database in PHP. And PDO supports remote database connection out of the box.

Centralised file storage

File uploads are commonly stored in a web server, however, this can cause a major issue when scaling web servers horizontally, since common approaching is to remove the old server and migrate to a new server.

So files must be stored in a centralized location. There are cloud storage services such as Amazon S3, Azure Storage, and Google Storage. All of them are a good fit for centralized file storage.

Centralized session storage

Almost every PHP application involves user authentication and most of the authentication in PHP is using session storge.

In PHP, We use the file as session storage by default. It is out of the box and it is super handy to pick up, we almost have to do nothing. However, it comes with a huge trade-off. When you migrate a web server to a new one, you lose all your users' sessions instantly.

To scale PHP application horizontally in peace, your session storage must be centralized. Cloud services such as Amazon DynmoDB and Amazon ElastiCache can be used as centralized session storage.

The end

We hope you find this article tutorial and make your PHP application horizontal scale ready!