douza19870617 2017-10-23 13:42
浏览 57
已采纳

在不使用工匠服务的情况下运行laravel项目的最佳方法是什么?

guys I have a laravel project and its working fine. Every time I start the project by typing the command php artisan serve and then by typing the url localhost:8000 in my browser. But now I want to start my project only by typing the url localhost/projectname.

So I did a little bit of digging and found out a way to do this, I made it possible by changing the server.php file from root directory to index.php and copying the htaccess file from public folder to root directory`. This way my browser loaded only html file or php file but css files and js files were not loaded so I had to modify there link on the blade file for example:

Previously a style.css file was linked as:

 <link rel="stylesheet" type="text/css" href="{{asset('front_end/assets/css/style.css')}}">

Now I link the same style.css file as below:

<link rel="stylesheet" type="text/css" href="{{asset('/public/front_end/assets/css/style.css')}}">

And It works fine.

But now I have found another problem, I have stored some files (images) in the the storage/app/public/myfolder directory so to access the files I had to use the command php artisan storage:link command and to access the files(images) from above mentioned directory from blade file I use the code below:

<img src="{{$url = Storage::url('myfolder/'.$company->logo_name)}}"> 

This code did worked only worked when I used to start my project using php artisan serve command. Now I its not linking so what should I do? And also can you guys tell me the way that I changed the server.php file to index.php is the right way or not? And what you guys do in your real projects?

Thank You.

  • 写回答

3条回答 默认 最新

  • drryyiuib43562604 2017-10-23 13:59
    关注

    When deploying a Laravel project you want your nginx or apache configuration to point to your public path of your project. Changing the server.php or index.php files are not necessary.

    Apache Config Example:

    <VirtualHost *:80>
       ServerName project.dev
       DocumentRoot "/home/vagrant/projects/project/public"
       <Directory "/home/vagrant/projects/project/public">
          AllowOverride all
       </Directory>
    </VirtualHost>
    

    As you can see with this apache config example, it points to the public directory of your project.

    You can achieve this locally by installing either Apache or nginx on your local machine.

    I would recommend following Laravel's documentation guide on using Vagrant's Homestead to get an idea of how this is working before you decide to run this on a server. A link here

    There is a couple of options you can take to achieve essentially the same goal. This depends on the machine you are running on and personal preference.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化