我正在尝试在我的 Mac 中安装 Symfony,因此我安装了 symfony 和 Composer 以便开始开发,但是当我创建项目时遇到了一些问题:
composer create-project symfony/skeleton cost_management
Installing symfony/skeleton (v4.0.5)
- Installing symfony/skeleton (v4.0.5): Loading from cache
Created project in cost_management
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 21 installs, 0 updates, 0 removals
- Installing symfony/flex (v1.0.71): Loading from cache
- Installing symfony/polyfill-mbstring (v1.7.0): Loading from cache
- Installing symfony/console (v4.0.6): Loading from cache
- Installing symfony/routing (v4.0.6): Loading from cache
- Installing symfony/http-foundation (v4.0.6): Loading from cache
- Installing symfony/yaml (v4.0.6): Loading from cache
- Installing symfony/framework-bundle (v4.0.6): Loading from cache
- Installing symfony/http-kernel (v4.0.6): Loading from cache
- Installing symfony/event-dispatcher (v4.0.6): Loading from cache
- Installing psr/log (1.0.2): Loading from cache
- Installing symfony/debug (v4.0.6): Loading from cache
- Installing symfony/finder (v4.0.6): Loading from cache
- Installing symfony/filesystem (v4.0.6): Loading from cache
- Installing psr/container (1.0.0): Loading from cache
- Installing symfony/dependency-injection (v4.0.6): Loading from cache
- Installing symfony/config (v4.0.6): Loading from cache
- Installing psr/simple-cache (1.0.1): Loading from cache
- Installing psr/cache (1.0.1): Loading from cache
- Installing symfony/cache (v4.0.6): Loading from cache
- Installing symfony/dotenv (v4.0.6): Loading from cache
Writing lock file
Generating autoload files
Symfony operations: 4 recipes (7c280e93acfad83db0b06dac8600cc2d)
- Configuring symfony/flex (>=1.0): From github.com/symfony/recipes:master
- Configuring symfony/framework-bundle (>=3.3): From github.com/symfony/recipes:master
- Configuring symfony/console (>=3.3): From github.com/symfony/recipes:master
- Configuring symfony/routing (>=4.0): From github.com/symfony/recipes:master
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 255
!!
!! Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "FileResource" from namespace "App".
!! Did you forget a "use" statement for "Symfony\Component\Config\Resource\FileResource"? in /Users/gate11/Desktop/cost_management/src/Kernel.php:39
!! Stack trace:
!! #0 /Users/gate11/Desktop/cost_management/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php(80): App\Kernel->configureContainer(Object(Symfony\Component\DependencyInjection\ContainerBuilder), Object(Symfony\Component\Config\Loader\DelegatingLoader))
!! #1 [internal function]: App\Kernel->Symfony\Bundle\FrameworkBundle\Kernel\{closure}(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
!! #2 /Users/gate11/Desktop/cost_management/vendor/symfony/dependency-injection/Loader/ClosureLoader.php(38): call_user_func(Object(Closure), Object(Symfony\Component\DependencyInjection\ContainerBuilder))
!! #3 /Users/gate11/Desktop/cost_management/vendor/symfony/config/Loader/DelegatingLoader.php(40): Symfony\Component\DependencyInj in /Users/gate11/Desktop/cost_management/src/Kernel.php on line 39
!! PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "FileResource" from namespace "App".
!! Did you forget a "use" statement for "Symfony\Component\Config\Resource\FileResource"? in /Users/gate11/Desktop/cost_management/src/Kernel.php:39
!! Stack trace:
!! #0 /Users/gate11/Desktop/cost_management/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php(80): App\Kernel->configureContainer(Object(Symfony\Component\DependencyInjection\ContainerBuilder), Object(Symfony\Component\Config\Loader\DelegatingLoader))
!! #1 [internal function]: App\Kernel->Symfony\Bundle\FrameworkBundle\Kernel\{closure}(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
!! #2 /Users/gate11/Desktop/cost_management/vendor/symfony/dependency-injection/Loader/ClosureLoader.php(38): call_user_func(Object(Closure), Object(Symfony\Component\DependencyInjection\ContainerBuilder))
!! #3 /Users/gate11/Desktop/cost_management/vendor/symfony/config/Loader/DelegatingLoader.php(40): Symfony\Component\DependencyInj in /Users/gate11/Desktop/cost_management/src/Kernel.php on line 39
!!
我尝试了很多方法来安装它,我在他们的网站上看到了命令,所以我做到了,但安装时仍然遇到一些问题。 如果有人知道出了什么问题,或者我需要其他东西,我希望得到你的帮助。 谢谢。
最佳答案
请替换composer create-project symfony/skeleton cost_management
与 composer create-project symfony/website-skeleton cost_management
**OR**
您可以通过终端执行以下步骤在 Ubuntu 上使用 PHP7.2 安装和设置 Symfony4 应用程序:
-
composer create-project symfony/website-skeleton cost_management
-
cd cost_management
-
php -S 127.0.0.1:8000 -t public
-
ctrl + c
退出服务器运行composer install
-
sudo chmod 777 -R var/cache/ var/log/
- 现在又来了
php -S 127.0.0.1:8000 -t public
- 现在您可以通过此
http://localhost:8000/
检查您的浏览器或者直接访问,无需http://localhost/project_directory/public/index.php
运行服务器
Note:-
1. 默认情况下 symfony 4 设置为开发环境,但您可以设置
通过设置 $_SERVER['APP_ENV']
您的环境
2. 如果它工作正常,那么您将在底部看到 404 错误消息和探查器,因为它默认设置为 dev
模式。
3. 要查看某些内容,您需要通过以下文档 Symfony 4 create your first page 创建您的第一个 Controller
关于php - 使用 Composer 创建 Symfony 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49267500/