2014-10-30 32 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