- Laravel Application Development Cookbook
- Terry Matula
- 395字
- 2021-07-23 15:33:31
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:
- Open the WAMP Apache
httpd.conf
file. It is often located inC:/wamp/bin/apache/Apach2.#.#/conf
. - Locate the line
#Include conf/extra/httpd-vhosts.conf
and remove the first#
. - Move to the
extra
directory, open thehttpd-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>
- Restart the Apache service.
- Open the Windows hosts file, often in
C:/Windows/System32/drivers/etc
, and open the filehosts
in a text editor. - 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
.
- Mastering Machine Learning for Penetration Testing
- 智能網(wǎng)聯(lián)汽車V2X與智能網(wǎng)聯(lián)設(shè)施I2X
- Django 2 by Example
- 正在爆發(fā)的互聯(lián)網(wǎng)革命
- 電力物聯(lián)網(wǎng)工程技術(shù)原理與應(yīng)用
- Building RESTful Web services with Go
- C/C++串口通信:典型應(yīng)用實例編程實踐
- 網(wǎng)絡(luò)設(shè)計與應(yīng)用(第2版)
- 紅藍攻防:構(gòu)建實戰(zhàn)化網(wǎng)絡(luò)安全防御體系
- 大型企業(yè)微服務(wù)架構(gòu)實踐與運營
- Implementing NetScaler VPX?
- 圖神經(jīng)網(wǎng)絡(luò)前沿
- 網(wǎng)絡(luò)基本通信約束下的系統(tǒng)性能極限分析與設(shè)計
- XSS跨站腳本攻擊剖析與防御
- Telerik WPF Controls Tutorial