网页 综合 更新时间 2026-11-13 17:27:14

Symfony CLI (Symfony Docs)

自动蜘蛛 symfony.com 正文约 5080 字
Symfony CLI (Symfony Docs)
The Symfony CLI is a free and open source developer tool to help you build, run, and manage your Symfony applications directly from your terminal. It's designed to boost your productivity with smart features like:
The Symfony CLI is available as a standalone executable that supports Linux, macOS, and Windows. Download and install it following the instructions on symfony.com/download.
The Symfony CLI supports autocompletion for Bash, Zsh, and Fish shells. This helps you type commands faster and discover available options:
After installation, restart your terminal to enable autocompletion. The CLI will also provide autocompletion for composer and console commands when it detects a Symfony project.
The Symfony CLI includes a project creation command that helps you start new projects quickly:
Pass the --cloud option to initialize a Symfony Cloud project at the same time the Symfony project is created.
The Symfony CLI includes a local web server designed for development. It's not intended for production use, but it provides features that improve the developer experience:
To serve a Symfony project with the local server:
Now browse the given URL or run the following command to open it in the browser:
You can also start the local server and open the given URL in your browser in a single command:
If you work on more than one project, you can run multiple instances of the Symfony server on your development machine. Each instance will find a different available port.
The server:start command blocks the current terminal to output the server logs. To run the server in the background:
Now you can continue working in the terminal and run other commands:
The server:log command tails the logs from the web server, PHP, and your application.
On macOS, when starting the Symfony server you might see a warning dialog asking "Do you want the application to accept incoming network connections?". This happens when running unsigned applications that are not listed in the firewall list. The solution is to run this command to sign the Symfony CLI:
PHP-FPM must be installed locally for the Symfony server to use it.
When the server starts, it checks for web/index_dev.php, web/index.php, public/app_dev.php, public/app.php, public/index.php in that order. If one is found, the server will automatically start with PHP-FPM enabled. Otherwise the server will start without PHP-FPM and will show a Page not found page when trying to access a .php file in the browser.
When an index.html and a front controller (e.g. index.php) are both present, the server will still start with PHP-FPM enabled, but the index.html will take precedence. This means that if an index.html file is present in public/ or web/, it will be displayed instead of the index.php, which would otherwise show, for example, the Symfony application.
Running your application over HTTPS locally helps detect mixed content issues early and allows using features that require secure connections. Traditionally, this has been painful and complicated to set up, but the Symfony server automates everything for you:
For WSL (Windows Subsystem for Linux), the newly created local certificate authority needs to be imported manually:
In the file explorer window that just opened, double-click on the file called default.p12.
The Symfony CLI provides PHP management features, allowing you to use different PHP versions and/or settings for different projects.
If you have multiple PHP versions installed on your computer, you can tell Symfony which one to use by creating a file called .php-version at the project root directory:
To see all available PHP versions:
You can create a .php-version file in a parent directory to set the same PHP version for multiple projects.
Override PHP settings per project by creating a php.ini file at the project root:
Use symfony php to ensure commands run with the correct PHP version:
The Symfony CLI forwards unknown commands to the bin/console script of your project, so symfony cache:clear is the same as symfony console cache:clear.
By default, projects are accessible at a random port on the 127.0.0.1 local IP. However, sometimes it is preferable to associate a domain name (e.g. my-app.wip) with them:
The Symfony CLI includes a proxy that allows using custom local domains. The first time you use it, you must configure it as follows:
Open the proxy settings of your operating system:
Set the following URL as the value of the Automatic Proxy Configuration:
http://127.0.0.1:7080/proxy.pac
Now run this command to start the proxy:
If the proxy doesn't work as explained in the following sections, check the following:
By default, Symfony uses .wip (for Work in Progress) as the local TLD for custom domains. You can define a local domain for your project as follows:
Your application is now available at https://my-app.wip
View all local domains and their configuration at http://127.0.0.1:7080 (or in JSON format at http://127.0.0.1:7080/index.json).
You can also use wildcards:
This allows accessing subdomains like https://api.my-app.wip or https://admin.my-app.wip.
访问原文 返回搜索 https://symfony.com/doc/current/setup/symfony_cli.html
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。