0

I just try to deploy to production a Symfony (3.3.5) project for the first time and I am in a little trouble.

MySQL is installed and running on the server, Symfony can connect to it. Apache2 and PHP are running too. (And simple PHP files like a echo "hello world" work as expected).

I have two points:

First: when I try to access http://example.com/web/app.php the "page isn't working" (this is the Chrome error message) with error code 500. Same thing for any other URL like http://example.com/web/app.php/login.

Second: Why do I still have to use routes with /web/app.php (if I don't use it, the server show me a directory explorer of the web server) whereas my .htaccess file looks like this:

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

And my /etc/apache2/sites-available/example.com.conf file is:

<VirtualHost *:80>

    ServerAdmin mymail@gmail.com
    ServerName example.com
    ServerAlias dev.gepacte.com
    DocumentRoot /var/www/example.com/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory "/var/www/example.com/public_html">
        <IfModule sapi_apache2.c>
            php_admin_flag engine on
        </IfModule>
        <IfModule mod_php5.c>
            php_admin_flag engine on
        </IfModule>
        #If one of the following lines is uncommented, the apache2 serve won't restart.
        #DirectoryIndex app.php
        #Options -Indexes
        #AllowOverride All
        #Allow from All
    </Directory>

</VirtualHost>

Of course, my symfony project is located in /var/www/example.com/public_html

EDIT:

My /var/log/apache2/access.log file:

80.215.95.207 - - [07/Nov/2017:18:22:44 +0100] "GET /web/app.php/ HTTP/1.1" 500 716 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"

And the /var/log/apache2/error.log file:

[Tue Nov 07 18:24:20.542808 2017] [mpm_prefork:notice] [pid 17564] AH00169: caught SIGTERM, shutting down [Tue Nov 07 18:24:20.723226 2017] [mpm_prefork:notice] [pid 22562] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations [Tue Nov 07 18:24:20.723301 2017] [core:notice] [pid 22562] AH00094: Command line: '/usr/sbin/apache2'

Victor Castro
  • 101
  • 1
  • 5
  • 3
    Welcome to Server Fault! A 500 error is the webservers way of saying "I have a major problem, but I don't want to talk about it in public". Look at the error log of the server, there will be a clear message saying what's wrong. – Gerald Schneider Nov 07 '17 at 07:06
  • Thanks for your help @GeraldSchneider , I just edited my post with the content of my log files. These contents does't help me so much... – Victor Castro Nov 07 '17 at 17:29

1 Answers1

0

I'm assuming you have apache 2.4 and apche served by the user www-data .

Setup write permissions in var folder

Check you have the right permissions

chown -R www-data:www-data /var/www/example.com/public_html/var
chmod -R 777 /var/www/example.com/public_html/var
rm -rf /var/www/example.com/public_html/var/cache/{dev|prod}
rm -rf /var/www/example.com/public_html/var/logs/*

Apache setup

You have to expose only the web folder not the full project.

<VirtualHost *:80>
    ServerAdmin mymail@gmail.com
    ServerName example.com
    ServerAlias dev.gepacte.com
    DocumentRoot /var/www/example.com/public_html/web
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory "/var/www/example.com/public_html/web">
        <IfModule sapi_apache2.c>
            php_admin_flag engine on
        </IfModule>
        <IfModule mod_php5.c>
            php_admin_flag engine on
        </IfModule>
        AllowOverride All
        Options -Indexes FollowSymLinks
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Remove this

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

The first few request will fail as symfony will be rebuilding the cache be patient, after a few minutes it should work.

Check your symfony production logs after.

albert
  • 153
  • 1
  • 7