Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Laravel Application Development Cookbook

You're reading from   Laravel Application Development Cookbook Since Laravel is so versatile, one of the best learning routes is a cookbook. We've included lots of recipes and guidance on building web application, both simple and complex. It's a pick & mix approach that works brilliantly.

Arrow left icon
Product type Paperback
Published in Oct 2013
Publisher Packt
ISBN-13 9781782162827
Length 272 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Terry Matula Terry Matula
Author Profile Icon Terry Matula
Terry Matula
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Laravel Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Setting Up and Installing Laravel FREE CHAPTER 2. Using Forms and Gathering Input 3. Authenticating Your Application 4. Storing and Using Data 5. Using Controllers and Routes for URLs and APIs 6. Displaying Your Views 7. Creating and Using Composer Packages 8. Using Ajax and jQuery 9. Using Security and Sessions Effectively 10. Testing and Debugging Your App 11. Deploying and Integrating Third-party Services into Your Application Index

Setting up a virtual host and development environment in Apache


When developing our Laravel app, we'll need a web server to run everything. In PHP 5.4 and up, we can use the built-in web server, but if we need some more functionality, we'll need a full web stack. In this recipe, we'll be using an Apache server on Windows, but any OS with Apache will be similar.

Getting ready

This recipe requires a recent version of WAMP server, available at http://wampserver.com, though the basic principle applies to any Apache configuration on Windows.

How to do it...

To complete this recipe, follow these steps:

  1. Open the WAMP Apache httpd.conf file. It is often located in C:/wamp/bin/apache/Apach2.#.#/conf.

  2. Locate the line #Include conf/extra/httpd-vhosts.conf and remove the first #.

  3. Move to the extra directory, open the httpd-vhosts.conf file, and add the following code:

    <VirtualHost *:80>
        ServerAdmin {your@email.com}
        DocumentRoot "C:/path/to/myapp/public"
        ServerName myapp.dev
        <Directory "C:/path/to/myapp/public">
            Options Indexes FollowSymLinks
            AllowOverride all
            # onlineoffline tag - don't remove
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1
        </Directory>
    </VirtualHost>
  4. Restart the Apache service.

  5. Open the Windows hosts file, often in C:/Windows/System32/drivers/etc, and open the file hosts in a text editor.

  6. At the bottom of the file, add the line 127.0.0.1 myapp.dev.

How it works...

First, in the Apache config file httpd.conf, we uncomment the line to allow the file to include the vhosts configuration files. You can include the code directly in the httpd.conf file, but this method keeps things more organized.

In the httpd-vhosts.conf file, we add our VirtualHost code. DocumentRoot tells the server where the files are located and ServerName is the base URL that the server will look for. Since we only want to use this for our local development, we make sure to only allow access to the localhost with the IP 127.0.0.1.

In the hosts file, we need to tell Windows which IP to use for the myapp.dev URL. After restarting Apache and our browser, we should be able to go to http://myapp.dev and view our application.

There's more...

While this recipe is specific to Windows and WAMP, the same idea can be applied to most Apache installations. The only difference will be the location of the httpd.conf file (in Linux Ubuntu, it's in /etc/apache2) and the path to the public directory for DocumentRoot (in Ubuntu, it might be something like /var/www/myapp/public). The hosts file for Linux and Mac OS X will be located in /etc/hosts.

You have been reading a chapter from
Laravel Application Development Cookbook
Published in: Oct 2013
Publisher: Packt
ISBN-13: 9781782162827
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image