Laravel Localhost or pretty url not working - php

I have installed composer on windows 8 and i am using the webserver xampp,
I did the comand composer global require
composer global require "laravel/installer=~1.1"
I even configure env path for composer like this
set PATH=%PATH%;%USERPROFILE%\AppData\Roaming\Composer\vendor\bin
Then created the project like this
Laravel new myproject
I check the file .htaccess in my public folder of my laravel project,
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I have checked the module activation for url rewriting in apache httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
then i test it and i typed many urls and it gives a page not found ERROR !
Here are the url tested:
localhost/laravel/
localhost/laravel/public
localhost/laravel/myproject/
localhost/laravel/myproject/public
Did i miss something, i am quite surprised to fix things for hours to use a popular framework like laravel.

From the comment of my question we conclude that laravel has a bug with xampp and the bug was reported 3 days ago on the official bug tracking forum from laravel
Please check this link: http://github.com/laravel/framework/issues/8129
Also we have found that my folder structure is too long and it could generate conflict within the configuration of xampp, the advice was to use a virtual host solution, the one advised by laravel is Homestead, so let's try with homestead !
http://laravel.com/docs/5.0/homestead
Good luck to everyone who need to fix their xampp server to work with laravel maybe try to use another webserver instead.

Related

how to remove the /public folder from laravel 9?

I have laravel 9 running locally on windows (MAMP) and I want to open the home page with:
localhost/myproject
instead of
localhost/myproject/public
I tried to add .htaccess to the root folder with the following:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
and it didn't work! (I got 404),
(Although this worked with laravel 8!)
so what is the solution for this !? I spent hours on searching blogs and tweaking to no avail!
I also read on some discussions that using .htaccess or replacing the server.php and renaming it are NOT totally safe for production.
so what is the solution, and would this solution also work if I host my website online (for example on shared hosting) ?
THANKS
I have deployed several websites to hosting and vps servers with following .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
If error still occurs you may contact to your hosting provider and ask them to give you valid .htaccess rules. You may move your files inside public folder to root folder as well.
Please beware of doing solutions like htacces and changing laravel core files in production, which will make your private files public.
there is a more secure way to do it.
Developments
use: `php artisan serve`
production
you can use Document Root to make the domain point to your project's public folder.
To remove the public folder from laravel 9 you need to customize the .htaccess file.
You must have mod_rewrite enabled on your Apache server. The rewrite module is required to apply these settings. You also have enabled .htaccess in Apache virtual host for Laravel.
Update the code into your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
create a .htaccess in root directory
put these two line in it
RewriteCond %{REQUEST_URI} !^/public($|/)
RewriteRule ^(.*)$ public/$1 [L]

No solution here works for my "Class 'PDO' not found."

I know there are questions with similar titles here but none seem to work for me hence the reason to create a new question.
So here's the problem, i have a site that works perfectly on localhost where i am sure has PDO support but after uploading on my shared hosting i get the
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Class 'PDO' not found
the solutions here all involve editing php.ini and installing PDO however, i am on a shared hosting without access to php.ini file or ssh.
I am using laravel 5.5, php version 7.2 with a voyager backend.
here's what my .htaccess looks like
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<IfModule mime_module>
AddType application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
Any help will be appreciated. Thanks.
Contact your Hosting support and let them enable PDO for you.
In some hosting you can overwrite php.ini by creating php.ini file in your hosting root. These are the extensions you need to enable in php.ini if you are in windows hosting.
extension=php_pdo.dll
extension=php_pdo_mysql.dll
Edit:
Check if PDO is already installed by your hosting provider.
Create index.php file or any other file which you can access. The content must have
<?php
phpinfo();
?>
If PDO is installed already, the next thing to do is running composer install (SSH access required). You must delete your vendor folder beforehand. Assuming that your public folder is /var/www/html. go to the html directory and run
composer install
It's late but i here is my solution. i was facing the same problem in Laravel 5.6 and i didn't have SSH access for some reason. but when i change my PHP version from 7.2 to 7.1 it works for me.
Hope this will work with someone who doesn't have shell access.

Laravel 5 - Internal Pages giving Not Found Error

Actually I am deploying my laravel 5 Application on Linode Server.
My client create space for me in such type of path.
var/www/html/abcproject
I point out my godaddy domain to abcproject directory.
Now I have uploaded my all Laravel 5 files on abcproject directory.
My issue is that , my home page is working fine but my internal pages
are giving Not Fount Error.
Suppose when I try to logged in it is giving below error.
Not Found
The requested URL /abcproject/login was not found on this server.
Secondly Laravel 5 URL is getting url like that.
Supposed URL.
http://15.30.19.61/abcproject/index.php/registers
I did not understand where is and what is the issue.
One thing is my project is working fine when I try such type of URL.
http://example.com/index.php/ But In this case my URL Rewriting did not work but project is working like I can logged in, go in different pages, Logout etc.
My HTACCESS FILE
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Thanks
If you are powering your laravel project from a sub folder such as you mentioned above:
http://15.30.19.61/abcproject
You should add this to your .htaccess file under RewriteEngine On.
RewriteBase /abcproject
I also faced a similar issue with LAMP configuration and I resolved by enabling rewrite rules of apache. If some needs details then it can be referred at the below blog notes
http://ankgne.com/post/setting-up-digital-ocean-for-laravel-application
Step 1: Enabling mod re-write using sudo a2enmod rewrite
Step 2: Allowing the laravel .htaccess (in public directory of laravel page)
file to apply rewrite rules
sudo vi /etc/apache2/sites-available/000-default.conf and adding below lines
Note: Change "/var/www/html" to "path of laravel public folder"
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
. . .
Step 3: Restarting web server using sudo systemctl restart apache2

Installing Drupal 8.2.4 - Clean URLs

So I have attempted to install Drupal 8.2.4 onto a dedicated server that I own.
I am running WampServer 3.0.4 64-bit with PHP 5.6.19 and MySQL 5.7.11.
I successfully get through the installation wizard and to the main page of the website however when I try to go to various pages, none of them work.
This appears to be an issue with Clean URLs. During the installation I get a warning message that Clean URLs is not enabled.
However, I have checked my apache config and rewrite_mod is enabled.
I tried to manually access the admin page # ?q=admin/config/search/clean-urls however it just returns me to the index page.
I've taken a look over the guide here: https://www.drupal.org/node/15365
I tred modifying my httpd.conf by adding the following to the bottom:
RewriteEngine on
RewriteBase /mms-beta
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
However, then the server won't start.
I've also ensured that for /www/ the AllowOverride is set to All for the purposes of htaccess.
Can someone give me an idea as to what I need to do to get this to work?
UPDATE: So I tried adding garbage to my .htaccess file and it doesn't break, so its clear my htaccess file is not even being read.
Ok, solved.
You need to add an alias under Apache through the wamp tray icon and then modify the conf file.
In the conf file specify as follows:
AllowOverride All
Then delete:
require local
Now htaccess will work correctly.

access a folder in 'public' directory of laravel

How can I access a folder placed in the public directory of my default laravel installation. This question is for both - testing as well as live purpose.
While Testing-
I am testing on windows using XAMPP's apache http server. I have placed my app's root folder in the htdocs folder of XAMPP. Thus, when I try to access a folder in public directory, 'localhost/myappname/public/blog' it redirects me to 'localhost/blog'.
I don't want this behavior. I want it to pick up the 'index.php' file present at 'localhost/myappname/public/blog/' location. But it doesn't do so.
While Live-
I have my site live on ubuntu with apache http server. When I try to access 'mysitename.com/blog' in the firefox, it gives me this error -
Firefox has detected that the server is redirecting the request for this
address in a way that will never complete.
I have no hint about what's wrong. I have tried spending two days working with laravel's default .htaccess file(in public folder) and apache httpd.conf but still not able to resolve it. Have searched a lot over stackoverflow and google but still no clue about where I am wrong. Please guide me.
Added:
The content of .htaccess file is -
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
You just need to comment this line in your .htaccess file.
RewriteRule ^(.*)/$ /$1 [L,R=301]
Comment it or strip out from the file. This will solve both your directory /blog issue as well as redirect loop issue.
I used the Alias feature of apache to overcome this problem. I added an alias for '/blog' in my virtual host configuration.

Categories