Question

Deploying a Laravel Project in a LAMP Ubuntu 20.4 Droplet. All pages throw 404 not found except the root "/"

Hi All.

I created a droplet using the LAMP droplet from the marketplace and used the following link to set it up:

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-laravel-with-nginx-on-ubuntu-20-04

Replacing the nginx with apache configurations. The home page(root) is showing but every other page throws a 404 not found. At some point I also had to go through this article for one of the errors that was appearing with apache:

https://www.digitalocean.com/community/tutorials/apache-configuration-error-ah00558-could-not-reliably-determine-the-server-s-fully-qualified-domain-name

Any help would be appreciated. Below I’ve added my error log, the apache 000-default configuration, and the .htaccess file in the Laravel public folder.

error.log

[Mon Aug 16 17:19:58.899476 2021] [mpm_prefork:notice] [pid 34331] AH00169: caught SIGTERM, shutting down
[Mon Sep 13 13:34:22.991863 2021] [mpm_prefork:notice] [pid 863] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Mon Sep 13 13:34:23.072201 2021] [core:notice] [pid 863] AH00094: Command line: '/usr/sbin/apache2'
[Mon Sep 13 20:29:25.526729 2021] [mpm_prefork:notice] [pid 863] AH00171: Graceful restart requested, doing restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Mon Sep 13 20:29:25.670884 2021] [mpm_prefork:notice] [pid 863] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Mon Sep 13 20:29:25.670901 2021] [core:notice] [pid 863] AH00094: Command line: '/usr/sbin/apache2'
[Mon Sep 13 20:56:05.646164 2021] [mpm_prefork:notice] [pid 863] AH00171: Graceful restart requested, doing restart
[Mon Sep 13 20:56:05.757679 2021] [mpm_prefork:notice] [pid 863] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Mon Sep 13 20:56:05.757696 2021] [core:notice] [pid 863] AH00094: Command line: '/usr/sbin/apache2'
[Mon Sep 13 21:10:59.372735 2021] [mpm_prefork:notice] [pid 863] AH00169: caught SIGTERM, shutting down
[Mon Sep 13 21:10:59.530231 2021] [mpm_prefork:notice] [pid 34337] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Mon Sep 13 21:10:59.530299 2021] [core:notice] [pid 34337] AH00094: Command line: '/usr/sbin/apache2'
[Tue Sep 14 00:00:08.417459 2021] [mpm_prefork:notice] [pid 34337] AH00171: Graceful restart requested, doing restart

000-default.conf

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/public

        <Directory /var/www/html/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

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

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

</VirtualHost>

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

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


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Hi there,

As the configuration looks good, it sounds like that the Mod Rewrite is not enabled.

To enable this for Apache run:

sudo a2enmod rewrite

After that you might have to restart Apache as well:

sudo systemctl restart apache2

Let me know how it goes! Best, Bobby

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.