What PHP and Laravel are and how they work
PHP is a general-purpose interpreted scripting language, most often used on the web: the code runs on the server and the client receives only the result, such as HTML or JSON. Laravel is a PHP web framework with routing, the Eloquent ORM, Blade templates, queues and the Artisan console already assembled and configured.
Laravel is used in two ways. As a full-stack framework, it accepts requests and renders pages itself with Blade templates. As an API backend, it serves a single-page or mobile application. In both cases the framework takes care of the database, authentication, queues and mail. A one-off script, such as processing a file or running a cron task, does not need a framework: PHP runs it from the command line, without a web server or browser.
Every request follows the same chain. The web server, such as nginx, passes it to PHP over the FastCGI protocol, usually through PHP-FPM (FastCGI Process Manager). The application’s entry point is public/index.php. Service providers register the framework’s components, then the request passes through middleware to the router, which calls a controller. The response returns through the same middleware in reverse order.
PHP keeps no state between requests: global variables and open connections disappear with the response. The application keeps persistent data in the database, the session and the cache.
- The web server sends all requests to
public/index.php. The file loads the Composer autoloader and gets the application frombootstrap/app.php; the first thing created is the service container. - The HTTP kernel does the initial setup: error handling, logging and environment detection.
- Service providers set up the database, queues, validation and routing:
registeris called on all of them first, thenboot. Your own and third-party providers are listed inbootstrap/providers.php. - Middleware are layers around the application: the session, CSRF token verification, maintenance mode. Some run for every request, others only for their own routes.
- The router finds the matching route and calls a closure or a controller method.
- The response passes back through the route’s middleware, and the
sendmethod delivers it to the client.
What PHP provides and what Laravel provides
| Task | PHP alone | Laravel |
|---|---|---|
| Receive a request | the web server passes it to a script over FastCGI | a single entry point, public/index.php, and routes in routes/ |
| Render a page | PHP code inside the HTML, between <?php and ?> | Blade templates in resources/views |
| Work with a database | extensions such as PDO | Eloquent models in app/Models, migrations and seeders in database/ |
| Background work | command-line scripts run by cron | queued jobs in app/Jobs, the schedule in routes/console.php |
| Console commands | php followed by a script name | Artisan: php artisan list make shows only the generators (make:*) |
What to know beforehand
- HTTP: methods, status codes, headers and cookies — see the “HTTP and REST” reference.
- SQL: selecting data and joining tables — see the “SQL” reference. Eloquent writes queries for you, but you will still need to read them.
- The Linux command line: running commands and file permissions — see the “Linux” reference.
Section sources
the section is written from these pages- Request Lifecyclelaravel.com/framework/docs/13.x/lifecycle(opens in a new tab)
- What is PHP and what can it do?php.net/manual/en/introduction.php(opens in a new tab)
- FastCGI Process Manager (FPM)php.net/manual/en/install.fpm.php(opens in a new tab)
- Directory Structurelaravel.com/framework/docs/13.x/structure(opens in a new tab)
- Installation: Next Stepslaravel.com/framework/docs/13.x/installation(opens in a new tab)