Laravel virtual host on Xampp does not work properly - php

I want to load my Laravel 5.8 project with Virtual Host on XAMPP. So here is what I did:
I opened up C:\Windows\System32\drivers\etc\hosts and put this:
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 local.nanoclub.ir
Then at C:\xampp\apache\conf\extra\httpd-vhosts.conf, I added this:
<VirtualHost local.nanoclub.ir:80>
DocumentRoot "C:/xampp/htdocs/badges/public"
ServerName local.nanoclub.ir
ServerAlias *.local.nanoclub.ir
SetEnv APPLICATION_ENV "development"
<Directory "C:/xampp/htdocs/badges/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And also added this to my project, public .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
But now when I want to run local.nanoclub.ir on browser, I get this:
So what's going wrong here? I used to access this local.nanoclub.ir correctly but now it loads this screen.
How to solve this issue?

You need to grant access to this directory.
You can grant this access in your virtual host definition or in the apache2.conf
In virtual host definition
<VirtualHost local.nanoclub.ir:80>
DocumentRoot "C:/xampp/htdocs/badges/public"
ServerName local.nanoclub.ir
ServerAlias *.local.nanoclub.ir
SetEnv APPLICATION_ENV "development"
<Directory "C:/xampp/htdocs/badges/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
# The missing one
Require all granted
</Directory>
</VirtualHost>
In apache2.conf
<Directory C:/xampp/htdocs/badges/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Notice: Don't forget to restart apache after changing configuration.

Related

My redirection is removing the slash after uploading the website on Apache2 server - admin.site.comlogin instead of admin.site.com/login

I have a website built based on PHP/HTML/CSS and which follow the MVC design pattern.
The website is the following : https://admin.site.com
It works well on Localhost. However, when I upload it to my apache2 server, I encounter a problem. It seems that the "/" get removed automatically after ".com" . As I need to be authentificated to access the website, I'm directly redirected to the login page but as the "/" has been removed, it is not working.
I get https://admin.site.comlogin/ instead of https://admin.site.com/login/
Before posting here, I tried to check everything but I run out of ideas.
Especially the fact that this same website works on a different subdomain that I initiated for testing : http://sub1.site.com
The only difference is that that this one does not have any SSL certificate but I don't know it's something that may cause the problem.
Here my different files in Apache2 server.
000-defaut.conf
<VirtualHost *:80>
ServerAdmin contact#site.com
ServerName site.com
ServerAlias sub1.site.com
DocumentRoot /var/www/sub1/interface/
<Directory /var/www/sub1/interface/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin contact#site.com
ServerName site.com
ServerAlias admin.site.com
Redirect permanent "/" "https://admin.site.com"
DocumentRoot /var/www/site/interface/
<Directory /var/www/site/interface/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
defaut-ssl.conf
ServerAdmin contact#site.com
ServerName site.com
ServerAlias admin.site.com
DocumentRoot /var/www/site/interface/
<Directory /var/www/site/interface/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
...
</VirtualHost>
.htaccess
`# Remove the question mark from the request but maintain the query string
RewriteEngine On
# Uncomment the following line if your public folder isn't the web server's root
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,R]
Do you have any insight about why it is not working and the slash get removed ?
I solved my issue simply :
I have added a trailing slash at the end to the redirect permanent directive.
Redirect permanent "/" "https://admin.site.com/"
I had some conflict as well with some directive. So I removed all the Directory directive to my conf file and let them only on my apache2.conf .
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

How to configure wordpress application in subdirectory with simple php application using .htaccess / Apache2?

I want to configure a Wordpress application with a simple php application. The directory structure of the application is as follow :
Root directory : /var/www/demoApp/
Wordpress directory : /var/www/demoApp/wordpress/
Here i want to access the wordpress application using route http://BASE_URL/wordpress. But i am not able to configure the htaccess file. All the php pages under /var/www/demoApp/ directory are working fine using url http://BASE_URL/. While wordpress files are not being loaded correctly.
Here is my Apache configuration block :
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /var/www/demoApp
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/demoApp>
Options 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>
What should be the .htaccess file?
My configuration:
domain: test.localhost
wordpress url: test.localhost/wordpress
.htaccess in the wordpress folder:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
Apache settings for the subdomain (Wamp server under windows)
<VirtualHost *:80>
DocumentRoot "e:\Sync\www\test"
ServerName localhost
ServerAlias test.localhost
<Directory "e:\Sync\www\test">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
</Directory>
</VirtualHost>
I had this issue while trying to modify a few absolute paths to relative paths. The problem was that I left an extra / at the start of the relative path.
Correct Code:
About
<!--The link goes to to http://BASE_URL/wordpress_subdirectory/about-->
Errorneous code:
/About
<!--This href is relative to the 'Root'. It goes to http://BASE_URL/about-->

configure virtual hosts in azure ubuntu to run multiple laravel applications

I have created 2 laravel applications in /home/azureuser directory.
I want to run multiple laravel applications on single ubuntu VM. I tried configuring virtual hosts but not able to make it work.
Below is the contents of /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName apitesting.cloudapp.net/demo
DocumentRoot /home/azureuser/demoapp/public
<Directory /home/azureuser/demoapp/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
SetEnv APPLICATION_ENV dev
LogLevel warn
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName apitesting.cloudapp.net/quiz
DocumentRoot /home/azureuser/quizapp/public
<Directory /home/azureuser/quizapp/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
SetEnv APPLICATION_ENV dev
LogLevel warn
</VirtualHost>
Not sure whether the above is correct.
It seem we cannot set the ServerName in the URL with a sub path param. As according your requirement, you can leverage the rewrite mod.
First, install apache rewrite mod via command: sudo a2enmod rewrite, then restart apache via: sudo service apache2 restart.
After that, modify the config file /etc/apache2/sites-enabled/000-default.conf, config the directory to the parent folder of your applications:
...
DocumentRoot /home/azureuser
ServerName apitesting.cloudapp.net
<Directory /home/azureuser>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
...
Then create a file named .htaccess in the root directory of your application, to redirect the incoming requests to your public folders, with the content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

apache - my .htaccess doesn't work only for 1 sub-domain and work for other

I'm using Ubuntu wizzy as my local server and then I set up domain there which are
domain.svr
api.domain.svr
adm.domain.svr
And here is the problem. I've create exactly same configuration for all of them but why only adm.domain.svr doesn't work? It's always response 404 when I goes to http://adm.domain.svr/site/dashboard/ but it's okay when I try http://api.domain.svr/site/dashboard/
Here is my configuration
<VirtualHost *:80>
ServerAdmin localhost#gmail.com
ServerName domain.svr
DocumentRoot /home/shaf/web/domain.dev/frontend/web
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /home/shaf/web/domain.dev/frontend/web>
Require all granted
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog /home/shaf/log/domain-error.log
LogLevel warn
CustomLog /home/shaf/log/domain-access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin localhost#gmail.com
ServerName adm.domain.svr
DocumentRoot /home/shaf/web/domain.dev/backend/web
<Directory /home/shaf/web/domain.dev/backend/web>
Require all granted
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog /home/shaf/log/domain-adm-error.log
LogLevel warn
CustomLog /home/shaf/log/domain-adm-access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin localhost#gmail.com
ServerName api.domain.svr
DocumentRoot /home/shaf/web/domain.dev/api/web
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /home/shaf/web/domain.dev/api/web>
Require all granted
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog /home/shaf/log/domain-api-error.log
LogLevel warn
CustomLog /home/shaf/log/domain-api-access.log combined
</VirtualHost>
and here is my .htaccess which I placed on every domain web folder
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
Please give me advice about this, I really have no idea.
Your ServerName domain.svr is wrong. Apache can not route it. Try to rename it to adm.domain.svr
I just solve this by duplicate another directory to adm and try it but fail, so I create another 1 host so I have 4 host. 1 is duplicate for adm and it's work perfectly. I still didn't know what happen but seems only that folder didn't read the htaccess and I'm sure of it because I already try to swap sub domain but only adm folder doesn't read the htaccess file.
So here is my conclusion and I don't know this is correct or not but apache has cache of htaccess so I need to hard refresh the apache (only restart apache doesn't work because I already tried it several times and nothing happen) so maybe you need to restart your OS / Server and if you doesn't want it, try my way.

Can't configure virtualhosts for XAMPP+Symfony

I keep trying to configure it so that the domain symfony.local would link to the app_dev.php, but I also keep getting forwarded to the xampp page.
My hosts file is:
127.0.0.1 symfony.local
My httpd-vhost is:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
ServerName symfony.local
DocumentRoot "C:\xampp\htdocs\testAS\web"
DirectoryIndex app_dev.php
<Directory "C:\xampp\htdocs\testAS\web">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app_dev.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
I'm using Windows 8. Appreciate any feedback.
I assume it's a fairly recent version of xampp? There is a new directive "Require local" that popped up a few years ago. I remember being stumped by it.
<Directory "C:/home/ahundiak/zayso2016/cerad3/web">
## Options Indexes FollowSymLinks
AllowOverride All
Require local ## Add This
</Directory>
<VirtualHost *:80>
ServerName local.api.zayso.org
DocumentRoot "C:/home/ahundiak/zayso2016/cerad3/web"
</VirtualHost>
I am not an expert on configuring this. The above works for me using the Symfony 2 .htaccess file.
may be it issue of your hosts file entry of symfony.local and local ip address or may between them only TAB(on keyboard) require ...
OR if above answer not work follow below
please follow this link Click Here it help you solve your issue of not show symfony project

Categories