Overview
The Sonata Extra Bundle enhances the SonataPageBundle by offering full multisite and multilingual management capabilities. This feature allows tracking and switching between page translations on the front-end and supports a flexible multisite strategy.
Screens
- List view:

- Detailed view:

Setting up a multisite with multiple languages
Creation of multilingual websites
Each site can support different regional settings. Use the following command to create the necessary sites:
bin/console sonata:page:create-site
Quick setup for testing
For testing purposes, you can quickly set up multiple sites using these commands:
TRUNCATE `page__page`;
TRUNCATE `page__site`;
TRUNCATE `page__snapshot`;
php bin/console sonata:page:create-site --enabled --name="Sonata Extra FR" --locale=fr_FR --host=fr.sonata-extra.localhost --relativePath=/fr --enabledFrom=now --enabledTo=- --default
php bin/console sonata:page:create-site --enabled --name="Sonata Extra EN" --locale=en --host=en.sonata-extra.localhost --relativePath=/en --enabledFrom=now --enabledTo=-
php bin/console sonata:page:create-site --enabled --name="Sonata Extra ES" --locale=es --host=es.sonata-extra.localhost --relativePath=/es --enabledFrom=now --enabledTo=-
php bin/console sonata:page:create-site --enabled --name="Sonata Extra IT" --locale=it --host=it.sonata-extra.localhost --relativePath=/it --enabledFrom=now --enabledTo=-
php bin/console sonata:page:create-site --enabled --name="Sonata Extra VN" --locale=vn --host=vn.sonata-extra.localhost --relativePath=/vn --enabledFrom=now --enabledTo=-
Apache Virtual Host Configuration
Configure your Apache virtual host as follows:
<VirtualHost *:80>
ServerName sonata-extra.localhost
ServerAlias fr.sonata-extra.localhost
ServerAlias en.sonata-extra.localhost
ServerAlias es.sonata-extra.localhost
ServerAlias it.sonata-extra.localhost
ServerAlias vn.sonata-extra.localhost
DocumentRoot /var/www/sonata-extra/public
<Directory /var/www/sonata-extra/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Access the sites
- Admin panel: Access the main site admin panel at
http://sonata-extra.localhost/admin/login. - Localized sites: See the content on http://
[fr,en,es,it,vn].sonata-extra.localhost/[fr,en,es,it,vn]/. The administrator login for each site is available at the respective URLs.
Route and snapshot configuration
Run the following commands to create routes, fix them for Sonata Extra, and create snapshots:
bin/console sonata:page:update-core-routes
bin/console sonata:extra:page-fix-route
bin/console sonata:page:create-snapshots
Configure Sonata Page for multisite
To activate Sonata Extra's multilingual support, modify the configurations as follows:
Edit public/index.php
<?php
use App\Kernel;
use Sonata\PageBundle\Request\RequestFactory;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
$request = RequestFactory::createFromGlobals('host_with_path');
return $kernel->handle($request);
};
sonata_page.yaml Changes
### Configuration in sonata_page.yaml for multisite management
sonata_page:
multisite: host_with_path
Conclusion
The multisite and multilingual management features of the Sonata Extra Bundle offer a powerful and flexible approach to managing content across different locales and different sites, aligning with the robust capabilities of the SonataPageBundle.
Adapt the example to the installed version
The Symfony and Sonata examples remain tied to the versions indicated in the article. Symfony 4.x and Symfony 6.2 are no longer maintained: for a current project, use a maintained branch and the documentation that exactly matches your dependencies.
php bin/console about
composer show symfony/framework-bundle sonata-project/admin-bundle
Before resuming the code, check the signatures, services, routes, and templates concerned. Then add a functional test covering permissions, HTTP code, and the visible result.
Reference: maintained Symfony versions.