Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dagfooyo's avatar

404 error on /login

I deployed a brand-new Laravel project to my EC2 server and it shows up fine, but when I set up Auth it 404's when trying to view /login. Apache's serving the public directory fine because phpinfo loads just fine on the server as you can see: http://ec2-18-222-152-185.us-east-2.compute.amazonaws.com/info.php But the login 404's as you can also see: http://ec2-18-222-152-185.us-east-2.compute.amazonaws.com/login

What could be going on?

I've read through the thread here: https://laracasts.com/discuss/channels/laravel/the-requested-url-login-was-not-found-on-this-server?page=1 But none of the solutions there helped. I was advised to start a new thread as that one was marked as "solved."

I've also tried creating other routes in web.php and none of them work either so I'm thinking it may be a problem with the routing functionality.

1 like
20 replies
Cronix's avatar

Do you still have the .htaccess in the /public dir? Is the DocumentRoot set to the /public dir?

dagfooyo's avatar

Yes, and yes. I've found that I can put files and folders into /public and view them as if it was a static site.

.htaccess file in public looks like this:

<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>
Cronix's avatar

Do you have mod_rewrite enabled in apache? Edit, is it also called "mod_rewrite.c" or is it "mod_rewrite.so"?

dagfooyo's avatar

Hm. I thought I had. When I try to enable mod_rewrite based on the instructions for my server OS (Amazon Linux 2)

sudo a2enmod rewrite

I get the error "sudo: a2enmod: command not found"

With that not working, I'm not sure how to enable it or how to check if it's enabled.

1 like
Cronix's avatar

try apachectl -t from the cli to see if there's a config issue.

dagfooyo's avatar

CLI says "syntax OK" which I'm guessing is a yes?

Cronix's avatar

That just tests the config to see if there are any problems. Now try apache2ctl -M to see the list of loaded modules

1 like
dagfooyo's avatar

Hm. "-bash: apache2ctl: command not found"

dagfooyo's avatar

oh, looks like for this version of linux the command is "httpd -M" and the result is

Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 access_compat_module (shared)
 actions_module (shared)
 alias_module (shared)
 allowmethods_module (shared)
 auth_basic_module (shared)
 auth_digest_module (shared)
 authn_anon_module (shared)
 authn_core_module (shared)
 authn_dbd_module (shared)
 authn_dbm_module (shared)
 authn_file_module (shared)
 authn_socache_module (shared)
 authz_core_module (shared)
 authz_dbd_module (shared)
 authz_dbm_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_owner_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cache_module (shared)
 cache_disk_module (shared)
 cache_socache_module (shared)
 data_module (shared)
 dbd_module (shared)
 deflate_module (shared)
 dir_module (shared)
 dumpio_module (shared)
 echo_module (shared)
 env_module (shared)
 expires_module (shared)
 ext_filter_module (shared)
 filter_module (shared)
 headers_module (shared)
 include_module (shared)
 info_module (shared)
 log_config_module (shared)
 logio_module (shared)
 macro_module (shared)
 mime_magic_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 remoteip_module (shared)
 reqtimeout_module (shared)
 request_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 slotmem_plain_module (shared)
 slotmem_shm_module (shared)
 socache_dbm_module (shared)
 socache_memcache_module (shared)
 socache_shmcb_module (shared)
 status_module (shared)
 substitute_module (shared)
 suexec_module (shared)
 unique_id_module (shared)
 unixd_module (shared)
 userdir_module (shared)
 version_module (shared)
 vhost_alias_module (shared)
 watchdog_module (shared)
 dav_module (shared)
 dav_fs_module (shared)
 dav_lock_module (shared)
 lua_module (shared)
 mpm_prefork_module (shared)
 proxy_module (shared)
 lbmethod_bybusyness_module (shared)
 lbmethod_byrequests_module (shared)
 lbmethod_bytraffic_module (shared)
 lbmethod_heartbeat_module (shared)
 proxy_ajp_module (shared)
 proxy_balancer_module (shared)
 proxy_connect_module (shared)
 proxy_express_module (shared)
 proxy_fcgi_module (shared)
 proxy_fdpass_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_hcheck_module (shared)
 proxy_scgi_module (shared)
 proxy_uwsgi_module (shared)
 proxy_wstunnel_module (shared)
 systemd_module (shared)
 cgi_module (shared)
 http2_module (shared)
 proxy_http2_module (shared)

dagfooyo's avatar

Just followed those instructions and added this block to my httpd.conf file:

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

Restarted httpd and it's still giving a 404.

There's also this block in the .conf file which I left:

<Directory />
    AllowOverride none
    Require all denied
</Directory>

Do I need to remove that one?

Cronix's avatar

Is /var/www where your project is located (or in that www dir)?

Cronix's avatar

Try commenting out that 2nd block and restarting the server. Beyond that, I don't think I can help much more. I've forgotten most of my apache knowledge as I really haven't used it for many years now.

Also, if you have a small budget ($12-$19/mo to spare), personally I'd use a service like Laravel Forge, which can set up your AWS server with everything needed and is really simple to use. It has automatic deployments, free ssl certs, and a lot of other goodies to make this stuff simple. Laracasts just created a new video series to show it off. I'd watch it.

https://laracasts.com/series/learn-laravel-forge

https://forge.laravel.com/

newbie360's avatar

can you show all the virtual host code , mask the ServerName

no no no, don't remove this

<Directory />
    AllowOverride none
    Require all denied
</Directory>
dagfooyo's avatar

Aha! It WAS the AllowOverride! I had forgotten that I'd already put it in httpd.conf before, but I hadn't changed "none" to "all". So when I re-added it further up the document it was superceded by the incorrect instructions further down. Routes are serving correctly now :-)

Thanks for your help!

newbie360's avatar

be careful, you are change the AllowOverride in virtual host , not in this

# don't touch this
<Directory />
    AllowOverride none
    Require all denied
</Directory>
dagfooyo's avatar

OK I feel like a complete newb now... how do I mark this thread as "solved?" I don't see an obvious button to do so.

1 like
Cronix's avatar

@dagfooyo Next to each post, under the persons avatar, there are 2 icons. Thumbs up to "like" a post, and the checkbox to mark that post as the solution for the one that helped the most.

Please or to participate in this conversation.