David
David

Reputation: 10758

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.

Upvotes: 0

Views: 1762

Answers (2)

Juan Treminio
Juan Treminio

Reputation: 2178

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.

Upvotes: 1

Terry Wang
Terry Wang

Reputation: 13920

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

Upvotes: 2

Related Questions