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 someemail@example.com 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:
- inside .htaccess changing DirectoryIndex to /public/index.php
- inside .conf file changin DocumentRoot to /va/www/domain.com/public_html/public
- tried clearing cache
SO far nothings seems to help.
Would be extremely helpful for any advice.
Advertisement
Answer
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.