ZF2 Skeleton Application Without Virtual Host?

2019-06-14 12:15发布

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 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();

For access CSS Or Image all time I used $this->basePath() prepend to fetch it.

My application is works fine if I write URL like this:

localhost/projectname/public/modulename

but I doesnt want to use public in url. How can I call my project without "Public" in url.

1条回答
Melony?
2楼-- · 2019-06-14 12:38

Place your folder ProjectName somewhere outside of web server document root and make symbolic link to public folder in it.

For example, if your web server document root:

/var/www/html

place your project to

/var/www

and make simlink

/var/www/html/ProjectName -> ../ProjectName/public

If you work under the Windows OS, it is in much the same way.

For your case make this steps:

  1. Open command prompt as administrator
  2. 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

After that you may try to access your project by URL:

http:\\localhost\projectname

"NTFS symbolic link" on wikipedia

查看更多
登录 后发表回答