Yii2 Advance application show directory listing instead web view - apache

I just copy my Yii2 advanced app from windows to linux.
PHP, Apache2, etc already installed successfully.
But when I got to localhost/myweb It show directory listing instead of web view.
Here is my apache2.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/myweb/frontend/web/
</VirtualHost>
Here is myweb/.htaccess
# prevent directory listings
Options -Indexes
IndexIgnore */*
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^administrator(/.+)?$ backend/web/$1 [L,PT]
RewriteRule ^(.+)?$ frontend/web/$1
How I can show web view, instead of directory listing?
Where I doing wrong?
Thanks in advance.

On Linux, you may need to modify the httpd.conf file located at:
/etc/httpd/conf/httpd.conf
you should change the following lines from:
<Directory "/var/www/html">
AllowOverride None
</Directory>
to
<Directory "/var/www/html">
AllowOverride All
</Directory>
and then restart the httpd service

Related

DirectorySlash Off doesn't work

I'm using apache 2.4.7
This is my virtualhost's config:
DocumentRoot /var/www/login
ServerName login.mydomain.com
<Directory "/var/www/login">
allow from all
AllowOverride All
Options +Indexes
DirectoryIndex index.html index.php
DirectorySlash Off
Require all granted
</Directory>
In my /var/www/login directory, I have a directory called freeseat and in there, there's the index.php file, so it's full location is /var/www/login/freeseat/index.php
When I try to access it through the following link (domain replaced), it redirects to the same URL with a trailing slash:
http://login.mydomain.com/freeseat -> http://login.mydomain.com/freeseat/
Why isn't the DirectorySlash Off working? I tried to put it in .htaccess, but that didn't help either.
Thanks a lot for your help,
David
First of all, you vHost won't work if you don't use the directive.
This works:
<VirtualHost *:80>
DocumentRoot /var/www/login
ServerName login.mydomain.com
<Directory "/var/www/login">
Allow from all
AllowOverride All
Options +Indexes
DirectoryIndex index.html index.php
DirectorySlash Off
Require all granted
</Directory>
ErrorLog /var/www/login/error.log
</VirtualHost>
To answer you question: DirectorySlash works as expected.
Also see apache documentation for mod_dir, especially the red box called "Security Warning" of section "DirectorySlash".
Tip: always use not publicly accessible error logs to determine the root of evil. :)
Edit #1:
I think I might have misunderstood your question. You want to access /var/www/login/freeseat/index.php through http://login.mydomain.com/freeseat (w/o trailing slash).
Then, drop the freeseat folder and use index.php as var/www/login/freeseat.php and create a RewriteRule in the /var/www/login/.htaccess file (mod_rewrite must be active):
RewriteEngine On
RewriteRule ^freeseat$ freeseat.php
Also, drop
Options +Indexes
DirectoryIndex index.html index.php
from your vHost configuration. It isn't needed anymore.

.htaccess not working on my Ubuntu 14.04 Distribution

I have just configured my LAMP stack on my Ubuntu 14.04 distribution and want to set .htaccess up to serve a website.
I followed the tutorial https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file and configured a virtual host for my domain, however I am still unable to use the .htaccess file in my projects root, whenever I try to serve a page I get a 404 error.
The .conf file for my domain looks like:
<VirtualHost *:80>
ServerAdmin alexmk92#live.co.uk
ServerName alexsims.me
ServerAlias www.alexsims.me
DocumentRoot /var/www/alexsims.me
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/alexsims.me>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I tried to change AllowOverride None to AllowOverride All but that caused an internal 500 error even after enabling mod_rewrite.
Regards,
Alex.
EDIT: .htaccess contents
#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^alexsims.me [NC]
RewriteRule ^(.*)$ http://www.alexsims.me/$1 [L,R=301,NC]
#--- Rewrite PHP files clean URL
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)$ ?page=$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ ?page=$1&id=$2 [NC,L]
I have same issue with Ubuntu 15.10.
I solved this way.
First you need to enable rewrite module:
sudo a2enmod rewrite
sudo gedit /etc/apache2/apache2.conf
and replace
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
With:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And finally
sudo service apache2 reload
Actually what is difference between restart and reload !
restart= stop + start
reload = remain running + re-read configuration files.
We have changed configuration so we need to reload configuration.
It should help someone as I have wasted 4 hours :)
Try
Require all granted
in place of
Order allow,deny
allow from all
See the upgrade documentation for more info:
In 2.2, access control based on client hostname, IP address, and other
characteristics of client requests was done using the directives
Order, Allow, Deny, and Satisfy.
In 2.4, such access control is done in the same way as other
authorization checks, using the new module mod_authz_host. The old
access control idioms should be replaced by the new authentication
mechanisms, although for compatibility with old configurations, the
new module mod_access_compat is provided.
AllowOverride None
That's your problem, right there. The 500 error you're getting could mean that your .htaccess file is malformed - start
See http://httpd.apache.org/docs/current/mod/core.html#allowoverride
You should check if the directives you use in .htaccess are enabled.
For example if you use RewriteEngine you should have apache module rewrite enabled:
cat /etc/apache2/mods-available/rewrite.load
a2enmod rewrite
service apache2 restart
For ExpiresActive directive you should enable apache module expires:
cat /etc/apache2/mods-available/expires.load
a2enmod expires
service apache2 restart
etc.

.htaccess rewrites not being read

I have the following in htaccess:
RewriteEngine on
RewriteRule ^list/([A-Za-z0-9_\.-]+).html?$ list.php?table=$1 [QSA,L]
In virtualhosts:
ServerName localhost
DocumentRoot "c:/wamp/www"
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/kurz/site/www"
ServerName kurz.local
<Directory c:/wamp/www/kurz/site/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
in apache config:
DocumentRoot "c:/wamp/www/"
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
Now the weird problem is:
there is a rewrite happening, even AFTER i delete the .htaccess, I tried also removing ALL other sites in the www folder, but there's still a rewrite happening from somewhere (do these things cache? i tried clearing browser cache and all that),
BUT
if I put some jibberish in the .htaccess, i get a server error, so I know it is being read!
the other problem is that the rewrite is not passing any variables,
this link works:
http://kurz.local/admin/list/pages.html
but it seems to take to:
http://kurz.local/admin/list.php
instead of
http://kurz.local/admin/list.php?table=pages
online this setup is working, but locally it's not
any ideas ?
i'm really puzzled!
You haven't mentioned if you restarted the server? editing server config files needs a restart, but I believe .htaccess file changes do not need apache server restart.
Your server doc root is:
c:/wamp/www/
Your virtual host doc root is inside the above, I don't think that is allowed.
It should be :
c:/wamp/vhosts/site1root
c:/wamp/vhosts/site2root
etc.
Also see this: https://httpd.apache.org/docs/2.2/vhosts/name-based.html

xampp - mysite.local redirects to xampp folder

I've been battering my head against this all evening and can't see where I'm going wrong. I want to set a host, mysite.local, on xampp and have followed all the instructions, but I keep getting redirected to mysite.local/xampp.
Any ideas where I'm going wrong here? The paths are correct, and I've restarted Apache :)
I edited my hosts file to add:
127.0.0.1 mysite.local
I edited extra/httpd-vhosts.conf:
NameVirtualHost localhost:80
<VirtualHost localhost:80>
ServerName localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost localhost:80>
<Directory "/Applications/XAMPP/xamppfiles/htdocs/wd">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/wd"
ServerName mysite.local
</VirtualHost>
I've just got the very same problem yesterday. Even if the steps you did are correct in a context, you need to do some more tasks ;)
You also need to edit Apach'es httpd.conf referring to your new VirtualHost like this:
# Your great site!
<Directory "/Applications/XAMPP/xamppfiles/htdocs/wd">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
With this alone you'll be able to access http://mysite.local without the redirection to the XAMPP splash screen BUT you'll see the directories of your proyect (at least if you don't have and index in the root folder)
If you need to load a file from a folder (for example /public/index.php) you'll need to use an .htaccess file. Remember this file must be in the folder(s) you want to have control. So for example, an .htaccess file located at the root of your project to redirect to the /public/index.php file you must do it this way:
RewriteEngine On
RewriteBase /
RewriteRule ^.*$ public/index.php [NC,L]
Just remember to use the correct regular expression you need and don't forget to take preventive measures with more security in a production website ;) I wish I've helped you out =)

Symfony 1.4 under a userdir in Apache

I have users who want to run their own Symfony projects under their home directories, but I can't get Symfony to work properly. In my Apache2 config file, I set the userdir as:
UserDir sfproject/web
But the DocumentRoot has to be:
/var/www/sfproject/web
This requirement is there because when we deploy the code to production, we don't want to change the Apache config file. And everything is going to be under that directory.
The problem is that when we go to a user directory: dev.server.com/~asdf
Symfony gives a 404 error: Empty module and/or action after parsing the URL "/index.php" (/).
I don't understand what's wrong. We want them to see their individual projects in their home directories. I looked at some other people setting up Symfony in shared hosting environments, but this is not a shared hosting environment. This is a dedicated server and I have root. Thank you for your help. Here is the relevant parts of my Apache config:
UserDir sfproject/web
<Directory "/usr/share/php/data/symfony/web/sf">
AllowOverride All
Allow from All
</Directory>
<VirtualHost *>
DocumentRoot "/var/www/sfproject/web"
DirectoryIndex index.php
<Directory "/var/www/sfproject/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf /usr/share/php/data/symfony/web/sf
<Directory "/usr/data/symfony/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
I think something like the following would be closer to a solution.
<VirtualHost *>
DocumentRoot "/var/www/sfproject/web"
DirectoryIndex index.php
<Directory "/var/www/sfproject/web">
AllowOverride All
Allow from All
</Directory>
# or is the dir /usr/share/php/data/symfony/data/web/sf ?
Alias /sf /usr/share/php/data/symfony/lib/vendor/symfony/data/web/sf
<Directory "/usr/share/php/data/symfony/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
The paths from your excerpt does not look good I guess. Try it out and let us know if it works.