Unable to access backend after changing the default document root - laravel

I have hosted a website recently on AWS ec2 ubuntu instance. My directory structure consists of two folders:
back (consists of laravel 5.2)
front (consists of index.html,css and javascript files)
I am using laravel for the back end. Whenever I am accessing my website say
www.abc.com I am getting the default ubuntu page. So, I had to manually go to www.abc.com/front/index.html. As a workaround, I changed the Document root in /etc/apache2/sites-available/000-default.conf
from /var/www/html to /var/www/html/front. Everything works fine except for one thing - I am unable to access the back folder using the link www.abc.com/back/public.
What I think is happening would be I am now accessing www.abc.com/front/back/public.
What should be done now?
000-default.conf :
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/front
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

replace your DocumentRoot to
DocumentRoot /var/www/html/front/public
and put these inside your conf
<Directory /var/www/html/front/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

Related

laravel app won't appear on localhost

I am having issues with my xampp and locahost and laravel projects. When I create a new laravel project: composer create-project --prefer-dist laravel/laravel fmvcei in my C:/xampp/htdocs folder, when I type in localhost/fmvcei/public, nothing appears. I pulled from another stack overflow question on this where it suggested removing the NameVirtualHost *:80. When I try to configure my host files to be able to type fmvcei.test in the browser, still nothing. I have restarted xampp each time. Here are my httpd/vhost and host files:
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
##ServerAdmin webmaster#dummy-host.example.com
##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
##ServerName dummy-host.example.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>
##<VirtualHost *:80>
##ServerAdmin webmaster#dummy-host2.example.com
##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
##ServerName dummy-host2.example.com
##ErrorLog "logs/dummy-host2.example.com-error.log"
##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerAdmin admin#localhost
ServerName localhost
<Directory "C:/xampp/htdocs/">
Options Indexes FollowSymLinks
AllowOverride all
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/fmvcei/public"
ServerAdmin admin#localhost
ServerName fmvcei.test
ServerAlias www.fmvcei.test
<Directory "C:/xampp/htdocs/fmvcei/public">
AllowOverride All
Options Indexes FollowSymLinks
Require local
# if you want access from other pc's on your local network
#Require ip 192.168.1
# Only if you want the world to see your site
#Require all granted
</Directory>
</VirtualHost>
hosts file:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 tbhtoat.app
127.0.0.1 fmvcei.test
First things, make sure both Apache and MySQL are running.
Move to the root project directory, fmvcei in your case, then run this command php artisan serve. you can browse by 127.0.0.1:8000
NB. you need to install composer if you don't yet.

I'm not able to configure my virtual host in XAMPP and also I want to change my root htdocs directory to a different folder

NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot C:/Users/user/Desktop/WebsiteDesign
ServerName testproject
<Directory "C:/Users/user/Desktop/WebsiteDesign">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
I have gone to C:\xampp\apache\conf\extra\httpd-vhosts.conf and changed the values.
After making the changes I went to C:\Windows\System32\drivers\etc\host
Also following all these steps I stopped and started Apace Service from the XAMPP control panel. Still it's not working. I have also given the httpd-vhost.conf file. Can someone please guide me to configure step by step. my xampp version is 3.2.2
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry
about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
##ServerAdmin webmaster#dummy-host.example.com
##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
##ServerName dummy-host.example.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot C:/Users/user/Desktop/WebsiteDesign
ServerName testproject
<Directory "C:/Users/user/Desktop/WebsiteDesign">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

HOW TO: Set up a Virtual Host on Apache 2.4.4 [ MAC / *NIX ]

I am posting this because I recently had a lot of trouble setting up a Virtual Host with a MAMP stack, due to Apple's throttling of the useable PHP version on Mac OS 10.8's default Apache2 installation.
This is a very quick guide on what to do and I owe the solution to this question on Stack Overflow:
Information Source
You can think of this as a compilation of what worked for me, as the accepted answers had no effect, but rather those with a significantly lower score.
Similarly, every guide I have seen fails to mention some points which users answered with on the sourced question.
Step 1: Install and configure Apache.
Make sure you specify what port you want to listen on, for me I specified 8080. This will be the case for this series of instructions.
Listen 8080 - Default is 80
Step 2: Edit your /etc/hosts file to spoof your loopback address, 127.0.0.1
127.0.0.1 localhost
127.0.0.1 some.example # domain-name.domain-TLD
127.0.0.1 www.some.example # The same as the above line, but with www. prefixed
You should really add a handle for subdomains on your web server, Apache or Nginx (or whatever else you use. Something that routes www to non-www.
Step 3: Enable the Virtual Hosts import on Apache.
Open your httpd.conf file located within Apache2's subdirectories. Usually within /conf
Uncomment the line that resembles this: Include conf/extra/httpd-vhosts.conf
Also uncomment this module import: LoadModule log_config_module modules/mod_log_config.so
Step 4: Configure your Virtual Hosts file
Find your Virtual Hosts config, httpd-vhosts.conf, you can comment out the two example Virtual Hosts in the file. Usually within /conf/extra
Copy your own Virtual Host into the file from this template:
<VirtualHost *:80> # Change the 80 to the number Apache2 "Listen"s on. In my case, 8080
ServerName SERVER-ADDRESS # E.g. mywebsite.local
ServerAlias WWW.SERVER-ADDRESS # E.g. www.mywebsite.local
DocumentRoot " SERVER-FILE-ROOT " # E.g. "Users/user-name/Sites"
<Directory /> # This should be a full path, though
Require all granted # Required for permission errors
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride none
</Directory>
</VirtualHost>
You're Done!
Once your Virtual Host has been edited to your liking you are done, just restart Apache and enjoy.
This guide already includes the fixes implemented, but in-case you still get permission errors:
You MUST make sure that your DocumentRoot is not inside any documents your user explicitly owns. If it needs to be, give "Read Only" access to "Everyone" on Mac for that particular folder, E.g. "Documents" or "Movies" etc....
Although the above answer is much explanatory, the following 2 things are most important when you are migrating virtual hosts to apache 2.4
Go to wamp/bin/apache/apache2.4.x/conf/httpd.conf find #Include conf/extra/httpd-vhosts.conf and uncomment to Include conf/extra/httpd-vhosts.conf
Add the virtual hosts in wamp/bin/apache/apache2.4.x/conf/extra/httpd-vhosts.conf as
<VirtualHost *:80>
ServerAdmin admin#localhost.com
DocumentRoot "H:/Wamp/www/mysite"
ServerName mysite
ServerAlias mysite
<Directory />
Require all granted
</Directory>
</VirtualHost>
Note: <Directory **/**> the / is important

vagrant laravel vhost set up

So i have a public network VM set up with Vagrant and PuPHPet to get an apache web server up and running. I'm using Laravel as my framework of choice. I can access my site in my browser by visiting the following:
http://192.168.1.14/public/index.php/
Using PuPHPet i configured my vhost to use "phptest.dev" as the Server Name.
I'm a little stuck on how i should set a vhost to prettify my url. I'm not sure where the "phptest.dev" server name comes into play. I can't ping phptest.dev and get anything back.
What is the proper way to set this up? I'd like to visit "phptest.dev" in my browser to see my site. I think i need to add an .htaccess file to route all requests through the 'public/index.php` file so i can get that out of the url but i'm not sure.
Don't know PuPHPet but I can answer in a generic way.
You can use /etc/hosts file to do name resolution, as long as you haven't changed /etc/nsswitch.conf.
For example in /etc/hosts, add
192.168.1.14 phptest.dev
You should be able to ping the hostname from within the VM.
Suppose you are using Debian/Ubuntu, the sites configuration file is in /etc/apache2/sites-available/phptest.dev.conf
NOTE: don't forget to create a symbolic link in sites-enabled
<VirtualHost *:80>
ServerAdmin EMAIL
DocumentRoot /path/to/php
ServerName phptest.dev
ServerAlias www.phptest.dev
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /path/to/php>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/phptest.dev-error_log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/phptest.dev-access_log combined
</VirtualHost>
Do a service apache2 reload or restart and see if you can access by using phptest.dev
I can't respond directly to Terry Wang, but he's mostly right.
Ignore everything past his 4th line, though, because PuPHPet takes care of setting up the vhost in your VM for you.
You simply need to tell your local machine (your Mac or your Windows or maybe your Linux machine) that the domain phptest.dev is located at ip address 192.168.1.14.
That's why you need to edit your hosts file.

Setting up a virtual host on XAMPP on Mac

I am trying to set up a virtualhost on my apple mac on localhost. The server is provided by XAMPP, which bundles Apache/MySQL/PHP in one bundle.
Here is what I have done so far:
Edited /private/etc/hosts to include 127.0.0.1 to point to test.myserver.local
127.0.0.1 test.myserver.local
Edited /Applications/XAMPP/etc/extra/httpd-vhosts.conf to inlcude my vhosts details
<VirtualHost *:80>
DocumentRoot /Users/???/Documents/workspace/trunk/htdocs
ServerName test.myserver.local
<Directory "/Users/???/Documents/workspace/trunk/htdocs">
AllowOverride All
</Directory>
</VirtualHost>
Placed a simple index.html in there with the word test in it.
I have restarted the server, and then browse to the test url to be greeted with Apache's default page instead of my test page.
The vhosts file works for another virtual host, the code is copied with the respective bits changed (i.e. folder paths), the hosts file works, as when Apache is turned off, my browser says server not found.
Why is Apache refusing to show up my test code? Are there any other files I need to change? I cant think of any others, its usually just those on linux/windows.
On xampp you need to edit 3 files to setup virtual hosts
the /etc/hosts and /Applications/XAMPP/etc/extra/httpd-vhosts.conf as you did.
But also you need to edit /Applications/XAMPP/xamppfiles/etc/httpd.conf to include the http-vhosts.conf
make sure you have uncommented this line
# Virtual hosts
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
EDIT
Have you tried to add this lines
Order allow,deny
Allow from all
Just before the
AllowOverride All
Try leaving the the setting for "localhost" at the end of the file "httpd-vhosts.conf",
i.e.:
#
# Virtual Hosts
#
...
# others vhost
<VirtualHost *:80>
...
</VirtualHost>
# localhost
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
#end of httpd-vhosts.conf file
Worked for me, greetings!
Have you told Apache to actually use name-based virtual hosting?
# Use name-based virtual hosting.
#
NameVirtualHost *:80
I don't believe it's enabled by default in Xampp on Mac.

Resources