Update Symfony server post
This commit is contained in:
parent
a43d1059ef
commit
826bc6808f
|
@ -1,5 +1,6 @@
|
||||||
---
|
---
|
||||||
title: Running Drupal 8.8 with the Symfony Local Server
|
title: Running Drupal 8.8 with the Symfony Local Server
|
||||||
|
excerpt: Running Drupal 8.8 with the Symfony Local Server
|
||||||
date: ~
|
date: ~
|
||||||
tags:
|
tags:
|
||||||
- drupal
|
- drupal
|
||||||
|
@ -8,12 +9,12 @@ tags:
|
||||||
draft: true
|
draft: true
|
||||||
---
|
---
|
||||||
|
|
||||||
https://symfony.com/doc/current/setup/symfony_server.html
|
![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)
|
||||||
|
|
||||||
![](/iimages/blog/drupal-symfony-server/terminal.png)
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
https://symfony.com/doc/current/setup/symfony_server.html
|
||||||
|
|
||||||
The Symfony server is bundled as part of the `symfony` binary that is available
|
The Symfony server is bundled as part of the `symfony` binary that is available
|
||||||
to download from <https://symfony.com/download>.
|
to download from <https://symfony.com/download>.
|
||||||
|
|
||||||
|
@ -23,21 +24,54 @@ To install it, run this command:
|
||||||
curl -sS https://get.symfony.com/cli/installer | bash
|
curl -sS https://get.symfony.com/cli/installer | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
It works with any project, not just Symfony.
|
Even though it’s by Symfony, the local webserver works with any type of
|
||||||
|
project - including Drupal 8 and Drupal 7.
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
```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
|
||||||
|
```
|
||||||
|
|
||||||
|
`web` and `docroot` directories are automatically used as the document root for
|
||||||
|
the server, so files are served from there if you run the `serve` command within
|
||||||
|
the project’s root directory.
|
||||||
|
|
||||||
## Different PHP Versions
|
## Different PHP Versions
|
||||||
|
|
||||||
One of the most useful features of the Symfony server is that it
|
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)
|
[supports multiple versions of PHP](https://symfony.com/doc/current/setup/symfony_server.html#different-php-settings-per-project)
|
||||||
if you have them installed (e.g. via Homebrew on macOS), and a different version
|
if you have them installed, and a different version can be selected per
|
||||||
can be selected per directory.
|
directory.
|
||||||
|
|
||||||
This is done simply by adding a `.php-version` file to the root of the project
|
This is done by adding a `.php-version` file to the root of the project that
|
||||||
that contains the PHP version to use - e.g. `7.3`.
|
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
|
Next time the server is started, this file will be read and the correct version
|
||||||
of PHP will be used.
|
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)
|
[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.
|
by adding a `php.ini` file.
|
||||||
|
|
||||||
|
@ -46,16 +80,17 @@ by adding a `php.ini` file.
|
||||||
The Symfony server allows for serving sites via HTTPS by installing its own
|
The Symfony server allows for serving sites via HTTPS by installing its own
|
||||||
local certificate authority.
|
local certificate authority.
|
||||||
|
|
||||||
To install it, run this command:
|
If it’s not installed automatically, run this command to install it:
|
||||||
|
|
||||||
```
|
```
|
||||||
symfony server:ca:install
|
symfony server:ca:install
|
||||||
```
|
```
|
||||||
|
|
||||||
Any HTTP traffic will be automatically redirected to HTTPS.
|
Now any site will be served via HTTPS by default, and any HTTP requests will be
|
||||||
|
automatically redirected to HTTPS.
|
||||||
|
|
||||||
If you then need to run a site with just HTTP, add the `--no-tls` option to the
|
If you need to run a site with just HTTP, add the `--no-tls` option to the
|
||||||
`server:start` command.
|
`serve` command.
|
||||||
|
|
||||||
## Adding Databases with Docker
|
## Adding Databases with Docker
|
||||||
|
|
||||||
|
@ -86,7 +121,7 @@ automatically creates environment variables prefixed with `DATABASE_`.
|
||||||
|
|
||||||
A list of all the environment variables can be seen by running
|
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
|
`symfony var:export` (add `| tr " " "\n"` if you want to view each one on a new
|
||||||
line):
|
line, and `| sort` if you want to list them alphabetically):
|
||||||
|
|
||||||
```dotenv
|
```dotenv
|
||||||
DATABASE_DATABASE=main
|
DATABASE_DATABASE=main
|
||||||
|
@ -110,8 +145,6 @@ Drupal to connect to the database service.
|
||||||
```php
|
```php
|
||||||
// web/sites/default/settings.php
|
// web/sites/default/settings.php
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
if ($_SERVER['SYMFONY_DOCKER_ENV']) {
|
if ($_SERVER['SYMFONY_DOCKER_ENV']) {
|
||||||
$databases['default']['default'] = [
|
$databases['default']['default'] = [
|
||||||
'driver' => $_SERVER['DATABASE_DRIVER'],
|
'driver' => $_SERVER['DATABASE_DRIVER'],
|
||||||
|
@ -129,14 +162,26 @@ if ($_SERVER['SYMFONY_DOCKER_ENV']) {
|
||||||
|
|
||||||
## Installing Drupal
|
## Installing Drupal
|
||||||
|
|
||||||
`../vendor/bin/drush site-install`:
|
Drush is added as a dependency via Composer.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../vendor/bin/drush site-install
|
||||||
|
```
|
||||||
|
|
||||||
|
However, this will cause an error like this because Drupal cannot connect to the
|
||||||
|
database.
|
||||||
|
|
||||||
> Error: Class 'Drush\Sql\Sql' not found in Drush\Sql\SqlBase::getInstance()
|
> Error: Class 'Drush\Sql\Sql' not found in Drush\Sql\SqlBase::getInstance()
|
||||||
|
|
||||||
`symfony php ../vendor/bin/drush st`
|
To fix this, ensure that the command is prefixed with `symfony php`. This will
|
||||||
|
ensure that the correct PHP version and configuration is used, and that the
|
||||||
|
appropriate environment variables are available.
|
||||||
|
|
||||||
This will ensure that the correct PHP version and configuration is used, and
|
```bash
|
||||||
that the appropriate environment variables are available.
|
symfony php ../vendor/bin/drush site-install
|
||||||
|
```
|
||||||
|
|
||||||
|
This also applies to all other Drush commands.
|
||||||
|
|
||||||
## Custom Domain Names
|
## Custom Domain Names
|
||||||
|
|
||||||
|
@ -144,6 +189,8 @@ Good for multisites.
|
||||||
|
|
||||||
https://symfony.com/doc/current/setup/symfony_server.html#local-domain-names
|
https://symfony.com/doc/current/setup/symfony_server.html#local-domain-names
|
||||||
|
|
||||||
|
TODO: add proxy image
|
||||||
|
|
||||||
```
|
```
|
||||||
cp web/sites/default web/sites/umami
|
cp web/sites/default web/sites/umami
|
||||||
```
|
```
|
||||||
|
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 97 KiB |
Reference in a new issue