2014-10-30 59 views
0

我已经在我的cpanel和localhost中安装了laravel,但是我找到了执行/运行laravel的两种方法。哪一个更好地运行laravel?

  1. 访问

/公共/

  • 使用
  • PHP人员服务

    ,如果我在我的笔记本上运行/本地主机,我可以使用PHP的工匠服务,并把工作做好像路由和数据库,但在我的cPanel我不能使用第二种方法,所以我必须用第一种方式,但它做得不好像路由等

    那么哪一个更好,如何使第一种方式运行良好?

    回答

    2

    通常情况下,你会在只有你的开发环境使用

    php artisan serve 
    

    在生产服务器上,您将在Apache配置中添加<VirtualHost>或Alias drective。

    <VirtualHost *:80> 
        ServerAdmin [email protected] 
        DocumentRoot /path/to/your/laravel/public 
        ServerName your.domain.com 
    
        <Directory /path/to/your/laravel/public> 
         AllowOverride None 
         Order allow,deny 
         Allow from All 
    
         Options FollowSymLinks 
    
         RewriteEngine On 
    
         RewriteCond %{REQUEST_FILENAME} !-f 
         RewriteCond %{REQUEST_FILENAME} !-d 
         RewriteRule ^(.*)$ index.php/$1 [L] 
        </Directory> 
    </VirtualHost> 
    

    使用这种类型的配置,您可以访问您的Laravel站点: http://your.domain.com/

    当使用别名,你的Apache配置将是这样的:

    Alias /any/path/you/want /path/to/your/laravel/public 
    <Directory "/path/to/your/laravel/public"> 
        Order allow,deny 
        Allow from All 
    
        Options +FollowSymLinks 
    
        RewriteEngine On 
        RewriteBase /any/path/you/want 
    
        RewriteCond %{REQUEST_FILENAME} !-d 
        RewriteCond %{REQUEST_FILENAME} !-f 
        RewriteRule^index.php [L] 
    </Directory> 
    

    有了这个配置,你会访问laravel为:http://your.domain.com/any/path/you/want

    在一些网站托管服务提供商,Y您无权访问Apache配置 ,在这种情况下,您必须将您的配置置于公用目录中的.htaccess文件中。 Laravel有包含此公共目录中默认的.htaccess文件:

    <IfModule mod_rewrite.c> 
        <IfModule mod_negotiation.c> 
         Options -MultiViews 
        </IfModule> 
    
        RewriteEngine On 
    
        # Redirect Trailing Slashes... 
        RewriteRule ^(.*)/$ /$1 [L,R=301] 
    
        # Handle Front Controller... 
        RewriteCond %{REQUEST_FILENAME} !-d 
        RewriteCond %{REQUEST_FILENAME} !-f 
        RewriteRule^index.php [L] 
    </IfModule> 
    

    你必须检查,如果你的主机允许的.htaccess

    +0

    我使用的cPanel在我的主机,那么该怎么办呢? – yozawiratama 2014-10-30 03:21:43

    +0

    不确定您的cpanel是否提供对Apache配置的访问。如果没有,恐怕你将不得不使用.htaccess文件。 – gmarintes 2014-10-30 10:36:41