Skip to content
Mail Cabinet Choose a plan

Server Configuration for Website Speed: Cache, PHP, Compression

Server Configuration for Website Speed: Cache, PHP, Compression

On the server side, a website gets faster mainly through five things: a server cache (Redis or Memcached), sensible PHP limits, GZIP or Brotli compression, database indexes and the right web server, plus monitoring that shows problems early. On shared hosting you can change part of this yourself (PHP values, .htaccess, indexes); the rest is only possible on your own server. Measure TTFB before and after every change instead of trusting promised percentages.

Below, each setting comes with a command to check it, the official default values and a table of what you can adjust yourself on shared hosting.

Server-level caching: ready responses from memory

Caching simply means keeping ready-made responses. Instead of building the same page again for every visitor or running the same query again, the server keeps the result in memory. Browsers and PHP cache too, but server-side caching works deeper.

The most common tools are Redis and Memcached: a buffer between the database and the site that serves repeated query results from RAM. How much this speeds up your site is something to measure: compare TTFB before and after enabling the cache with curl -o /dev/null -s -w "TTFB: %{time_starttransfer} s\n" https://your-site/. Google’s web.dev guide rates a TTFB of 0.8 seconds or less as good and over 1.8 seconds as poor (checked 30.10.2026).

Infographic: server configuration in 6 steps to a faster site

Where you enable the cache depends on your hosting. On shared hosting, Redis or Memcached are available only if the provider offers them as a service; you cannot install them there yourself. On your own server you install the service and then connect the application to it (in WordPress, through an object cache plugin).

  • Redis: more data structures (lists, hashes, sets) and optional persistence to disk
  • Memcached: a simpler, multithreaded key-value cache for strings and objects
  • Cache lifetime (TTL): depends on how often the data changes; rarely changed content can stay cached for hours, frequently changed data only for minutes
  • Memory limit: decide how much RAM the cache may use (maxmemory in Redis, -m in Memcached)

Check CPU load before and after enabling the cache, in the hosting panel or with top on the server. The more identical database queries the site makes, the bigger the effect.

PHP configuration: the parameters that matter

php.ini contains dozens of directives, but five of them cause most of the problems on CMS sites:

Parameter PHP default Example for a CMS site Why change it
memory_limit 128M 256M Large data sets and plugins; should be larger than post_max_size
max_execution_time 30 s 60-120 s Long scripts (imports, backups) are not cut off halfway
upload_max_filesize 2M 64M Uploading large files
post_max_size 8M 72M Must be larger than upload_max_filesize, otherwise large uploads fail
max_input_vars 1000 3000 Forms and menus with many fields are not truncated

The defaults and the size rules (upload_max_filesize smaller than post_max_size, post_max_size smaller than memory_limit) come from the PHP manual (checked 30.10.2026). The example column is a guide, not a norm: set what your site really needs and what your plan allows. The command php -i | grep -E "memory_limit|upload_max_filesize|post_max_size" or the phpinfo() function shows the current values. If errors already appear, see our guides to the Allowed memory size exhausted error and to increasing upload_max_filesize.

On shared hosting the main php.ini belongs to the provider. You usually change per-site values in the control panel, in a .user.ini file in the site root (when PHP runs via FastCGI or PHP-FPM, see the PHP manual on .user.ini files) or with php_value in .htaccess (when PHP runs as an Apache module), and only within the provider’s limits. memory_limit and max_execution_time can also be set in code with ini_set() (mode INI_ALL); upload_max_filesize, post_max_size and max_input_vars cannot (mode INI_PERDIR). By default PHP rereads .user.ini every 300 seconds (user_ini.cache_ttl), so a change can take up to 5 minutes to apply. On your own server you edit php.ini or the PHP-FPM pool and restart PHP-FPM.

Important: don’t change values blindly. Keep a copy of the original settings: one wrong value can take the whole site down.

Web server control panel with performance metrics and hosting optimization analytics

Compression: making text files lighter

Your site sends HTML, CSS and JavaScript to the browser. Text compresses well: the server shrinks the files before sending them, and the browser unpacks them without the user noticing. This is GZIP or Brotli compression.

If Apache with mod_deflate serves the site, a few lines in .htaccess are enough (this enables GZIP; Brotli in Apache is a separate module, mod_brotli):

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
</IfModule>

If Nginx serves the responses (on its own or as a proxy in front of Apache), .htaccess does not control compression: it is set in the Nginx configuration. According to the documentation on nginx.org, the gzip directive is off by default, and Brotli is not one of the standard Nginx modules. On shared hosting this is up to the provider; on your own server you switch it on yourself.

How much smaller the transfer gets depends on your files, so check it yourself. The command curl -sI -H "Accept-Encoding: gzip, br" https://your-site/ | grep -i content-encoding should return gzip or br. If the line is missing, compression is not working.

gtmetrix.com and pagespeed.web.dev also show file sizes and flag uncompressed resources.

Database optimization: indexes and slow queries

The database is the heart of every dynamic site and often the very thing that slows it down. The usual cause is missing indexes: structures that let the database find rows without reading the whole table.

Imagine a library without a catalog: the book is there, but you have to search every shelf. With an index, the database knows exactly where to look.

What to do:

  1. Open phpMyAdmin or another database management tool.
  2. Check whether columns often used in searches and joins (ID, user_id, status) have an index.
  3. After deleting many rows, run OPTIMIZE TABLE table_name;. For InnoDB tables, MySQL then recreates the table and updates its statistics (ALTER TABLE … FORCE plus analyze); the MySQL manual notes that most setups do not need it at all, so it is not a routine task.
  4. Delete leftover tables from removed plugins and old versions (make a backup first).
  5. Turn on the slow query log and see which queries take too long. It is off by default, long_query_time is 10 seconds, and enabling it at runtime requires the SYSTEM_VARIABLES_ADMIN privilege. On shared hosting only the provider can enable it; on your own server you set it in the MySQL configuration.

The bigger the table, the more a missing index hurts: a query that was instant on a small database can slow down the whole site on a large one.

Nginx or Apache: which web server to choose

Apache is the older, universal server with flexible per-directory configuration (.htaccess). Nginx is younger, event-driven and serves static files with less memory, but has no .htaccess and is configured on the server.

In simple terms:

  • Apache: with the prefork MPM it runs one process per connection, while the default event MPM uses threads (Apache documentation); flexible and good for complex configurations
  • Nginx: asynchronous architecture, one worker process serves thousands of connections, fast with static files
  • The choice depends on the load: a small blog does fine with Apache, while with many concurrent connections Nginx uses memory more sparingly. A common compromise is Nginx in front of Apache.

If you move fully to Nginx, you will need to rewrite mod_rewrite rules in Nginx syntax. It is not hard, but it takes time.

Criterion Apache Nginx
Architecture Processes (prefork) or threads (worker, event) Asynchronous, thousands of connections per worker process
Memory use Higher Lower
Strength Flexible configuration, .htaccess Fast delivery of static files
Configuration Universal, mod_rewrite rules Rules must be rewritten in Nginx syntax
Best for Small sites, complex per-directory rules Many concurrent connections

On shared hosting the provider chooses the web server; you only configure what .htaccess and the panel allow. The choice between Nginx and Apache is yours on your own server.

Monitoring: spotting problems before customers write to you

Server configuration is not something you set once and forget. After every change, and regularly afterwards, watch these values:

  • CPU and RAM: if CPU keeps hitting the plan limit, the site slows down and may answer with a 504 Gateway Timeout error
  • Disk space: when the disk is almost full, the database can no longer write new data
  • Database queries: track slow queries in the logs
  • Uptime: an external service such as Pingdom tells you if the site went down at night

Control panels such as cPanel and Plesk show disk and traffic usage; Google Cloud Monitoring and Datadog suit larger projects. Which metrics matter and how to set up alerts is covered in our guide to hosting monitoring.

The main point: optimization is ongoing work. Change one thing, measure, then take the next step.

What you can change on shared hosting and what needs your own server

This table answers the most common question. Shared hosting means the provider manages the server. Your own server (a VPS or a dedicated server) means you manage everything yourself.

Setting Shared hosting Own server (VPS)
PHP values (memory_limit etc.) In the panel, via .user.ini or .htaccess, within the provider’s limits php.ini and PHP-FPM pool, any values
GZIP/Brotli compression Via .htaccess if Apache serves the site; otherwise set by the provider Full control: Apache modules or gzip in Nginx
Redis / Memcached Only if the provider offers it Install and configure yourself
Indexes, OPTIMIZE TABLE Yes, for your own databases in phpMyAdmin Yes
Slow query log No, needs server-level privileges Yes, in the MySQL configuration
Nginx or Apache Chosen by the provider Your choice
Monitoring Panel statistics plus an external uptime check Any tools, including agents on the server

RichHost hosting plans run on NVMe disks with our own control panel and its AI assistant, with servers in Europe and the USA, from $8 a month. If your site runs on WordPress, also see how to speed up WordPress.

FAQ

What are the PHP defaults for memory and uploads?

According to the PHP manual: memory_limit 128M, max_execution_time 30 seconds, upload_max_filesize 2M, post_max_size 8M, max_input_vars 1000. Your provider may set other values; phpinfo() shows the actual ones.

Can I enable Redis on shared hosting?

Only if the provider offers Redis or Memcached as a service. Otherwise use page caching at the CMS level or move to your own server, where you install Redis yourself.

Should I run OPTIMIZE TABLE regularly?

No. On InnoDB the command recreates the table, and the MySQL manual recommends it only when space is really wasted, for example after deleting many rows.

How do I know compression is working?

Run the curl command from the compression section: the content-encoding header must show gzip or br.

What TTFB is good?

Google’s web.dev guide rates 0.8 seconds or less as good and more than 1.8 seconds as poor. Measure several times and from the region where your visitors are.

How we checked. On 30.10.2026 we checked the PHP defaults and changeable modes (directive tables and the .user.ini page in the PHP manual), OPTIMIZE TABLE, the slow query log and the privileges for SET GLOBAL in the MySQL 8.4 manual, the gzip directive in the nginx.org documentation, the MPMs in the Apache HTTP Server 2.4 documentation and the TTFB thresholds in Google’s web.dev guide. There was no test on our bench for this article, so we give no speedup percentages: measure the effect on your own site with the commands above.

More on this topic

All articles
How to Connect via SSH from Windows, macOS and Linux: Step by Step
Hosting Guides and Tutorials27.09.2026

How to Connect via SSH from Windows, macOS and Linux: Step by Step

A step-by-step guide on how to connect via SSH from Windows, macOS and Linux with the terminal or PuTTY, set up key…

Swap and the OOM Killer: How Much Swap You Need and Why MySQL Dies
Hosting Performance14.06.2026

Swap and the OOM Killer: How Much Swap You Need and Why MySQL Dies

How much swap a server needs, what swappiness means and why the OOM killer kills MariaDB instead of PHP: a cgroup test…

Cron Jobs on Web Hosting: How to Set Up and Fix Common Errors
Hosting Guides and Tutorials12.06.2026

Cron Jobs on Web Hosting: How to Set Up and Fix Common Errors

How to add a cron job in the panel or with crontab, why a command works over SSH but fails in cron,…