skip to Main Content

I have a Laravel installation in Xampp and i configured a virtualhost with the url “http://laravel.test” so i don’t have to write “http://localhost/laravel5-upaetest/public/“.

The problem is that now whenever i write the url “http:laravel.test” in my browser it takes me to the root of the htdocs folder and when i write “localhost” it takes me to my laravel project folder.

How can i fix it? the idea is that when write laravel.test it takes me to my project in laravel5-upaetest/public.

This is my httpd-vhosts.conf file:

# 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 [email protected]
    ##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 [email protected]
    ##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>



<Directory c:/xampp>

    AllowOverride All
    Require all granted
    Allow from all
</Directory>

<VirtualHost *:80>
    DocumentRoot c:/xampp/htdocs/laravel5-upaetest/public
    ServerName laravel.test
</VirtualHost>

3

Answers


  1. enter image description here
    I Think, You already use all types of work.

    But you have a mistake, i think.
    Use code like below...
    1. sudo mkdir -p /var/www/example.com
    2. sudo chown -R $USER:$USER /var/www/example.com
    3. sudo chmod -R 755 /var/www
    4. sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
    5. sudo nano /etc/apache2/sites-available/example.com.conf
    6. <VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/example.com
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    7. sudo a2ensite example.com.conf
    8. sudo a2dissite 000-default.conf
    9. sudo systemctl restart apache2
    10. sudo nano /etc/hosts
    11. 127.0.1.1  www.example.com example.com
    
    Login or Signup to reply.
  2. <VirtualHost *:80>
         ServerName localhost
         DocumentRoot "C:xampphtdocs"
         <Directory "C:xampphtdocs">
    
         </Directory>
     </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot "C:/xampp/htdocs/job/public"
        ServerName job.dev
        <Directory "C:/xampp/htdocs/job/public">
            Options FollowSymLinks
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>
    </VirtualHost>
    
    Login or Signup to reply.
  3. these lines

    # The first VirtualHost section is used for all requests that do not
    # match a ##ServerName 
    

    explain your issue – you’ll want to have two blocks in your httpd-vhosts.conf with the first being the generic server files path:

    <Directory c:/xampp>
    
        AllowOverride All
        Require all granted
        Allow from all
    </Directory>
    
    <VirtualHost *:80>
        DocumentRoot c:/xampp/htdocs
    </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot c:/xampp/htdocs/laravel5-upaetest/public
        ServerName laravel.test
    </VirtualHost>
    
    
    

    other things to check would be to restart apache. any config changes (*.conf like the vhosts file) will require a restart of the server to load them.

    you can also add AccessLog and ErrorLog directives to see what’s going on (see the commented out ## lines for examples, check the log files for any messages).

    you’ll probably want to add 127.0.0.1 laravel.test to your hosts file, which for Windows can live in eg C:WindowsSystem32driversetc

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search