A slow Laravel script on shared hosting is usually slow for a fixable reason: uncached config, a database query running hundreds of times per page, or a host that gives your site very little CPU. Find which one it is before you change anything, then fix that one thing first.
We say that because the common advice — "just add caching" — helps only when caching is the actual problem. If the real cause is a missing database index, caching hides it for a while and the site slows down again as data grows. This guide walks through the checks in the order we run them, from the free five-minute fixes to the point where the host itself is the answer.
How do I know what is actually slow?
Guessing wastes time. Before you touch code or settings, measure where the seconds go. A page that takes six seconds to load might spend five of them on one database query, or it might spend five seconds waiting for the server to start PHP at all. Those are different problems with different fixes.
The cheapest tool is the Laravel log and the browser. Load the page, note the time, then check storage/logs/laravel.log for slow query warnings or errors. If your script has query logging available, enable it for one request and look at how many queries ran and how long each took. One page running 200 queries is a code problem. One page running 5 queries but still taking six seconds is a server problem.
If you have access to install packages, Laravel Debugbar shows the same information in the browser: query count, query time, memory use and route time. If you cannot install anything, add a simple timer around the slow part of the page and write the result to the log. It is rough, but it tells you whether the delay is in the database, in a remote call, or in rendering the view.
Also check whether the slowness is constant or comes and goes. A site that is fast at 3 a.m. and slow at 8 p.m. is sharing a busy server with other sites. A site that is always slow has a problem of its own. That one observation saves a lot of pointless optimisation.
Is caching the first fix, and which caches matter?
On shared hosting, caching is the highest-value fix because it costs nothing and the gains are immediate. Laravel has four caches, and each one removes a different piece of repeated work.
| Cache | Command | What it saves |
|---|---|---|
| Config cache | php artisan config:cache | Reading and parsing .env and config files on every request |
| Route cache | php artisan route:cache | Rebuilding the route list on every request |
| View cache | php artisan view:cache | Recompiling Blade templates on every request |
| OPcache | Enabled in PHP settings | Recompiling PHP files on every request |
Run the first three from your project folder after every deployment or .env change. They are safe on a finished site, and the difference on a slow shared host is often obvious — pages that took two seconds drop well under one. Just remember the rule: after you change .env, run php artisan config:clear, then cache again. A cached config ignores .env completely, which is how people end up debugging a setting they already fixed.
OPcache is different because it is a PHP setting, not a Laravel command. Many shared hosts enable it by default, but some do not. In cPanel, check the PHP settings or ask your host whether OPcache is on for your account. If it is off, turning it on is usually the single biggest free speed win available — PHP stops recompiling every file on every request.
One warning: do not cache routes or config while you are still developing the site. Cached values ignore your edits, and you will spend an hour debugging a change that was never loaded. Cache when the site is finished, clear when you are working on it.
What database fixes help a slow Laravel script most?
Most slow Laravel pages are slow because of the database, and most database slowness comes from two causes: missing indexes and the N+1 problem. Both are cheap to fix once you see them.
The N+1 problem is the classic one. Your code loads a list of 50 orders, then for each order it runs a separate query to fetch the customer. That is 1 query plus 50 more — 51 queries for one page. Eager loading fixes it: load the related records in one query with the with() method, and the page drops from 51 queries to 2. If your query log shows the same small query repeating dozens of times with different IDs, you are looking at N+1, and eager loading is the fix.
Missing indexes are the other half. A query that filters or sorts by a column without an index forces MySQL to scan the whole table. On a table with a hundred rows nobody notices. On a table with a hundred thousand rows, the page crawls. Add an index to the columns you filter, sort and join on most often — foreign keys and status columns are the usual suspects — and the same query can go from seconds to milliseconds.
Two more habits help a lot on shared hosting. First, paginate long lists instead of loading everything: showing 20 records per page instead of 2,000 is an instant win. Second, select only the columns you need instead of SELECT * — fetching ten columns you never display is wasted work on every request. And if your script sends email or calls an external API during the request, move that work to a queue so the user is not waiting on it.
Should heavy work run in a queue instead of the request?
Yes, whenever it can. A web request should do the minimum: save the data, show the result, and finish. Anything slow — sending email, generating a PDF, calling a payment gateway, resizing images — belongs in a queue job that runs in the background.
On shared hosting you cannot always run a queue worker the way a VPS can, but most Laravel scripts on cPanel can use the database queue driver with a cron job that runs php artisan queue:work --stop-when-empty every minute. It is not as fast as a dedicated worker, but it moves slow work out of the user's request, and the user notices the difference immediately. Our guide to setting up cron jobs on cPanel shows how to wire that up.
The same thinking applies to scheduled tasks. If your script runs a heavy report or cleanup job inside a web request, move it to the scheduler. A job that takes thirty seconds is fine at 3 a.m. and terrible at 3 p.m. in the middle of a checkout.
What about images, assets and the front end?
Not all slowness is in PHP. A page can have a fast server response and still feel slow because it loads three megabytes of uncompressed images and a dozen JavaScript files.
- Compress images before uploading them, and serve them at the size they are actually displayed — a 4000-pixel photo shown at 400 pixels is wasted bandwidth.
- Combine and minify CSS and JavaScript where your build tools allow it, so the browser makes fewer requests.
- Turn on gzip or Brotli compression in cPanel if your host offers it, so text files travel smaller.
- Use browser caching headers for images and assets, so returning visitors do not download them again.
- Check the page in your browser's developer tools, on the Network tab, and sort by size — the biggest files are usually the easiest wins.
This is also where a content delivery network helps, but on a small site it is optional. Fix the images and the caching first; those two cover most of the front-end delay.
When is the host itself the problem?
Sometimes you do everything right and the site is still slow. On shared hosting, that usually means the server is oversold: hundreds of sites sharing one machine, each getting a thin slice of CPU and memory. The signs are consistent — the site is fast at night and slow in the evening, response times jump around for no reason, and simple pages take seconds even with every cache enabled.
Before you blame the host, rule out your own code with the checks above. A host will not fix a slow query for you, and moving a broken script to a faster server just makes the same mistake run faster. But once the caches are on, the queries are indexed, the lists are paginated and the heavy work is queued, and the site is still slow — that is a hosting problem, and no amount of code tuning will fix it.
At that point the honest options are a better shared plan, a VPS, or a host that gives PHP more resources. We have seen scripts go from four seconds to under one second with nothing but a move to a less crowded server. If you are not sure whether your host is the bottleneck, compare the same script on a quiet hour versus a busy hour. A big gap between the two is the host talking.
If your script is not just slow but broken after an install or upload, our 9 common errors guide and the 500 error checklist cover the usual causes, and the cPanel installation guide walks through a clean setup from scratch. You can also browse the full catalogue — every product ships with full unencrypted source code and an installation guide — If you are still stuck, our support is a real human on WhatsApp at +92 333 4916432, or by email at contact@zqdevelopers.com.