Lesson 1.1: How a request is served
An installed Exponential is a directory of PHP files. Something must accept connections, speak HTTP and HTTPS, hand out static files and pass every other request to a front controller. This lesson gives learners the map they need for the whole course: the four ways to serve a site, the one routing rule list they all share, and a quick check that shows whether a server really applies it.
Warning
.htaccess slows down every request. When .htaccess files are enabled (AllowOverride anything but None), let alone
used, Apache looks for them and reads and evaluates them on every request, in every directory of the path, and
page loading times go up drastically (measured). The only real fix is to switch the feature off for
the virtual host: AllowOverride None in the HTTPS virtual host, and the rules in the virtual host's own
configuration as mod_rewrite rules. That is far faster in production speed tests and well worth the time it takes
to optimize a production configuration. Switch over right away: copy the rules of the
example HTTPS virtual host into your virtual host (with the static cache, also
staticcache_offload.conf), set AllowOverride None, run apachectl configtest, reload Apache and
test the site. The same rules for other servers: nginx, LiteSpeed,
Caddy, IIS, Velocity (built in); where virtual host rules go in a control
panel: Plesk, cPanel, DirectAdmin, ISPConfig.
On LiteSpeed or OpenLiteSpeed, the server's own page cache can also answer anonymous visitors and crawlers without PHP: Page caching with LiteSpeed and OpenLiteSpeed.
Note
Every exercise in this course runs on the learner's own training installation or virtual machine, never on a live customer site.
At a glance
| Course | Hosting and operations |
| Module | Module 1: Serving the site |
| Duration | 40 minutes (20 presenting, 20 exercise) |
| Level | Intermediate |
| Audience | System administrators and hosting support staff |
| Prerequisites | A training installation per learner, served on the learner's machine (see One installation per learner); a terminal with curl |
Learning objectives
After this lesson, learners can:
- name the four ways to serve a site (Velocity with the
qbixengine, FrankenPHP through Velocity, Apache with PHP-FPM, nginx with PHP-FPM) and say which one the project recommends; - explain why the document root is the installation root;
- describe what happens to a request for a dot file, a PHP file below the root, an asset and any other path;
- check with four
curlrequests that the routing rules are active on a server.
Trainer's notes
How to present it
Source: Chapter 8: Serving the site, sections 8.1 and 8.2.
- The choice in one table (6 minutes). Put the table of section 8.1 on the projector. Point out three rows:
Separate web server needed (no for Velocity and FrankenPHP), Application kept in memory between requests
(only Velocity) and Suits shared hosting (usually only Apache with PHP-FPM). Velocity's
qbixengine is the recommended way at every stage; FrankenPHP is a production-ready alternative; Apache and nginx with PHP-FPM are the traditional setups. - When to choose a traditional server (4 minutes). From section 8.1: hosting that forbids long-running processes, a tuned Apache or nginx the customer wants to keep, or customers that need operating-system isolation from each other. (A machine with only PHP 8.0 is no longer on the list: Velocity runs on 8.0 from its release 0.0.4.54.)
- One routing list (6 minutes). Draw the diagram of section 8.2. The rules are written down once in
.htaccess_root; Velocity's engines and the generated FrankenPHP configuration implement the same list. Stress the two security consequences: no PHP file runs because its path was asked for (except the front controllers at the root), and a file outside the asset list is never handed out. - The check (4 minutes). Show the four
curlrequests from section 8.2 against your own training site and explain each expected answer.
Common questions
Why is the document root not a public/ directory? The installation root is the document root under every
server; the routing rules decide what is reachable. A 404 for every asset under design/ is the sign that the
document root is set wrong.
Can I use PHP's built-in server? It is the third Velocity engine (php) and the shipped default only because it
needs nothing installed. It has no TLS and is for development, not for visitors.
Can two servers serve the same files? Yes. Velocity beside Apache during a migration is a common shape; the file ownership rules of section 8.7.2 then matter (lesson 1.2).
Where are the rules for nginx? The project ships none; chapter 8 gives a derived server block, translated rule
for rule from .htaccess_root (lesson 1.2).
Pitfalls
- A
200for/.git/config. The rules are not active: Apache without.htaccessorAllowOverride, or an nginx block that is not the chapter's. Stop and fix it before anything else; this is the most important result of the lesson. Under Apache,./console exp:setup:statusshows at once whether.htaccessexists and which template it is a copy of (Setting up .htaccess and config.php from the console). - Wrong port. Learners copy
127.0.0.1:8088from the book while their site runs elsewhere. Have them runphp bin/php/console exp:velocity statusfirst; it lists every address as a full URL. - The qbix engine answers 403, not 404, for dot paths. Both mean the file was refused.
Hands-on exercise
Use your own training installation, served on your machine (for example with
php bin/php/console exp:velocity start after exp:install, see
The console install).
In a terminal, change to the installation root (the directory that holds
index.php).Run
php bin/php/console exp:velocity statusand note the address of the site.Open
.htaccess_rootin a text viewer (less .htaccess_root). Find the rule for dot files and the final rule that sends everything else toindex.php.Request a dot file, replacing the address with your own:
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8088/.git/configRequest a kernel source file:
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8088/kernel/classes/ezcontentobject.phpRequest
robots.txtthe same way and note the code.Ask for the settings file and count whether its content came back:
curl -s http://127.0.0.1:8088/settings/site.ini | grep -c '^\[DatabaseSettings\]'Request a stylesheet path from the site's front page (copy one from the page source) and check that it answers
200.Write down, in one sentence each, what happened to the requests of steps 4 to 8 and why.
Expected result
- Step 4:
404(or403from theqbixengine). - Step 5:
404; the PHP file was neither run nor sent. - Step 6:
200when the file exists. - Step 7:
0: the request reachedindex.php, which answered with a page, not the file. - Step 8:
200for a listed asset path. - The trainer checks by asking two learners to read their codes aloud and explain the step 7 result.
Quiz
- Which way of serving a site does the project recommend for every stage?
A. Apache with PHP-FPM B. nginx with PHP-FPM C. Velocity with the
qbixengine D. PHP's built-in server - What is the document root of an Exponential site?
- A request for
/settings/site.inireturns the file's contents. What does that tell you? - Name two reasons to choose Apache or nginx with PHP-FPM instead of Velocity.
- True or false: a
.phpfile inside an extension's design directory runs when its path is requested.
Answers
- C. Chapter 8 calls Velocity's
qbixengine the recommended way at every stage. - The installation root, the directory that holds
index.php(section 8.2). - The routing rules are not active; fix the server before the site is reachable from outside.
- Any two of: hosting that forbids long-running processes, an existing tuned server, operating-system isolation between customers (section 8.1).
- False. Scripts and dot paths are never served or run below the root, even in a listed asset directory.
Further reading
- Chapter 8: Serving the site: the reference for this module.
- Choosing a web server: the decision guide for hosts.
- What hosting Exponential involves: the bigger picture for hosting staff.
- Requirements at a glance: PHP and extension requirements.
- Setting up .htaccess and config.php from the console: which
servers read
.htaccess, and the commands that put it into place.
Related pages
- Module 1: Serving the site
- Hosting and operations: course overview
- Trainers: start here
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.