skip to Main Content

I have apache2 server on Ubuntu 16.04LTS and I have Laravel 5.6 project called book_donation in /var/www/html now when I visit localhost the Laravel welcome screens appear no problem but whenever I click on any url it gives:

Not Found

The requested URL /book_donation/public/login was not found on this
server. Apache/2.4.18 (Ubuntu) Server at 127.0.0.1 Port 80

and here is .htaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

and here is my /etc/apache2/site-available/000-default.conf:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    <Directory "/var/www/html">
         AllowOverride all
         Require all granted
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

My php version is 7.1 and apache version is 2.4.18, how to solve this?

2

Answers


  1. As stated in the docs, you should configure your web server’s document / web root to be the public directory.

    Create a new file /etc/apache2/site-available/book_donation.test.conf:

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName book_donation.test
        ServerAlias www.book_donation.test
        DocumentRoot /var/www/html/book_donation/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

    Edit your /etc/hosts file and add the following:

    127.0.1.1   book_donation.test
    

    Then run:

    sudo a2ensite book_donation.test.conf
    sudo service apache2 restart
    

    Then you should be able to visit book_donation.test and see your site.

    Login or Signup to reply.
  2. I was facing same problem any new route was not working and gave 404 error. Also check php artisan route:list where new route details showing properly but still it was not working. I also tried following command to make it work

    php artisan view:clear
    php artisan config:clear
    php artisan cache:clear

    Here are my project details

    My DocumentRoot is /var/www/html/project/public. when add new route in web.php, it was nor working and gave 404 error but root route was working fine. Means any new route was working. so I did following changes and it start working.

    changed in /etc/apache2/sites-available/project.conf

    <Directory /var/www/html/project/public>

    **Allowoverride All**
    

    and enable url rewrite by running sudo a2enmod rewrite

    restart apache server by running sudo systemctl restart apache2

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search