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条)

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了