3

I need some help with configuring Symfony on apache2 web server.

My current project category structure is:

var/www/domain.com/public_html

Inside public_html is where my Symfony application is located.

I am stuck at figuring our what I am doing wrong in my either .htaccess or /etc/apache2/sites-available/domain.com.conf files.

I am using symfony/apache-pack. My .htaccess files live inside /public folder as per documentation. Here it is:

DirectoryIndex index.php

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
    RewriteRule .* - [E=BASE:%1]

    RewriteCond %{HTTP:Authorization} .+
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]

    RewriteCond %{ENV:REDIRECT_STATUS} =""
    RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 307 ^/$ /index.php/
    </IfModule>
</IfModule>

And here is my /etc/apache2/sites-available/domain.com.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /var/www/mydomain.com/public_html/public
    <Directory /var/www/mydomain.com/public_html/public>
        AllowOverride All
        Order allow,deny
        Allow from All
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

I also read this and updated 000-default.conf as follows:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerAlias www.mydomain.com
        DocumentRoot /var/www/mydomain.com/public_html/public

        <Directory /var/www/domain.com/public_html/public>
            Options FollowSymlinks MultiViews
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
            Allow from All
        </Directory>

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

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml >
        </IfModule>

</VirtualHost>

For the moment I am still seeing symfony project folder structure.

I tried:

  1. inside .htaccess changing DirectoryIndex to /public/index.php
  2. inside .conf file changin DocumentRoot to /va/www/domain.com/public_html/public
  3. tried clearing cache

SO far nothings seems to help.

Would be extremely helpful for any advice.

4
  • 2
    DocumentRoot and Directory should point to .../public_html/public. What happens when you do that and how does it "not help"? Do you see a blank page or...? Server logs would be helpful, too. Commented Oct 7, 2020 at 22:04
  • @msg, I have tried that. Added public to DocumentRoot and Directory, restarted apache and cleared cache. Getting same symfony project structure Commented Oct 8, 2020 at 0:46
  • The same structure? With src, public, etc? Then I can only think of two things: either browser cache or your second VirtualHost (the one over https you are redirecting to) is still configured with public_html. This is what I usually do, and just deal with one VHost config. Commented Oct 8, 2020 at 2:22
  • @msg, I have updated post. Yes, same symfony project structure. Browsers cache is cleared Commented Oct 8, 2020 at 6:05

1 Answer 1

1

I see that you are editing vhost which begins with <VirtualHost *:80>......

That mean your website should be reachable by 80 port or in other words by http protocol. But! If in reality you are accessing your website by https protocol then make sure you are editing right Apache2 .conf file.

If the website is reachable by https protocol (especially if you use LetEncrypt), then try locating /etc/apache2/sites-available/....-le-ssl.conf config file (or similar one with corresponding domain title and with ssl prefix or postfix in it's name).

After editing that file do not forget to restart Apache2 webserver with $sudo service apache2 restart and test website again.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.