404 on GET request Laravel 9 - php

I'm working on a project with the new version of Laravel. My other projects are all previous versions. I tried every artisan clean method to make everything clear. I checked the server requirements, which are precisely the same as how I run my other Laravel 8 projects. But when I request by Postman my API, it returns a 404 page instead of the actual action.
Route
GET|HEAD api/token ... generated::*** › UserController#tokenRequest
api.php
Route::get('token', [UserController::class, 'tokenRequest']);
I return a simple response with a token. If there is a PHP error, I'll see it and not return with a 404, which is weird. I had the same problem with my other projects, but it was just a mod_rewrite issue, but I all checked those options. Each is set correctly in the .conf. I use apache on my Ubuntu 20.04 server, like my other projects. The only difference is the Laravel version.
URL that I use:
https://example.com/directory/api/token
Public directory URL is working perfectly.
https://example.com/directory/public
Custom domain .conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#domain1.com
DocumentRoot /var/www/html
<Directory /var/www/html>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com.log combined

I usually setup vhost for each project and this is how it looks like for me:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#domain1.com
DocumentRoot /var/www/html/example.com/public
<Directory "/var/www/html/example.com/public">
AllowOverride All
ReWriteEngine On
Options Indexes MultiViews FollowSymLinks
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com.log combined
and this worked for all my laravel apps

Related

Laravel redirects resources to https on localhost and got 404

I set up xampp apache on macos.
Added to httpd-vhosts.conf to have separated url from my other projects
<VirtualHost *:80>
ServerAdmin admin#abc.local
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/abc_web/public"
ServerName abc.local
ServerAlias www.abc.local
<Directory "/Applications/XAMPP/xamppfiles/htdocs/abc_web/public">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/abc.local-error_log"
CustomLog "logs/abc.local-access_log" common
</VirtualHost>
also on hosts file
127.0.0.1 abc.local
But after this all my assets tying to load over HTTPS
and getting 404
<script src="{{ asset('/js/app.js') }}" defer></script>
When I open it direct on browser over HTTP http://abc.local/js/app.js it loads without any problem.
Also when I run php artisan serve and go to localhost:8000 everything is ok.
I don't understand why.

Laravel 7 - server only serving root page

I'm trying to serve a Laravel 7 site on my server, built using a Raspberry Pi and storing the files on an external hard drive.
I cloned my Laravel project from Github, ran composer install and after a bit of fiddling and configuration, the root page loaded. However, the root page is the only route that will load. Neither my own routes nor the auth routes generated by Laravel work. Any attempt to access a different route leads to a 404 error thrown by Apache on my server.
Here is my VirtualHost config file in Apache:
<VirtualHost *:80>
ServerName myurl.tld
ServerAdmin myemail#example.com
DocumentRoot /mnt/external/public_html/MyProject/public
<Directory /mnt/external/public_html/MyProject>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Not sure what is going on here. The same thing happens with projects generated on the server as well as the cloned project.
Permissions on /mnt/external/public_html/MyProject are set to 775 all the way up to external, and the whole path is owned by the www-data user.
Try the below VirtualHost config
<VirtualHost *:80>
ServerName myurl.tld
ServerAdmin myemail#example.com
DocumentRoot /mnt/external/public_html/MyProject/public
<Directory /mnt/external/public_html/MyProject/public>
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Restart Apache.

Setup VirtualHost for Zend Application on Wamp server

I'm following this tutorial to learn how to start a project using ZendFramework
http://framework.zend.com/manual/1.12/en/learning.quickstart.create-project.html
When I get to setup a virtual host I get stuck. If I do exactly as the tutorial says, it shows me an error (in all my project, zend or not), says the file wasn't found.
Then I found this tutorial on StackOverflow very handy
Can't run zend framework MVC application on WAMP
Following what the guy on the bottom of the page says takes me to the same error when I try to access my app as zendProject.local/
This is what I got
on hosts (Windows/System32/drivers/etc/hosts) file
127.0.0.1 blog.local
on httpd-vhosts.conf file
<VirtualHost 127.0.0.1>
ServerName blog.local
DocumentRoot /blog/public
SetEnv APPLICATION_ENV "development"
<Directory /blog/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Can you tell me what I am doing wrong? The browser still says Not Found The requested URL /public was not found on this server when I go to http://blog.local/
I'm running WAMP on Windows. And this is the absolute path to the 'blog' project C:\wamp\www\blog
#Edit RiggsFolly
this is what I got now in the httpd-vhosts.conf file
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www">
AllowOverride All
# make sure this is only allowed to be accessed by the local machine
# then if/when you open one of your other sites up to the internet and somebody uses your IP
# they will get directed here as its the first VH def and then receive a 403 not allowed to access
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/websites/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/websites/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
And I created a new directory at C:/ called 'websites' as you suggested
You need to be a little more specific with your folder locations. I guess this tutorial was written for Unix and you are using windows.
For Apache 2.2.x use this syntax:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/wamp/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/wamp/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
You would be better avoiding the Allow from all and using Allow from localhost 127.0.0.1 ::1 until you actually want to allow the universe to see your sites.
For Apache 2.4.x use this syntax:
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/wamp/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/wamp/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
Note NameVirtualHost *:80 no longer required for Apache 2.4.x
Again you would be better avoiding the Require all granted and using Require local until you actually want to allow the universe to see your sites.
EDITED After comment from Questioner:
Right, that's the Apache default. If you enter a url it cannot find a Virtual Host definition for it will default to the first Virtual Host definition you gave it, the blog in your case.
Ok, so now you need to create a Virtual Host for each of your other projects, and MOST IMPORTANTLY the first one needs to be localhost and only be allowed to be accessed from the local PC for a bit of extra security.
Now personally I would take this opportunity to move my actual sites to a totally separate folder structure outside the \wamp\ folder structure so there is no confusion with rights given to the \wamp\www folder and my other sites.
So for example, create a folder c:\websites\www and in that folder create a folder for each of your projects eg
c:\websites\www\blog
c:\websites\www\project2
Then point your virtual hosts to the relevant folder containing the site code ( this can be on another disk if you like ). This allows you to specify the Apache security ( who is allowed in to this site) specifically for each of your VHOSTS. So when you want a client or friend to be able to play with one site, you just change the security on that one site while you let them play.
Like this:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www">
AllowOverride All
# make sure this is only allowed to be accessed by the local machine
# then if/when you open one of your other sites up to the internet and somebody uses your IP
# they will get directed here as its the first VH def and then receive a 403 not allowed to access
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/websites/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/websites/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName project2.dev
DocumentRoot "C:/websites/www/project2"
Options Indexes FollowSymLinks
<Directory "C:/websites/www/project2">
DirectoryIndex index.php
AllowOverride All
Require local
# this site also available to other PC's on my internal network
Require ip 192.168.0
</Directory>
</VirtualHost>
Remember, for each new Virtual Host site you create you also need to add that ServerName (project2.dev) to the hosts file.
hosts file:
127.0.0.1 blog.local
127.0.0.1 project2.dev
I hope this helps.

routing in laravel3 not working properly

I am new bee in Laravel. I have set up Laravel by help of this tutorial. I have set virtual host, on my virtual host I wrote this.
<VirtualHost *:80>
ServerName ranjitalaravel.com
DocumentRoot "/var/www/html/laravel4/public"
<Directory "/var/www/html/laravel4/public">
</Directory>
</VirtualHost>
In my host file i.e. /etc/hosts
127.0.0.1 ranjitalaravel.com
When I type the http://ranjitalaravel.com/ on my browser all list of file inside my laravel directory is showing. But when I type home after it it shows me "The requested URL /home was not found on this server.". I have write this code in route.php inside application folder.
Route::any('home', function()
{
return View::make('home.index');
});
<VirtualHost *:80>
ServerAdmin postmaster#some_server
DocumentRoot "E:/xampp/htdocs/some_server"
ServerName some_server
ServerAlias some_server
ErrorLog "logs/some_server.localhost-error.log"
CustomLog "logs/some_server.localhost-access.log" combined
</VirtualHost>
this works fine to me, hope helps you
Try this configuration
<VirtualHost *:80>
ServerName ranjitalaravel.com
DocumentRoot /var/www/html/laravel4/public
<Directory /var/www/html/laravel4/public/>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
are you using symlinks?
Instead of using VirtualHosts which can get nasty from time to time why not use PHP 5.4 inbuilt development server.
Here's how XAMPP localhost returns object not found after installing Laravel

Problems in installing Laravel at localhost

I am trying to install PHP-Laravel in Windows 8 and I am using Xamp server(localhost). I am following Installing Laravel guide.
According to this guide I am making virtual host using following code :
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/TssApp/public"
ServerName TssApp
<Directory "C:/xampp/htdocs/TssApp/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
</Directory>
</VirtualHost>
//Where "C:/xampp/htdocs/TssApp/public" is path of Laravel public folder
and I have also added following line in in etc/hosts
127.0.0.2 TssApp
After doing necessary steps mentioned in this tutorial when I type "http://TssApp" , it always redirect to "http://tssapp/xampp/" instead of Laravel Home page. I don't know if I am missing any thing.
Note: I can access laravel home page at "http://localhost/tssapp/public/" but want
to use "http://TssApp" link to access my application.
Please help me regarding this issue.
Thanks .
Do you have NameVirtualHost * in your virtual-hosts configuration?
You'll need to restart Apache after any changes to either /etc/hosts or your virtual-hosts configuration files
Try adding the code to C:\xampp\apache\conf\extra\httpd-vhosts.conf instead of adding it to your own conf file. As far as I know xampp will ignore it unless its in the vhosts file.
You could try this.
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs\TssApp\public"
ServerName tssapp
<Directory "C:\xampp\htdocs\TssApp\public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Although you should put your files in the xampp directory and not the htdocs directory, so your files should be C:\xampp\TssApp\public, This would stop people from visiting htdocs which is a public folder and getting access to your application.
According to the documentation (that you point to), you should write
<VirtualHost 127.0.0.2>
and not
<VirtualHost *:80>
Could you try that and restart your computer/server?
Add in:
Allow from all
after
AllowOverride all
The end result should be:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/TssApp/public"
ServerName TssApp
<Directory "C:/xampp/htdocs/TssApp/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Allow from all
</Directory>
</VirtualHost>
Also make sure you are editing the file "httpd-vhosts.conf" found in:
C:\xampp\apache\conf\extra

Categories