![A screenshot of a terminal window running a Drupal project with the Symfony local server](/images/blog/running-drupal-with-symfony-local-server/terminal.png)
Even though it’s by Symfony, the local webserver works with any type of
project - including Drupal 8 (and 9) and Drupal 7.
## Getting started
Here are the basic commands to start and stop the server:
```bash
# Alias for server:start, starts the server
symfony serve
# Run the server in daemon mode (in the background)
symfony serve -d
# Display the status of the server
symfony server:status
# Stop the server
symfony server:stop
```
If your Drupal files are within a `web` or `docroot` directory, it will
automatically be used as the document root for the server, so files are served
from there if you run the serve command.
If you use a different subdirectory name - one that isn't loaded automatically -
you can use the `--document-root` option:
```bash
symfony serve --document-root www
```
## Different PHP Versions
One of the most useful features of the Symfony server is that it
[supports multiple versions of PHP](https://symfony.com/doc/current/setup/symfony_server.html#different-php-settings-per-project)
if you have them installed, and a different version can be selected per
directory.
This is done by adding a `.php-version` file to the root of the project that
contains the PHP version to use. For example:
```bash
echo "7.3" > .php-version
```
Next time the server is started, this file will be read and the correct version
of PHP will be used.
If you’re using macOS and want to install another version of PHP, you can do it
using Homebrew:
```bash
# Install PHP 7.3
brew install php@7.3
```
[Further PHP customisations can be made per project](https://symfony.com/doc/current/setup/symfony_server.html#overriding-php-config-options-per-project)
by adding a `php.ini` file.
## Securing Sites Locally
The Symfony server allows for serving sites via HTTPS locally by installing its
own local certificate authority.
If it’s not installed automatically, run this command to install it:
```
symfony server:ca:install
```
Now any site will be served via HTTPS by default, and any HTTP requests will be
automatically redirected.
If you need to run a site with just HTTP, add the `--no-tls` option to the
`serve` command.
## Adding Databases (and other services) with Docker
The Symfony server has an integration with Docker for providing extra services -
such as databases that we’ll need to install Drupal.
This is my `docker-compose.yaml` file which defines a `database` service for
MySQL:
```yaml
version: '2.1'
services:
database:
image: mysql:5.7
ports: [3306]
environment:
MYSQL_ROOT_PASSWORD: secret
volumes:
- mysql-data:/var/lib/mysql
volumes:
mysql-data:
```
Because port 3306 is exposed, the server recognises it as a database service and
automatically creates environment variables prefixed with `DATABASE_`.
A list of all the environment variables can be seen by running
`symfony var:export` (add `| tr " " "\n"` if you want to view each one on a new
line, and `| sort` if you want to list them alphabetically):