dqhsv0147421 2015-05-18 11:07
浏览 61

Laravel符号链接没有丢失前缀

Hopefully someone out there has encountered this before because we haven't been able to find a solution yet.

Currently, we have two different frameworks installed on our server's root directory (/home/username). One of these is a micro framework for serving a very fast API. The other is a Laravel. The directory paths relevant to this question are below:

  • /home/username/public_html (the server's publicly accessible directory)
  • /home/username/microframework/public (the public folder for the micro framework)
  • /home/username/laravel-project/public (the public folder for our Laravel project)

Our goal is to be able to provide multiple prefixes that get routed to the appropriate framework. For example

www.domain.com/api/login --> goes to route /api/login on the micro framework
www.domain.com/account/login --> goes to route /account/login on Laravel
www.domain.com/admin/login --> goes to route /admin/login on Laravel

Attempt #1

The first thing we tried was using symbolic links to direct traffic to the different frameworks

ln -s /home/username/microframework/public/api /home/username/public_html/api
ln -s /home/username/laravel-project/public/account /home/username/public_html/account
ln -s /home/username/laravel-project/public/admin /home/username/public_html/admin

And then in Laravel's routes.php file, we have

Route::get('/account/login', 'AccountController@showLogin');
Route::get('/admin/login', 'AdminController@showLogin');

The issue we have encountered is that we get 403 and 404 errors when using this strategy.

You don't have permission to access /account/login on this server

It seems that we aren't allowed to create a symbolic link that goes to a fake directory (since /home/username/laravel-project/public/account and /home/username/laravel-project/public/admin do not exist). I would have thought this was possible, but it seems not.

Attempt #2

As an alternative, we tried the following approach. We created symbolic links that pointed directly to the framework's public folders.

ln -s /home/username/microframework/public /home/username/public_html/api
ln -s /home/username/laravel-project/public /home/username/public_html/account
ln -s /home/username/laravel-project/public /home/username/public_html/admin

This works, however, we loose the /account and /admin prefixes from our routing. Our Laravel routes.php only worked if it looked like this:

Route::get('/login', 'AccountController@showLogin');
//Route::get('/login', 'AdminController@showLogin'); // this causes conflict since the /login route is already defined

It seems that you can't filter based on the url PRIOR to the public folder, thus the /account and /admin prefixes were not available to define routing. Perhaps there is a setting that would enable this, but we were unable to find it.

So we have two options, but have been unable to get either one working.

  • 写回答

1条回答 默认 最新

  • doqrt26664 2015-07-25 21:32
    关注

    If you want to create a symbolic link for the public folder in order to avoid duplication between the public folder on Laravel project and the public folder on you "www" or public_html folder you need to do this: Out project name is : test1-core

    So if you went throw this guide: https://medium.com/laravel-news/the-simple-guide-to-deploy-laravel-5-application-on-shared-hosting-1a8d0aee923e you need to have 1 laravel project folder under (1 level up) your "www"/public_html folder. Let's say the name of our laravel project is test1-core. Now By the guide you need to copy the public foler from test1-core to the www folder.

    What we need to do is to create a symbolic link with linux to avoid the duplication. Next time you are doing git pull you will not need to copy the public folder to your www folder. First "cd" to your www fodler:

    cd ~
    cd www
    

    Second make the link:

    ln -s ../test1-core/public
    

    If you are on shared hosting and you have multiple folders on your www folder I recommend to named the link:

    ln -s ../test1-core/public test1
    

    Link this you will have test1 "linked folder" and you can redirect a domain to it.

    Godd luck.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable