1

If I open my Yii2 application with url http://IP_ADDRESS/DIR_NAME the it works perfectly. Now I have pointed my domain to path /var/www/html/. But if I open my domain in browser it displays my directory structure of yii2 project. So with http://IP_ADDRESS/DIR_NAME I could access my app but not with domain name. Apache rewrite is enabled for /var/www/html/ in 000-default.conf.

<Directory /var/www/html>
         Options Indexes FollowSymLinks
         AllowOverride All
         Require all granted
 </Directory>

-Content of 000-default.conf

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory /var/www/html>
                Options FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>
</VirtualHost>

-Content of domain.com.conf

<VirtualHost *:80>

        ServerName domain.com
        ServerAlias www.domain.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/domain.com
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
  • Did you fixed DocumentRoot parameter? – lese Jun 30 '17 at 15:02
0

To prevent directory listing you should remove the Indexes keyword from your Options directive, or simply put a - in front of it like: -Indexes

Additionally, check your DocumentRoot with following command, it must match your Yii2 folder:

grep -i Documentroot /etc/apache2/httpd.conf

Did you set the ServerName parameter in /etc/apache2/sites-enabled/000-default.conf conf file? for example:

ServerName IP_ADDRESS

And always remember to reload configuration after you do changes

  • No I didn't set ServerName IP_ADDRESS in /var/www/html/ in 000-default.conf – Peter Jul 4 '17 at 20:11
  • and yes in my000-default.conf I have changed Documentroot to /var/www/html/ – Peter Jul 4 '17 at 20:17
  • and I have added one more conf file in sites-available to add virtual host for my domain. I have changed Documentroot to /var/www/html/DIR_NAME/ – Peter Jul 4 '17 at 20:24
  • Ok, and what's the situation now? – lese Jul 5 '17 at 7:27
  • It's still not working. So I have two config file in sites-available first is 000-default.conf and second one is domain.conf. in 000 I have set Documentroot to /var/www/html/ and in domain.com.conf I have set Documentroot to /var/www/html/domain.com. also in 000-default.conf I have enabled apache rewrite to .../html/. I have no idea what I have done wrong. With Ip I can access my project. Please help me . – Peter Jul 5 '17 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.