How to build a scalable web application

We often develop web application without proper planning or architecture and finally at some point of time a scaling becomes impossible or spend a considerable amount of effort in terms of manpower and cost.
I am not a DBA or Developer so I will be excluding those side, still I think this can be a basic of any scalable application.
Traditional Applications
For a normal web application everything may be hosted on a single server or may at least database on a separate server. Database may have mirroring features as well and web servers also may have file replication to another location as backup. This is the easiest method to build a web application, unfortunately we are not thinking if there will be growth in future.
Suppose the website get an unexpected traffic (website becomes more popular) and at this time to improve the performance we have two options.
1) Upgrade the web server to next level or to the maximum possible
2) Upgrade the database server to next level or to the maximum possible
In both these cases there are certain limit and beyond that no upgradation is possible
A simple architecture for scalable web application
For every application you develop, make sure it is well optimized both scripts and database queries. There is no meaning on upgrading the hardware on bad code
Web application
For a website there are two elements normally, Scripts/static contents and dynamically created files. Scripts can be PHP, any other language prefer. I managed to host application which are developed in and PHP. This plan will be based on PHP & MYSQL Concept. You can think of better Database server (non SQL) if you really plan to build a perfect application.
Web application URL:
Document root: /home/
Also it is assumed that the content of public_html folder will be fixed or it is being updated by some automation tools.
We know that the application will dynamically generate files such as images, videos, pdfs, docs etc. I assume that my application will grow larger in few years and I will have millions of active users. We need to think well to choose the desired architecture as the dynamically created files will be too many and it will be huge in few years when there are millions of users. The best way is to keep these files on to separate locations. We can consider below options:
1) If you are using Amazon you can use Amazon S3
2) If you plan to use Azure you can use Azure Blob storage.
In all cases we need to set some limits on storage. For example let’s say 1 storage location will be used by certain number of users. For example 1TB storage for 1000 Users.
There can be a few table sin database like this
storage_master–>  storage_id, url, capacity
user_storage –> user_id – storage-id
This will ensure that we are not storing all files on to a single storage. The reasons is that there may be limit on storage.
If you are not going to choose Amazon or Azure you can manage it using dedicated servers as well. You will need to create multiple servers and these will act as storage device. You can name each of these servers as, etc. .
Database Scaling
Don’t keep every data on to a single database. Consult a DBA, split the database on to multiple DBS. Once DB structure is fixed you can add multiple slave databases and adjust the script to route all read operation to slave database servers.