没有虚拟主机的ZF2骨架应用程序? [英] ZF2 Skeleton Application Without Virtual Host?
问题描述
我是ZF2的新手.我已经使用虚拟主机在本地计算机上开发了小型应用程序.我想在没有虚拟主机的情况下运行此站点.
I am new in ZF2. I have developed my small application in my local computer using virtual host.I want to run this site without virtual host.
我的文件夹目录结构是这样的:
My Folder Directory Structure is like this:
-ProjectName
-config
-module
-vendor
- zendframework
-public
- css
- img
- JS
- index.php
Index.php文件:
Index.php File:
<?php
/**
* This makes our life easier when dealing with paths. Everything is relative
* to the application root now.
*/
chdir(dirname(__DIR__));
// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
return false;
}
// Setup autoloading
require 'init_autoloader.php';
// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
我一直使用$ this-> basePath()来获取CSS或图像,因此一直用于访问CSS或图像.
For access CSS Or Image all time I used $this->basePath() prepend to fetch it.
如果我这样写URL,我的应用程序就可以正常工作:
My application is works fine if I write URL like this:
localhost/项目名称/公共/模块名称
localhost/projectname/public/modulename
但是我不想在URL中使用public.如何在URL中没有公共"的情况下调用我的项目.
but I doesnt want to use public in url. How can I call my project without "Public" in url.
推荐答案
将文件夹ProjectName
放置在Web服务器文档根目录之外的位置,并在其中建立指向公共文件夹的符号链接.
Place your folder ProjectName
somewhere outside of web server document root and make symbolic link to public folder in it.
例如,如果您的Web服务器文档根目录:
For example, if your web server document root:
/var/www/html
将您的项目放置到
/var/www
并创建simlink
and make simlink
/var/www/html/ProjectName -> ../ProjectName/public
如果您在Windows操作系统下工作,其操作方式几乎相同.
If you work under the Windows OS, it is in much the same way.
针对您的情况,请执行以下步骤:
For your case make this steps:
- 以管理员身份打开命令提示符
-
假设您的用户名是USERNAME,您的Wamp磁盘位置是D:.执行命令:
- Open command prompt as administrator
Suppose your user name is USERNAME, your wamp disk placement is D:. Execute commands:
C:\Users\USERNAME> d:
D:\> cd wamp\www
D:\wamp\www> mklink /D projectname D:\wamp\www\projectname\public
之后,您可以尝试通过URL访问您的项目:
After that you may try to access your project by URL:
http:\\localhost\projectname
这篇关于没有虚拟主机的ZF2骨架应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!