laravel project serve not showing welcome page - php

I have started working on laravel CodeIgniter was a piece of cake in terms of development but laravel is pretty much full of stress I have installed laravel project using artisan command
compose create-project –-prefer-dist laravel/laravel micamp
After successfully installing i created an .htaccess file to serve laravel to web browser instead of
https://localhost/micamp/public
to
https://localhost/micamp
.htaccess which I created
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Placed the .htaccess on the main root directly nwo when I serve laravel project by typing in to the browser localhost/micampp
I see 404 not found instead of laravel welcome page

if you want to remove public follow the below steps ,
rename server.php (micamp/server.php) to index.php
paste below code in .htaccess file (micamp/.htaccess)
Options -MultiViews -Indexes
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>
Options -MultiViews -Indexes
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_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1
RewriteRule ^(css|js|images|trainer-cv)/(.*)$ public/$1/$2 [L,NC]
php artisan cache:clear
php artisan config:cache
then try now it will work

Related

How to configure .htaccess for a Laravel API app which is hosted on a subdomain?

I have a domain mydomain.com and a nginx space to host my website. The URL address mydomain.com is already in use and I don't want to buy another domain, so I created a subdomain myapp.mydomain.com. Then I created a laravel API app myapp for testing purposes and uploaded the code into /mydomain_com/myapp folder via a FTP client.
The problem now is I have to configure my .htaccess accordingly so the the app can run correctly.
At the current state, the homepage route / is working fine, but everything else is not working.
\mydomain_com\myapp.env:
...
APP_NAME=myapp
APP_ENV=local
APP_KEY=base64:U4v....
APP_DEBUG=false
APP_URL=https://myapp.mydomain.com
...
My routes are:
\mydomain_com\myapp\routes\web.php
Route::get('/', function () {
return view('welcome');
});
Route::get('/aaa', function () {
return view('welcome');
});
\mydomain_com\myapp\routes\api.php
Route::apiResource('os', OsController::class);
Now, when I go to https://myapp.mydomain.com I get this:
However when I try to visit https://myapp.mydomain.com/aaa and https://myapp.mydomain.com/api/os, I get this error ↓
Can You pls tell me what's the problem with my \mydomain_com\myapp\.htaccess ↓ ? Why is the homepage only working?
RewriteEngine On
RewriteBase /
# 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]
RewriteCond %{HTTP_HOST} !^subdomain
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{HTTP_HOST} ^subdomain
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
Im using the htaccess which is already with the laravel and Im posting it below, it works fine with me
<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>
Also check if the mod_rewrite is enabled in your server, if you are using ubuntu and apache2 server enable the mod_rewrite using the command
sudo a2enmod rewrite
Kindly refer : Enable mod_rewrite
Update the content of .htaccess file in the root folder with this. It should work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

NotFoundHttpException Lumen in production

When access Api, return print below:
Symfony\Component\HttpKernel\Exception
NotFoundHttpException
enter image description here
the project is in "back" folder and the url is api/
Root .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^api(/(.*))?$ back/public/$1 [L]
RewriteRule ^(.*) $1.php [NC,L]
.htaccess in public
Options -MultiViews -Indexes
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]
For this problem, I think you need to add a request capture inside the service container of the app.
For that, You need to add this code inside your public/index.php
$request = IlluminateHttpRequest::capture();
$app->run($request);
Or you can do one other solution by putting this code inside same file
$app->run($app->make('request'));

Laravel CPanel upload throws 403

I cannot start my laravel project on cpanel server. Asked domain provider website to add the pyp version that my laravel project use but still have that problem. I need to solve this is 4 hours please help.
Here is my .htaccess
'''
Options -MultiViews -Indexes
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]
'''
If you're using cPanel on shared hosting, try the following assuming the root of your project is public_html (you can adjust the path if your project is in another directory within public_html):
Set the document root to the root of the project ie. /public_html
Create an .htaccess file in the root of the project that looks like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
This will direct requests to the public folder.
Create another .htaccess file in the public directory that looks like:
<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>
Are you getting the issue while accessing the web ?
Step 1: just upload your all source code on the server (make sure database & .env set well) i) make zip and extract it ii) deploy code using git or take a clone from a repository and install all dependencies
Step 2: Make a .htaccess file on the project root directory and copy below code and paste it into this file.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
I get this answer from this video so please say thanks to him https://www.youtube.com/watch?v=6Qbd9HTh7AE
Ref: How do I upload a laravel project on cPanel shared hosting?
or Try with a default Laravel and then upload your code
or create laravel project via Cpanel UI and try. Later replace with your custom code. Capture the key and .env files before replacing.

Installed Laravel 5 in subfolder with modified .htaccess but assets not showing

I have installed laravel 5.4 in a subfolder, e.x. example.com/laravel.
I followed ka_lin's anwser and it seems like everything works fine except the assets as they are not showing. However, if I add "public" to the url, like example.com/laravel/public/(asset uri...) I can request the asset. I am wondering if there's anyway to work around with this.
.htaccess which resides in the project root folder:
<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]
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I finally figured out why!!
Because I named my folder to "img" instead of "images", so I have to change
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
to
RewriteRule ^(css|js|img)/(.*)$ public/$1/$2 [L,NC]
And if I have any other assets like fonts, I need to add the folder name to the parentheses and modify
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
to include the extension.
I don't know much about apache configuration but it works for me. Hope it help other people.

How to create Laravel-5.2 project beta version under public directory

I have been trying to create beta version of my live laravel-5.2 project in public/beta directory and have played alot with .htaccess file but in vain . please somebody help me out.
Here is my .htaccess file
Options -MultiViews
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Categories