How to run Laravel project on normal Apache?

14,238

Solution 1

Yes, it's absolutely possible to serve Laravel applications with Apache. To debug why your links are producing 404 errors, you'll have to provide more information about the URLs these links point to. It's best to always use Laravel's url(), secure_url() or route() helper functions when printing URLs. Also confirm that the Apache module mod_rewrite is enabled (Laravel Installation: Web Server Configuration)

Solution 2

Set up the apache server host file as shown below:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot D:\Users\Dims\Design\MyApplication\public
    ServerName  exampledomain.com
    ServerAlias  www.exampledomain.com
    ErrorLog "C:/some_dir/example.error.log"
    CustomLog "C:/some_dir/example.access.log" combined
    <Directory "D:\Users\Dims\Design\MyApplication\public">
        Options -Indexes
        DirectoryIndex index.php index.html
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Now that you have set the server name to exampledomain.com you also need to set up the hosts(DNS) file in windows so that you can type in exampledomain.com in your browser and access your laravel project.

Editing the hosts file:

Please follow the steps below:

  • Press the Windows key.
  • Type Notepad in the search field.
  • In the search results, right-click Notepad and select Run as administrator.
  • From Notepad, open the following file:

    c:\Windows\System32\Drivers\etc\hosts

  • Make the following changes to the file.

At the end of the file add the following line:

127.0.0.1        exampledomain.com www.exampledomain.com

Click File > Save to save your changes.

What we did here was to tell windows that when we try to access exampledomain.com or www.exampledomain.com do not try to find the server over the internet but take the request to the local machine itself(127.0.0.1) which will in return serve your laravel project.

You can also find one another method here at wikihow -> http://www.wikihow.com/Install-Laravel-Framework-in-Windows

Solution 3

If after configuring the virtualhost you're still unable visit your laravel app, but it works fine with artisan serve, check your apache php version:

Check /etc/apache2/mods-enabled and if the php module is lower than the one required in laravel specifications, update it. In my case:

$ a2dismod php7.0
$ a2enmod php7.2
$ service apache2 reload

Solution found at: https://laracasts.com/discuss/channels/laravel/unexpected-illuminatesupportarrphp-on-line-388

Share:
14,238
Dims
Author by

Dims

Software developer &amp; Machine Learning engineer C/C++/Java/C#/Python/Mathematica/MATLAB/Kotlin/R/PHP/JavaScript/SQL/HTML/ LinkedIn: http://www.linkedin.com/in/dimskraft Telegram: https://t.me/dims12 I prefer fishing rod over fish.

Updated on June 20, 2022

Comments

  • Dims
    Dims almost 2 years

    I have Laravel project and can run it with

    php artisan serve
    

    I am executing this command inside D:\Users\Dims\Design\MyApplication directory. After that I can see site on http://localhost:8000 and can navigate it, although slow.

    Now I am configuring the same place to serve by apache:

    <VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot "D:\Users\Dims\Design\MyApplication\public"
        ServerName myapplication.app
        ErrorLog "logs/myapplication-error.log"
        CustomLog "logs/myapplication-access.log" common
        <Directory />
            AllowOverride none
            Require all granted
            DirectoryIndex index.php
        </Directory>
    </VirtualHost>
    

    Not, that I pointed application not to the root of the project, but to the public directory. This makes me able to open home page of the site, but clicking any links causes error 404.

    If I serve

    DocumentRoot "D:\Users\Dims\Design\MyApplication"
    

    with Apache, I am unable to see home page at all, saying 403 forbidden. This probably because this directory has no index.php.

    So, is it possible to serve Laravel project with Apache?