我是Symfony的新手,刚刚在Debian服务器上创建了一个新项目。文件夹是/var/www/symfony。我使用了此处定义的说明:https://symfony.com/doc/current/book/installation.html
当我从web浏览器访问该文件夹时,我会看到包含文件的目录索引。但我错过了默认页面。
我检查了以下内容:
- 已将web服务器的权限配置为读/写用户/组/
- Apache2中的目录已配置为AllowOverride All
- DefaultController.php文件定义了一个"/"路由
当我尝试从项目目录运行PHP内部web服务器时(PHP-bin/console-server:run):
PHP Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /var/www/symfony/vendor/symfony/symfony/src/Symfony/Component/Debug/ErrorHandler.php on line 386
PHP Stack trace:
PHP 1. {main}() /var/www/symfony/bin/console:0
PHP 2. Symfony'Component'Debug'Debug::enable() /var/www/symfony/bin/console:24
PHP 3. Composer'Autoload'ClassLoader->loadClass() /var/www/symfony/bin/console:0
PHP 4. Composer'Autoload'includeFile() /var/www/symfony/vendor/composer/ClassLoader.php:301
我运行的是PHP 5.4.54。这是Symfony的bug,还是我遗漏了什么?
Symfony 3.0及以上版本要求您使用PHP 5.5.9或更高版本。
您应该确保DocumentRoot指向apache配置文件中的/var/www/symfonyproject/web文件夹。请参见下文。
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost