驱动程序中发生异常:SQLSTATE [HY000] [2002] php_network_getaddresses:getaddrinfo failed:名称或服务未知

时间:2018-06-07 15:15:38

标签: symfony4

我尝试从dev更改为prod时,在Symfony 4中检索到以下错误

驱动程序中发生异常:SQLSTATE [HY000] [2002] php_network_getaddresses:getaddrinfo failed:名称或服务未知

为了部署环境生产,我在运行时始终检索以下错误: php bin / console doctrine:database:create

驱动程序中发生异常:SQLSTATE [HY000] [2002] php_network_getaddresses:getaddrinfo failed:名称或服务未知

在错误日志中我也检索 - > PHP致命错误:在第1行的/var/www/Inventory-app/vendor/symfony/debug/Exception/OutOfMemoryException.php中,允许的内存大小为134217728字节(试图分配32768字节)

开发环境适用于使用PHP 7.2 TS和NTS的任何问题 我使用以下过程来部署应用程序。

EXAMPLE PRODUCTION ENV DEBIAN 8 JESSIE / DEBIAN 9 STREETCH
REQUERIMENTS
    INSTALL PHP 7.2 - MYSQL SERVER - ANY WEB SERVER - COMPOSER ( OPTIONAL GIT )

    apt-get install apt-transport-https lsb-release ca-certificates
    wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
    echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
    apt-get update && apt-get install php7.2 && apt-get install php7.2-xml && apt-get install php7.2-zip && apt-get install php7.2-mysql && apt-get install php7.2-mbstring && apt-get install php7.2-intl
    apt-get install apache2 && apt-get install mysql-server
    mkdir /etc/composer && cd /etc/composer
    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    php composer-setup.php
    php -r "unlink('composer-setup.php');"
    sudo mv composer.phar /usr/local/bin/composer
    cd .. && rm -r composer

    (OPTIONAL)

    apt-get install git

DEPLOYMENT APPLICATION

    cd /etc/apache2/sites-available
    touch inventory-app.conf
Paste the following code into the file inventory-app.conf

虚拟主机

<VirtualHost *:80>
ServerName inventory.local
ServerAlias www.inventory.local
DocumentRoot /var/www/Inventory-app/public
<Directory /var/www/Inventory-app/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
    <IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
    </IfModule>
</Directory>
<Directory /var/www/html/Inventory-app>
Options FollowSymlinks
</Directory>
<Directory /var/www/Inventoryapp/public/>
    <IfModule mod_rewrite.c>
    RewriteEngine Off
    </IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
SetEnv APP_ENV prod
SetEnv APP_SECRET 64732cb97c775c6cc0e480593ca9edfca2a7aad3
SetEnv DATABASE_URL "mysql://root:root$@localhost:3306/app_inv"

环境

a2ensite inventory-app.conf
a2enmod rewrite
service apache2 reload
nano ~/.bashrc -> fill with the env variables
export APP_ENV=prod
export DATABASE_URL="mysql://root:root$@localhost:3306/app_inv"
export APP_SECRET="64732cb97c775c6cc0e480593ca9edfca2a7aad3"

( REBOOT THE SYSTEM )

cd /var/www/
git clone https://github.com/VGzsysadm/Inventory-app.git && cd Inventory-app
composer install --no-dev -o
php bin/console doctrine:database:create
php bin/console cache:clear --env=prod --no-debug

0 个答案:

没有答案