Laravel : Redirections in a subfolder - php

I'm working on a local version of a website developed with Laravel. I have a URL like : http://localhost/s/SEO/userinstall which returns a 404 error. In the app/Http/routes.php , I tried the following but I'm still getting the same error :
Route::get('userinstall', 'InstallController#userinstall');
Route::post('userinstall', 'InstallController#saveUser');
Then I tried
Route::get('s/SEO/userinstall', 'InstallController#userinstall');
Route::post('s/SEO/userinstall', 'InstallController#saveUser');
I checked the AllowOverride directive in the Apache configuration file and it seems to be fine :
<Directory />
AllowOverride All
</Directory>
I'm using the defaut Laravel .htacess file. Any idea how I can fix this?
Thanks

By looking into your URL, http://localhost/s/SEO/userinstall
I am assuming s->SEO are directories under an apache root directory and because that you have to use "s/SEO/userinstall" in Route::get('s/SEO/userinstall', 'InstallController#userinstall');
You should Add the Apache Configuration of your website path "../s/SEO" assign a specific domain name. Such as http://sandbox.local such that you could access the site from http://sandbox.local/userinstall
That way, you could access the route by using
Route::get('userinstall', 'InstallController#userinstall');
Try to google it, to get an idea about, how you could setup your project to access through local domain.
Here is the URL which might help you. http://headsigned.com/article/setting-up-local-development-domain-with-apache-vhosts

Related

New Laravel routes showing XAMPP 404 error

I seem to have the problem since today when I wanted to add a new route to a project I have been working on for the past months where XAMPP shows me 404 errors.
I have tried looking everywhere, reinstalled XAMPP, reinstalled my project from github.
The route actually works on other people's computers on the same branch in my repo. making a new route in another project also works.
It's just that in this project XAMPP has decided to take over the error handling from Laravel and give me 404 errors on all new routes I make?
I just can't get into the controller or do anything with the route. I tried changing the route into anything and everything I could think of or find.
Not Found
The requested URL was not found on this server.
Apache/2.4.47 (Win64) OpenSSL/1.1.1k PHP/8.0.6 Server at 360feedback.hz.nl Port 443
*edit: I am using VirtualHost, which has always worked without issues.
every existing route works fine, route:clear does nothing.
Does anyone know what could cause this?
Another edit as i have found out some more things.
So this problem only occurs on my one project. Which makes things even stranger.
I have also found out that the problem so far seems to be fixed if I use the IP from xampp instead of using a custom domain I added in windows hosts
this picture shows the error on the one with domain and no error without domain.
also here is my vhost config
<VirtualHost 127.0.0.3:80>
DocumentRoot "C:/Users/davye/Documents/GitHub/SchoolProject-1/public"
DirectoryIndex index.php
ServerName laravel-gkb.test
<Directory "C:/Users/davye/Documents/GitHub/SchoolProject-1/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>

Why I can't correctly deploy this Laravel web site on my remote Linux server? Is it a virtual host configuration issue?

I am very new in PHP and moreover in Laravel (I came from Java) and I am going totaly crazy trying to correctly deploy a Laravel 5.4 projects that works fine in my XAMPP local environment on my Linux server. The problem should be related to virtual host configuration but I can't find a solution also asking question and reading documentation.
In my local environment (I am using XAMPP on Windows) I have setted this virtual host into the C:\xampp\apache\conf\extra\httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
ServerName laravel.dev
</VirtualHost>
So opening the laravel.dev URL I obtain the standard Laravel homepage (I have yet not replaced it with a landing page).
Then if I open this URL: http://laravel.dev/registration
I obtain the user registration page developed by me, this because I have this route into my web.php file into my project:
Route::resource('/registration', 'RegistrationController');
Then into my RegistrationController.php there is this method showing the resources/views/registration/index.blade.php view
public function index(){
return view('/registration/index');
}
In local environment, with the laravel.dev vhost pointing to the document root of my Laravel website, it works fine.
Now I have uploaded this Laravel website into my remote Linux server, into this folder: /var/www/html/HotelRegistration
But now my problem is that in this remote environment I had not virtual host (correct me if I am doing wrong assertion: from what I have understand the virtual host is used on the local environment to simulate a domain that Laravel need to point to the public folder, is it this reasoning correct?)
Anyway, this is the URL of the public folder of my deployed web site on my remote server:
http://89.36.211.48/HotelRegistration/public/
As you can see opening it the Laravel landing page is correctly shown, the problem is that I can access to the previous registration page, the only way that I have found is to open this URL:
http://89.36.211.48/HotelRegistration/public/index.php/registration
but it is pretty horrible and above all when the registration form is submitted it is generated a POST request toward this URL http://89.36.211.48/registration that end into a 404 Not Found error.
In the past I explained the situation here: What is wrong in the deploy of this Laravel application? Need I an effective domain instead the vhost used on my local environment?
but now I have do some changes to my Apache configuration followint the suggestion given in the previous post (adapting the answer to my folder structure).
So into this Apache folder /etc/apache2/sites-available I created and enabled the laravel.dev.conf related to my new vhost, having this configuration:
<VirtualHost *:80>
ServerAdmin mymain#gmail.com
ServerName 89.36.211.48
ServerAlias www.laravel.dev
DocumentRoot /var/www/html/HotelRegistration/public/
ErrorLog /var/www/html/HotelRegistration/storage/logs/error.log
CustomLog /var/www/html/HotelRegistration/storage/logs/access.log combined
<Directory /var/www/html/HotelRegistration/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
The path are related to where this website is installed on my remote server I am absolutly not sure if these configuration are ok, expecially about the ServerName value (I put here the IP of my server, is it correct?)
Then I enabled this virtual host using this statment:
sudo a2ensite laravel.dev.conf
and I restart apache.
Ok, the problem now is: what have I to do to correctly access to this website?
I still have the same problem, that is:
I still access to the Laravel landing page by this URL: http://89.36.211.48/HotelRegistration/public/
I still access to the registration form page by the horrible URL: http://89.36.211.48/HotelRegistration/public/index.php/registration
Submitting the form I still go to http://89.36.211.48/registration and obtain the same 404 Not Found error page.
So my doubts are:
Is it the virtual host correctly configured?
If it is correct what have I to do to correctly access to this web site? Need I a domain (if yes: what have to point this domain?) or can I use a path into my server in some way (something like: http://89.36.211.48/HotelRegistration/)
I am expanding my comment here.
Set folder structure like on image:
In index.php change paths like this:
line 22
require __DIR__.'/system/bootstrap/autoload.php';
line 36
$app = require_once __DIR__.'/system/bootstrap/app.php';
Thats all what I do when transferring Laravel app to server (and changing .env for database). Sometimes I have to change permissions for storage folders but thats it.

Setup Apigility on Turnkey Lamp

Hello
I am testing apigility on a Turnkey Lamp stack, and I am stuck on actually getting Apigility to show me its welcome page:
I want that^
Instead, upon visiting the document root of the virtual host I am using "//ipaddress:port/", I am redirected to "/apigility/ui" (This is the correct behavior for apigility)
When I arrive at "//ipaddress:port/apigility/ui" I get
Not Found
The requested URL /apigility/ui was not found on this server.
I am now stuck on how to move forward.
I have:
Made sure that the directory permissions are set correctly
Set up my virtual host (text at the bottom)
Made sure that my apigility dir is at the correct location
Made sure apigility is in development mode
Taken my googlefu to its limit
EDIT: I have also successfully opened a phpinfo.php page that I moved into the public folder of the apigility project
EDIT: If I turn off development mode, I do get the page that says how to turn on development mode. Possibly an issue with dev mode?
Edit: I attempted Rahman's fix, but it did not assist with apigility not correctly serving the apigility/ui page. Although it does seem like a cleaner way to use Apache.
Any help would be much appreciated.
To me it seems like there is some issue with the apigility setup, as it starts to redirect me to the correct location, but cannot find the /apigility/ui page it redirects me to.
Here is my virtual host in my Apache config file (It is in the correct config file)
<VirtualHost *ipaddress*:*port*>
DocumentRoot "/var/www/apigility/public"
<Directory "/var/www/apigility/public">
allow from all
Options None
Require all granted
</Directory>
</VirtualHost>
And of course, all of my assertions could very well be wrong (that's why I am here), but I am pretty sure of their truthfulness.
UPDATE:
While Rahman's answer is useful, it does not answer my question. I believe the not found error is related to apigility failing, not Apache incorrectly routing. I will not be accepting that answer, as the problem is not solved. (But would be open to discussion on that answer)
UPDATE: With Rahman's VirtualHost in the apache config file, I only had to enable mod_rewrite, and I can now access the Welcome to Apigility page!
Details on mod_rewrite I found here:
.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Not Found error is because your web server neither can find the location on the server nor can find any rewrite rule for requested url.
So considering that Apiagility has a .htaccess file in the public directory, your problem is in the Apache configuration.
I suggest you edit your Apache configuration file like this:
<VirtualHost *ipaddress*:*port*>
DocumentRoot "/var/www/apigility/public"
<Directory "/var/www/apigility/public">
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

EzPublish does not find his routes

I have installed ez publish (version: community 15.09, system: apache).
I have installed it in my public_html dir, and the public directory is
public_html/web
I can access to the demo page with this URL:
domain.com/
or with this (both version)
domani.com/index.php
but if I try another route, like this:
domain.com/ez
it not work (the server reply: The requested URL /ez was not found on this server.), work only if I include the index in the route:
domain.com/index.php/ez
I searched but found nothing...
Why this?
How to solve?
What you want to do is basically url rewriting.
You have 2 ways to do this :
have mod_rewrite enabled on the Apache side and apply a virtual host configuration like in this template. Make sure you replace the placeholders (%STUFF%) by the correct values.
use a .htaccess file in your public_html/web folder : see an example here
Note : being able to use a .htaccess requires that your apache configuration allows it. It's usually the AllowOverride None|All|... part of your <Directory /path/to/public_html/web>directive : see Apache Documentation here

Laravel basic routing returns 404

I've recently started learning Laravel but there is one problem which I don't know why it occurs. My current Laravel project is located at wamp/www/codebright. When I access localhost/codebright/public I see the welcome page to Laravel.
When I create a simple routing:
Route::get('my/page', function()
{
return "Harro world";
});
and trying to access:
localhost/codebright/public/my/page it returns with 404 error, not even with Laravel error. I've also tried to access: localhost/codebright/my/page and still.
However, if I type in CMD php artisan serve and open a server on 8000 port and then access:
localhost:8000/my/page it works just fine. I would like to know why my first method without the artisan command didn't work.
Thanks in advance!
Note
It seems like that if you have XAMPP installed, none of the problems mentioned above and in the answer comment section are occurring. Basically, if you are using XAMPP, you most likely won't get any error and the program will work just fine.
It is indeed possible to do what you want but if you're not using artisan serve you must have a webserver set up correctly. From your original post you obviously have a webserver set up as you get the welcome page, but it looks to me like one of the following:
You don't have the .htaccess file in place
Your base vhost (or Apache config if not using a vhost) on your web server setup does not AllowOverride All (which is required to allow .htaccess files to work)
You don't have mod_rewrite turned on
You should check these out. As a minimum, Laravel requires a way to turn URIs that don't exist as real files (my/page) into something it can fake a page for. This pretty much requires the use of mod_rewrite and an .htaccess file to specify the rules.
Explanation of the difference between using Apache and artisan serve: artisan serve does not use a 'dumb' webserver like Apache and instead uses a webserver built into PHP which has knowledge of how to handle 'non-existing' URIs that you browse to, which is why you don't need mod_rewrite and the .htaccess file.
Have you created virtual host for your laravel project?
If no here is how to create virtual host in window
Step 1: Open apache conf file
apache\conf\extra\httpd-vhosts.conf
Add below code in last line.
<VirtualHost *:80>
ServerName www.mark-thomas.loc
DocumentRoot E:\wamp\www\codebright\public
SetEnv APPLICATION_ENV "development"
<Directory E:\wamp\www\codebright\public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
E:\wamp\www\codebright\public is your laravel app path, you can replace it with your folder path.
Step 2:
Open-> Windows\System32\drivers\etc\hosts
Add your ip address in list of IP address
192.168.1.231 www.laravel.loc
Restart your apache server hit http://www.laravel.loc/my/page. Now you will see your message!

Categories