yozawiratama
yozawiratama

Reputation: 4328

which one is better to run laravel?

I have installed laravel in my cpanel and localhost, but i found two way to execute/run laravel.

  1. access the

/public/

  1. use

php artisan serve

if i run in my notebook/localhost i can use php artisan serve and it done well like routing and database, but in my cpanel i cant use the second way, so i must use first way, but it not done well like routing and etc.

So which one is better and how to make the first way run well?

Upvotes: 0

Views: 62

Answers (1)

gmarintes
gmarintes

Reputation: 1308

Normally, you would use

php artisan serve

on your development environment only.

On production servers, you will add a <VirtualHost> or an Alias drective in your Apache configuration.

<VirtualHost *:80>
    ServerAdmin admin@localhost
    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>

With this type of configuration, you can access your Laravel site as: http://your.domain.com/

When using an Alias, your Apache configuration will be something like this:

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>

With this configuration, you will access your laravel as: http://your.domain.com/any/path/you/want

On some web hosting providers, you don't have access to the Apache configuration, in which case, you will have to put your configuration in an .htaccess file inside your public directory. Laravel has a default .htaccess file inside the public directory that contains this:

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

You will have to check if your hosting allows .htaccess

Upvotes: 2

Related Questions