Apache2 on Ubuntu 14.04 won't load index.php - apache

Using the following posts:
Ubuntu 14.04 apache2 configuration problems
.htaccess file not working on Ubuntu 14.04 with apache2
Apache doesn't execute script of index.php in root automatically
I've changed my /etc/apache2/apache2.conf file to be the following:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory
And I've created the file /var/www/html/.htaccess to be the following:
DirectoryIndex Index.php index.php Index.html index.html Index.htm index.htm
When I go to my site, the default page is still the (It Works!) index.html file.
How do I configured Apache to give priority to index.php?

Is your DocumentRoot /var/www/ or /var/www/html/ (the latter is where you say you have your .htaccess file)??
If the .htaccess is in /var/www/html/ than I'm gonna guess you need to update your Apache config to be:
<Directory /var/www/html/>

Related

Apache 2.4 server not reading .htaccess file

We are setting up a new server, where we have installed Apache 2.4 and PHP 7.2. In our code structure we have an .htaccess file, but Apache is not accessing it.
We have modify the httpd.conf file and enabled the mod_rewrite and set
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And restart Apache after this, but it is not picking .htaccess file from location - htdocs/myProject/.htaccess
strange but its work for me, in httpd.conf file, I have change -
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
to
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
And it work for me.
Thanks

Yii2 Advance application show directory listing instead web view

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

Directory 'static' gives 404 error

On a Windows machine running XAMPP I have a folder in my web root called 'static'. It and everything in it return a 404 error even though the folder is there.
If I change the name of the folder, e.g. 'statics', all is well. I have other servers (Ubuntu) running Apache and I do not have this problem.
The site is a copy of one of the sites on one of our Linux servers. What can I do or change to allow the directory to work as named?
EDIT vhosts.conf
<VirtualHost *:8080>
ServerAdmin jablanchard#foo.com
DocumentRoot "C:/xampp/htdocs/home/app/gateway"
ServerName localhost
ServerAlias 127.0.0.*
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>
<Directory C:/xampp/htdocs/home/app/gateway/>
# allow .htaccess overrides to work
AllowOverride All
DirectoryIndex login.html index.html index.php
</Directory>
# this matches a link to any project directory to the physical webui directory
AliasMatch ^/projects/([-\w]*)/(.*)$ /home/src/gateway/webui/$2
<Directory /home/src/gateway/webui>
DirectoryIndex home.html
Options All
AllowOverride All
Require all granted
</Directory>
I was getting ready to re-install XAMPP but made one last pass through the config files for Apache. I found the problem was this bit of code in the httpd.conf file -
Alias "/static" "C:/xampp/htdocs/static"
<Directory "C:/xampp/htdocs/static">
AllowOverride All
Require all granted
</Directory>
I am not sure if this is part of the XAMPP install as all of the edits I have made to this installation are in the vhosts file. Once commented out the static directory, as I have defined it, works properly now.

htaccess works in localhost but doesn't work in EC2 instance

My htaccess file works on localhost but doesn't work when i deploy it to EC2 instance.
I'm using Macbook and in finder i cannot see the htaccess file, i thought that perhaps it didn't get copied to EC2 instance but i don't think this is the problem because when i copy the project i can see the htaccess file in my editor.
Is there something enabling mod rewrite in EC2 linux instance? If there is, i didn't do it or it enables mod rewrite as default?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
I pieced together some info from various posts so I thought I'd put up an answer.
As Paul commented, If you're running Amazon EC2 Linux, you're probably running httpd instead of Apache. The file is therefore in /etc/httpd/conf/httpd.conf
You have to change the file as root user. (from ssh access) Do this: sudo vim /etc/httpd/conf/httpd.conf (How to edit httpd.conf file in AMAZON EC2)
DocumentRoot "/var/www/html" was listed in two places for me. I had to change the subsequent AllowOverride None to AllowOverride All in those two places.
Restart apache. I restarted my whole ec2 instance (i have apache configured to start automatically) although just restarting apache should work. But I see the change is working.
I was trying to make the same changes in a .htaccess file (removing the index.php from urls in a code igniter application). Hope it helps!
By default EC2 doesn't have .htaccess enabled, you must edit your httpd.config to allow for it.
In /etc/apache/sites-available/default change AllowOverRide = None to AllowOverRide = All.
Its a three step process
Configure apache mod_rewrite,run in terminal.
sudo a2enmod rewrite
add the following code to /etc/apache2/sites-available/default
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
3.Restart apache
/etc/init.d/apache2 restart
There are three steps
Configure apache mod_rewrite,run in terminal. sudo a2enmod rewrite
Add this code in this file after closing VirtualHost tag /etc/apache2/sites-available/000-default.conf
DocumentRoot /var/www
Options FollowSymLinks
AllowOverride All
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Restart apache server by command
sudo service apache2 restart
When you using the apache2 server
Go to the following directory.
cd /etc/apache2/sites-available
If you use LS command here you will see the following file.
000-default.conf
That's the file with default apache configuration which are applied to your sites in /var/www/html folder.
Open this file for editing.
sudo nano 000-default.conf
Add following lines after DocumentRoot /var/www/html line.
Options FollowSymLinks AllowOverride All Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all
Save the file and restart the apache.
sudo service apache2 restart
that's it and now your .htaccess file will work
On Linux enviroment
1 - cd /etc/apache2/sites-available
2 - sudo nano 000-default.conf
and paste this code:
<Directory "/var/www/html">
Order allow,deny
Allow from all
Options None
AllowOverride All
</Directory>
This worked on AWS instance.
In my case, I am not running httpd, but only Apache.
I followed this website and it works.
Step 1: Enable mod_rewrite module in Apache
sudo a2enmod rewrite
Then restart the Apache HTTP server with service command with sudo:
sudo service apache2 restart
or using the systemctl command with sudo:
sudo systemctl restart apache2
Now that we have mod_rewrite enabled, we can proceed further to configure it.
Step 2: Enable the usage of the .htaccess file
sudo nano /etc/apache2/apache2.conf
Find the following section in /etc/apache2/apache2.conf. You should see the code like this:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and change, from AllowOverride None to AllowOverride All
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

CF file not found with Apache virtual hosts

I have Apache 2.2 configured to run with Coldfusion 9.2, both on the same Centos 6.2. The general config of DocumentRoot in Apache is
DocumentRoot "/var/www/html"
Up until now Apache handed all calls to cfcs and cfms over to Coldfusion. I then created a virtual host
<VirtualHost 192.168.123.207:80>
ServerName myserver.server.private
ServerAlias www.myserver.server.private
ServerAlias webmail.myserver.server.private
ServerAlias admin.myserver.server.private
DocumentRoot /home/myserver/public_html
ErrorLog /var/log/virtualmin/myserver.server.private_error_log
CustomLog /var/log/virtualmin/myserver.server.private_access_log combined
ScriptAlias /cgi-bin/ /home/myserver/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/myserver/public_html>
Options +Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch
allow from all
AllowOverride All
Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
<Directory /home/myserver/cgi-bin>
allow from all
AllowOverride All
Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.myserver.server.private
RewriteRule ^(.*) http://myserver.server.private:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.myserver.server.private
RewriteRule ^(.*) http://myserver.server.private:10000/ [R]
</VirtualHost>
When I open a html file on http://myserver.server.private/hello.html, the correct file within the virtual host document root (/home/myserver/public_html) gets served.
Calling a cfm fails though. Apache passes the request on correctly but then a Coldfusion error message shows up:
File not found: /hello.cfm
It seems that Coldfusion is getting the file name, prefixes a wrong directory path to it and fails loading it from the disk.
I scanned all Coldfusion files for a wrong document root but could not find anything.
EDIT
It turns out that Coldfusion looks into it's own webroot directory at
/opt/coldfusion/wwwroot
I placed a file with the same name but different content there and that one gets served, although there is a) a virtual host and b) the general DocumentRoot is set to /var/www/html.
It turns out that the coldfusion user (cfusion in my case) needs to be in the group of the virtual host user.
usermod -a -G newuser cfusion
After a restart of coldfusion, all works.