apache2 rewrite page not found - php

Ive just completed the setup of apache.
Setup looks as follow:
my virtualhost:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName system.local
ServerAlias www.system.local
DocumentRoot /var/www/system
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
My hosts file is:
127.0.1.1 system.local
I have also used a2enmod to enable mod_rewrite.
When i open my application and for instance go to /Admins/index i get a page not found.
Does anyone know what i might be missing?

If you are using an .htaccess file. You need to allow the use of an .htaccess file in your web directory using AllowOverride All. For that your code should look like this.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName learningbank.local
ServerAlias www.learningbank.local
DocumentRoot /var/www/system_learningbank
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/system_learningbank>
AllowOverride All
</Directory>
</VirtualHost>
Also don't forget to restart apache when making config changes.

Related

Virtual host not working on XAMPP, something very strange happenning

Hi I have browsed all the resources, but still seems can't find the solution.
I have XAMPP Control Panel v 3.2.4 (compiled Jun 5th 2019) installed on my computer, it is installed in d:\xampp. I want to create a Virtual host, so that I can correctly use various global PATH variables.
I followed instructions closely.
This is from my D:\xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:\xampp\htdocs"
<Directory "D:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName ikeen.localhost
DocumentRoot "D:\xampp\htdocs\ikeen"
SetEnv APPLICATION_ENV "development"
<Directory "D:\xampp\htdocs\ikeen">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I have added following lines to the end of httpd.conf:
<Directory />
AllowOverride none
Require all granted
</Directory>
I have the following line in my hosts file in windows:
127.0.0.1 ikeen.localhost
This is the structure of my site directory
In order to avoid cache I open URL in the incognito mode and from different browsers. I always get redirect to dashboard - https://ikeen.localhost/dashboard/, it opens the standard "Welcome to XAMPP for Windows 7.4.3"
I have heard that it has something to do with https, as I'm always transferred to https URL even if I try to use http. I've looked at httpd-ssl.conf, but I don't know what to do there. Any ideas?
Finally! For everyone who is looking for the solution do the following:
My desired site is located at D:\xampp\htdocs\ikeen.
1) Add this to your httpd-vhosts.conf:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:\xampp\htdocs"
<Directory "D:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName ikeen.localhost
DocumentRoot "D:\xampp\htdocs\ikeen"
SetEnv APPLICATION_ENV "development"
<Directory "D:\xampp\htdocs\ikeen">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
2) Add this to the end of httpd.conf:
<Directory />
AllowOverride none
Require all granted
</Directory>
3) Add this line to your hosts file in Windows directory
127.0.0.1 ikeen.localhost
4) Finally, this is the step that is missing from all the solutions. Add this to your httpd-ssl.conf, after the same section for your localhost (usually www.example.com), change example.com to your local settings for localhost, so that the whole section looks smth like this
<VirtualHost _default_:443>
# General setup for the virtual host
DocumentRoot "D:/xampp/htdocs"
#ServerName www.example.com:443
ServerName localhost
ServerAdmin admin#example.com
ErrorLog "D:/xampp/apache/logs/error.log"
TransferLog "D:/xampp/apache/logs/access.log"
# General setup for the ikeen host
DocumentRoot "D:/xampp/htdocs/ikeen"
#ServerName www.example.com:443
ServerName ikeen.localhost
ServerAdmin admin#example.com
ErrorLog "D:/xampp/apache/logs/error.log"
TransferLog "D:/xampp/apache/logs/access.log"
I had the same issue. Problem was solved by removing the standard virtual host entry and i wasn't redirected to the root directory.
Just remove these lines of code:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:\xampp\htdocs"
<Directory "D:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
If the case does not work, maybe change httpd-ssl.conf
My 3 sites worked, localhost, test1.com, test2.com
#
<VirtualHost _default_:443>
DocumentRoot "c:/xampp/htdocs"
ServerName localhost
ServerAdmin admin#example.com
ErrorLog "c:/xampp/apache/logs/error.log"
TransferLog "c:/xampp/apache/logs/access.log"
...
</VirtualHost>
#test1
<VirtualHost _default_:443>
DocumentRoot "c:/xampp/htdocs/test1"
ServerName test1.com
ServerAdmin admin#example.com
ErrorLog "c:/xampp/apache/logs/error.log"
TransferLog "c:/xampp/apache/logs/access.log"
...
</VirtualHost>
#test2
<VirtualHost _default_:443>
DocumentRoot "c:/xampp/htdocs/test2"
ServerName test1.com
ServerAdmin admin#example.com
ErrorLog "c:/xampp/apache/logs/error.log"
TransferLog "c:/xampp/apache/logs/access.log"
...
</VirtualHost>

Unable to connect to apache virtualhost

I have unizped codeigniter on /var/www/control_cuotas indx.php is placed on that folder and I settrd up a new virtualhost on apache on the 000-default.conf file whith this code
<VirtualHost *:81>
<Directory /var/www/control_cuotas>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/control_cuotas
ServerAlias www.control_cuotas.test
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
But I cannot acces to localhost:81 its Unable to connect and the serve rwas restarted before I tried to access
For example:
<VirtualHost *:80>
ServerName your_project
DocumentRoot "C:/wamp64/www/your_project"
<Directory "C:/wamp64/www/your_project/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Let's try one more time.
Make sure all your VirtualHosts define a ServerName. Failure to do so will mean trouble as you add more hosts.
<VirtualHost *:80>
DocumentRoot /var/www/control_cuotas
ServerName control_cuotas.test
ServerAlias www.control_cuotas.test
ServerAdmin webmaster#localhost
<Directory /var/www/control_cuotas>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Don't forget to enable the above config in Apache adding it to the sites-enabled list. Then restart Apache.
The file /etc/hosts should look like this at a minimum
127.0.0.1 localhost
127.0.0.1 control_cuotas.test
127.0.0.1 www.control_cuotas.test
Other VHosts should also be represented in this file.
You can also add entries for ipV6 if you want, but it is not a requirement in most cases. (The main case is that you have disabled communication using ipV4.)

Apache2 Alias working locally but not working for sub directory on another server

I have the same configuration and set up only the versions of Apache2 are slightly different. I have set up /api to load the /public.
So, locally (apache 2.4.18)
mysite.local correctly loads /var/www/mysite/application
mysite.local/api correctly loads /var/www/mysite/public
mysite.local/api/subdirectory correctly loads /var/www/mysite/public
I want to replicate this on a hosted dev server (Apache 2.4.7) however I am getting the following:
mysite.devserver.com correctly loads /var/www/html/mysite/application
mysite.devserver.com/api correctly loads /var/www/html/mysite/public
mysite.devserver.com/api/subdirectory incorrectly loads /var/www/html/mysite/application
Local mysite.conf file (working)
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName mysite.local
ServerAlias www.mysite.local
Alias /api /var/www/mysite/public
<Directory /var/www/mysite/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/mysite/application
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Dev server conf file (not working)
<VirtualHost *:80>
ServerName mysite.devserver.com
ServerAdmin webmaster#localhost
Alias /api /var/www/html/mysite/public
<Directory /var/www/html/mysite>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/html/mysite/application
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I have also tried to add the Alias into mods-enabled but its not making a difference. The code is the exact same, same .htaccess files in both instances.

laravel project not loading css with apache artisan serve working fine

I've created a Laravel Project, which I have deployed previously with apache2, and working great.
As I finished with my latest deployment, I found that no external CSS was being loaded when I was done with. So I did a check on all step many times over, but I don't think I have missed on anything.
However, upon running with php artisan serve everything works fine.
Here is my virtual_host config file:
<VirtualHost *:80>
ServerAdmin admin#project
DocumentRoot /var/www/html/project/public/index.php
ServerName example.com
ServerAlias www.example.com
DirectoryIndex index.php
<Directory /var/www/html/project/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
In virtualhost configuration, you should try using
<VirtualHost *:80>
ServerAdmin admin#project
DocumentRoot /var/www/html/project/public
ServerName example.com
ServerAlias www.example.com
DirectoryIndex index.php
<Directory /var/www/html/project/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Remove public folder from <Directory> and also remove index.php from DocumentRoot.

Problems with virtualhost and alias Laravel 5.4

I am trying to use a virtualhost with an alias to deploy a Laravel application.
Using apache2 in ubuntu 16.04.
My 000.conf file is:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options -Indexes
AllowOverride All
Require all granted
</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 index.htm
</IfModule>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/public
Alias /expediente "/var/www/public/"
<Directory /var/www/public/>
Options -Indexes
AllowOverride All
Require all granted
</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 index.htm
</IfModule>
</VirtualHost>
The first one is working ok but the second one does not.
What am I doing wrong?
==============
EDIT
Ok so i made two conf files in sites available and symlinked them to sites-enabled.
advanced.conf
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName ip-address:80/advanced
ServerAlias /advanced
DocumentRoot /var/www/html/advanced
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
expediente.conf
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName ip-address:80/expediente
ServerAlias /expediente
DocumentRoot /var/www/html/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Reloaded and restarted apache2.
If i try to navigate to ip-address/ i get the first page, the advanced,
If i try to navigate to ip-address/advanced 404 not found
If i try to navigate to ip-address/expediente 404 not found
What am i doing wrong?
its good practice create different host file for your alias. you can use this command to copy default config for your second alias with this command
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
and open it in whichever editor you like and put this content
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
save and close the file then run this command
sudo a2ensite example.com.conf
and restart your apache
You gonna need ServerName in your virtual hosts configurations, its probably always defaulting to the first one without that. For example
ServerName mydomain.net
Si tus proyecto esta de la forma http://localhost/AppName, entonces debes colocar en el httpd.conf
<VirtualHost site1.local:80>
ServerAdmin webmaster#example.com
DocumentRoot /path/to/htdocs/site1
ServerName www.site1.local
ServerAlias site1.com
</VirtualHost>
y el segundo.
<VirtualHost site2.local:80>
ServerAdmin webmaster#example.com
DocumentRoot /path/to/htdocs/site2
ServerName www.site2.local
ServerAlias site2.com
</VirtualHost>

Categories