【问题标题】:fsockopen() error 500 when I try to access my Symfony app after deployment to Ubuntu VPS部署到 Ubuntu VPS 后尝试访问 Symfony 应用程序时出现 fsockopen() 错误 500
【发布时间】:2016-11-22 17:55:45
【问题描述】:

EDIT2:APC 已安装并启用。解决办法是什么?

我正在尝试将 symfony 应用程序部署到 VPS。 我从 git 部署了代码,我安装了供应商并检查了 /web/config.php 以修复有关 Symfony 要求的所有主要和推荐问题。都是绿色的。

但是,当我尝试访问 [VPS_IP]/my_project/web/app.php 时,页面无法正常工作。 [my_ip] 目前无法处理该请求。

我还尝试配置虚拟主机并尝试仅以 URL 地址访问 [my_ip] 上的 Symfony 应用程序,我得到了相同的结果。

我已经启用了 apache 2 mod rewrite,我已经添加并启用了所有必要的 php 扩展,我已经在 php.ini 中设置了 date.timezone,我还查看了 dev.log 文件和我有这个错误可能是原因:

[2016-11-22 14:45:49] php.DEBUG: fsockopen(): unable to connect to 127.0.0.1:800           0 (Connection refused) {"type":2,"file":"/var/www/html/giftbundle/vendor/symfony           /symfony/src/Symfony/Bundle/FrameworkBundle/Command/ServerCommand.php","line":59           ,"level":28928} []

谁能提供一些帮助?

config.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: "@MyVendorBundle/Resources/config/services.yml" }

# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: en

framework:
    #esi:             ~
    #translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # handler_id set to null will use default session handler from php.ini
        handler_id:  ~
        save_path:   "%kernel.root_dir%/../var/sessions/%kernel.environment%"
    fragments:       ~
    http_method_override: true
    assets: ~

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    form_themes:
        - 'bootstrap_3_layout.html.twig'

# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

# app/config/config.yml
#knp_menu:
    # use "twig: false" to disable the Twig extension and the TwigRenderer
#    twig:
#        template: knp_menu.html.twig
    #  if true, enables the helper for PHP templates
#    templating: false
    # the renderer to use, list is also available by default
#    default_renderer: twig

assetic:
    debug:          '%kernel.debug%'
    use_controller: '%kernel.debug%'
    filters:
        cssrewrite: ~

gregwar_captcha: ~

liip_imagine:
    filter_sets:
        cover_filter:
            filters:
                thumbnail:
                    size: [600, 400]
                    mode: inset
        prod_thumbnail:
            filters:
                thumbnail:
                    size: [50, 50]
                    mode: inset

#web_profiler:
#    toolbar: true
#    position: bottom
#    intercept_redirects: false
#    excluded_ajax_paths:  ^/bundles|^/_wdt    

parameters.yml

# This file is auto-generated during the composer install
parameters:
    database_host: [another remote DB IP]
    database_port: 3306
    database_name: [remote DB name]
    database_user: [Remote DB user]
    database_password: [remote DB PSW]
    mailer_transport: sendmail
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    secret: rodacsoft
    facebook_app_id: [fb_app_ID] 
    facebook_app_secret: [fb_secret]

VPS /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>

    DocumentRoot /var/www/html/giftbundle/web
    <Directory /var/www/html/giftbundle/web>
        AllowOverride None
        Order Allow,Deny
        Allow from All

        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ app.php [QSA,L]
        </IfModule>
    </Directory>

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    ErrorLog /var/log/apache2/symfony_error.log
    CustomLog /var/log/apache2/symfony_access.log combined
</VirtualHost>

编辑:在 Symfony_error.log 我有这个。不知道如何修复它或它是否相关。

[Tue Nov 22 14:46:06.216187 2016] [:error] [pid 21788] [client 159.153.60.77:18035] PHP Fatal error:  Uncaught Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException: The service "validator.builder" has a dependency on a non-existent service "validator.mapping.cache.apc". in /var/www/html/giftbundle/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:58\nStack trace:\n#0 /var/www/html/giftbundle/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php(51): Symfony\\Component\\DependencyInjection\\Compiler\\CheckExceptionOnInvalidReferenceBehaviorPass->processReferences(Array)\n#1 /var/www/html/giftbundle/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php(51): Symfony\\Component\\DependencyInjection\\Compiler\\CheckExceptionOnInvalidReferenceBehaviorPass->processReferences(Array)\n#2 /var/www/html/giftbundle/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnIn in /var/www/html/giftbundle/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php on line 58

【问题讨论】:

  • 从错误日志来看,我认为你的 Symfony 项目启用了 APC 缓存,而你的服务器没有安装 APC 缓存
  • @Szanto apcache 从我在 phpinfo 中看到的内容启用。我将如何解决这个问题?将 Symfony 应用程序缓存更改为与其他东西一起使用,以防我的服务器位于我认为的其他东西上?
  • @SzántóZoltán 或者更好的是,如何配置 Symfony 以使用服务器 Memcache?
  • 真诚地说,我对 Symfony 不熟悉,但您可以尝试通过在 yml 文件中将缓存值设置为 false 来完全禁用映射缓存。
  • 我在 config.yml 中没有任何 APC 条目

标签: php symfony web-deployment vps ubuntu-server


【解决方案1】:

检查缓存文件夹是否可由 apache (www-data) 用户写入。您无法访问 [VPS_IP]/my_project/web/app.php,因为您已经在 apache 配置中将 web/ 文件夹定义为根文件夹。您应该使用您的域名在 apache config 中定义 ServerName 和 ServerAlias,或者尝试直接访问 [VPS_IP]/app.php。 还可以将您的 IP 输入到 app_dev 并访问 [VPS_IP]/app_dev.php 以获得更清晰的错误。

【讨论】:

  • 缓存文件夹是可写的,我解决了权限。我也尝试使用 IP 而不是 web 文件夹,因为我已经配置了我的虚拟主机。同样的问题。我会尝试让 app_dev.php 进行检查,但如果供应商安装了 --no-dev,请告诉我信息?
  • 我添加了 app_dev.php 并且当我访问该页面时加载,但没有格式和资产,即使它们存在于 web 文件夹中。那么,为什么没有 app_dev 就不能工作呢?
  • 我修复了文档根路径,并且资产在 app_dev.php 上加载正常,但是当我尝试定期访问 prod 时,我发现 页面无法正常工作。 [my_ip] 目前无法处理该请求。
猜你喜欢
  • 1970-01-01
  • 2013-02-04
  • 2021-11-26
  • 1970-01-01
  • 1970-01-01
  • 2012-12-01
  • 1970-01-01
  • 2015-07-01
  • 1970-01-01
相关资源
最近更新 更多