Symfony 4 项目生产问题

Symfony 4 project Production problems

伙计们,我在部署 Symfony 项目时遇到了一些问题:

我运行命令:

composer install --no-dev --optimize-autoloader

我使用了 apache-pack:

composer require symfony/apache-pack

这在 public 文件夹中创建了一个 .htaccess,其中包含 index.php.

-找不到资产。 (public 文件夹中的元素):

GET http://buy-m3.infinityfreeapp.com/css/custom.css 
net::ERR_ABORTED 404 (Not Found)

-数据库连接问题:

Request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: 
"An exception occurred in driver: SQLSTATE[HY000] [2002] N
o such file or directory" at /home/vol6_3/epizy.com/epighhg78813/htdocs/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php 
line 112 {"exception":"[object] (Doctrine\DBAL\Exception\ConnectionException(code: 0): An exception occurred in driver: SQLSTATE[HY000] [2002] 
No such file or directory at /home/vol6_3/epizy.com/epghghgh878813/htdocs/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:112)\n
[previous exception] [object] (Doctrine\DBAL\Driver\PDO\Exception(code: 2002): SQLSTATE[HY000] [2002] 
No such file or directory at /home/vol6_3/epizy.com/epihghgh13/htdocs/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18)
\n[previous exception] [object] (PDOException(code: 2002): 
SQLSTATE[HY000] [2002] No such file or directory at /home/vol6_3/epizy.com/epighgh8813/htdocs/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:38)"} []

// This file was generated by running "composer dump-env prod"

return array (
  'APP_ENV' => 'prod',
  'APP_SECRET' => 'c84117fa77c8ghgghghhgds03',
  'DATABASE_URL' => 'mysql:user:password@shost/dnbame',
);

我也在应用程序根目录添加了一个 htacces:

<IfModule mod_rewrite.c>

   
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ public/ [QSA,L]
</IfModule>

有人可以帮忙吗?谢谢

大家好,我可以通过很多流程解决这个问题:首先:composer require symfony/asset,然后执行部署 symfony 应用程序的常用命令,例如 composer require symfony/requirements-checker,composer dump -env prod( 确保执行此命令,它会创建一个 env..php 文件,其中包含 index.php 所需的 .env. 信息public 文件夹. composer install --no-dev --optimize-autoloader and APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear .此外,我不得不使用webpack来管理资产,有文档:https://symfony.com/doc/current/frontend.html

问候!