laravel publish site issue - php

I need to publish my web app written in laravel 4,
i've followed many tutorial in internet but i'm not able to make it works correctly.
i'm on a dedicate server with centos 6.6 where resides another website so the laravel app should be placed in a sub folder named vols
this is the current folder structure:
/
var/
www/
laravel/
app/
bootstrap/
vendor/
...
html/
vols/
other files of my website
i've changed the paths inside bootstrap/paths.php to
'app' => __DIR__.'/../../laravel/app'
'public' => __DIR__.'/../../html/vols'
'base' => __DIR__.'/../../laravel'
'storage' => __DIR__.'/../../laravel/app/storage'
and the paths inside vols/index.php to
require __DIR__.'/../../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/start.php';
my first controller is named volunteers, so if visit http://mydomain/vols i should be redirected to http://mydomain/vols/volunteers
instead i see this error message: The requested URL /vols/volunteers was not found on this server.
if i try to connect to http://mydomain/vols/index.php/volunteers everything works correctly but i don't want index.php in my route.
i think i should work on .htaccess inside vols folder, but i've never studied how it really works, so i'm just copying some random snippets from internet substituting public with vols.
currently it look like this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^vols
RewriteRule ^(.*)$ vols/$1 [L]
</IfModule>
Some solutions suggests to create vhost, technically i can do that, but i don't know how.
Could you please help me?

You should place the following .htaccess in your vols folder -
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /vols/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Related

Laravel 8.4 – Remove Public from URL

I am working on creating a website that converts text into speech. I am using the script from codecanyon which is Developed with PHP 7.4.x and Laravel 8.4.x . The issue I am facing is that I don't want to show /public URL as a permalink to access the website. Now, if I type mywebsite.com/pubic then the website is accessible otherwise if I write mywebsite.com then it only shows the files. I followed some of the previous queries posted on StackOverflow but got no results.
The topic I followed is Laravel 5 – Remove Public from URL
I tried even by renaming server.php , copying .htaccess and rewriting it. But those all resulted in a screen showing up errors or even blank.
My .htaccess file is;
<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]
To remove the /public from the URL you are not going to use the .htaccess file.
What you are going to do instead is set the /public folder as the serving directory for your Server.
If you use Apache, just go to your /etc/apache2/sites-available/000-default.conf file and change the DocumentRoot from {your base folder}/ (usually /var/www) to {your base folder}/public
The content of public folder should go to the public folder of your server (fe it's public_html on my server), and everything else should be stored in a different folder (fe laravel_mywebsite). Then you should go to public_html/index.php and change the folder paths based on where you put your Laravel app.
If you want to only use .htacces, you just need to rewrite all requests from /public to /
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]

Laravel 8 Cpanel Deploy - 404 Errors

I am trying to deploy my Laravel 8 app to a folder in CPANEL (first time I've deployed Laravel). I have searched the forum and made changes as the many posts direct. I am getting 404 errors across all pages apart from the homepage and login and register pages. This is a common error but I cant find a solution. Dont shoot me.
1.All files uploaded to url/laravel/blog
Public folder moved outside and renamed public_html
The /laravel folder now has two directories /blog and /public_html
index.php in the public_html folder updated:
require DIR.'/../blog/vendor/autoload.php';
$app = require_once DIR.'/../blog/bootstrap/app.php';
New .htaccess file added to the root of the public_html and set to chmod 755 (detailed below)
Renamed the cache folder in the /bootstrap folder so that new cache is created (I hope)
Database is linked within the .env file
I am out of ideas, I have created a test html file in the public folder and I can see this in the browser when I navigate to it. I am learning and any help will be appreciated.
<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>
I needed to point the subdomain/add-on domain to the public folder. No need to move anything or change Htaccess etc.... Credit to https://stackoverflow.com/users/2325620/james-clark-developer
Try this in your .htaccess
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>

Laravel Project in subfolder reroutes to main domain. Is the setup right and how to add prefixes?

For the testing of a new version of a project, I have to deploy a laravel project to a sub folder which was set up for me. I already programmed it on the localhost and only need to upload it.
The subdomain is on example.com/new
The structure I found in Filezilla was like this:
(I do not have access/can't see to the main Versions files-does this mean it is a subdomain?)
htacess
env
newProject(folder)
public
I did not have permission to upload new files above the public folder. The .env and .htacess could be replaced. So I did the following:
htacess
env
newProject(folder)
public
index
project(folder)
(laravel put another.env and .htacess in here are these the right ones to change)
.htacess
.env
rest of laravel files
Out of confusion I always just make a change in both existing .env's and .htacess because I don't know which is the right one. Is this setup right? I already changed the index
require __DIR__.'/project/vendor/autoload.php';
$app = require_once __DIR__.'/project/bootstrap/app.php';
My htacess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
[[rewritebase /new
# 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>
MY PROBLEM:
There is at least something working. Because I have an automatic rerouting for languages in the web.php
Route::redirect('/', '/en');
Route::group(['prefix' => '{language}', ''], function (){
...routes
And when I go to example.com/new it reroutes me to example.com/en instead of example.com/new/en. That means it does come to the routing part, dies this mean htacess and .env are set up right?
the error is of course
"Not Found
The requested URL was not found on this server."
MY QUESTION
How do I stop the rerouting to /en and go to /new/en. Is there a prefix I can add to all my routes. And can I be sure the rest is set up right just because the code routes to /en which is set up in the web.php?

How to use Laravel app in subfolder of Apache User Directory

I'm trying to get a Laravel 4 app installed in a subfolder of the web root directory for one of my users. I know there are major security concerns having the entire framework accessible via the web. I plan to address those separately after I understand how to get this working.
I've tried every combination of Apache Aliases, and Rewrite rules I can think of, but nothing seems to work. Here's my directory structure:
/home/username/public_html
.htaccess
my_laravel_app/
app/
bootstrap/
public/
.htaccess
index.php
robots.txt
...etc (standard Laravel 4 public folder contents)
vendor/
...etc (standard Laravel 4 files and folders)
The first .htaccess file, the one listed directly under the users public_html directory, contains the following:
AuthType Basic
AuthName Private
Authuserfile /path/to/.htpasswd
Require valid-user
The second .htaccess is a standard Laravel 4 .htaccess file. It contains the following:
<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]
</IfModule>
I would like to essentially treat this my_laravel_app/public directory as a webroot, so that the Laravel app functions the same way it would if for a normal Laravel installation directly on a domain.
I believe I just need to edit the first .htaccess file to contain rewrite rules that send any request to /my_laravel_app to my_laravel_app/public, but I can't seem to get this working. Can anyone help?
This may be different depending on your setup, but the base config is:
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/my_laravel_app/public/%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}/my_laravel_app/public/%{REQUEST_URI} -f
RewriteRule . public/%{REQUEST_URI} [L]
RewriteRule . public/index.php [L]
And put inside your my_laravel_app as an .htaccess to limit the complexity of the conditions. You get the idea hopefully.

Installing Laravel in a subdirectory

I've been searching around for an answer to this and can't find anyone with my exact problem and was hoping someone else has had this issue.
I had Laravel installed locally using a vhost, and it was installed at the root. I've now had to move this install to another server at http://domain.com/~username, all my files are in /~username/ and I'm using .htaccess to access the public folder from http://domain.com/~username.
I've also set my paths correctly and my site URL in app.php.
Everything almost works except for my routes.
If I navigate to http://domain.com/~username I get a NotFoundHttpException
This is my route for my homepage:
Route::get('/', function() { ... });
if I change it to
Route::get('/~username', function() { ... });
it shows me the homepage. This isn't exactly ideal and kind of hacky, plus there's a lot more issues than just the homepage.
I'm having other issues with pretty much everything because Laravel thinks it's installed in the root folder, and not /~username/.
My question is how can I get Laravel to see that it's installed to http://domain.com/~username/ and NOT http://domain.com/?
EDITS: adding .htaccess files
My current .htaccess file in root (/~username)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~username/
RewriteCond %{THE_REQUEST} ^GET\ /public/ [NC]
RewriteRule ^public/(.*)$ $1 [L,R=301,NE]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>
and the .htaccess file in /public
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /~username/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
</IfModule>
I might not have understood your question properly but here is my solution.
Go to /bootstrap/paths.php and change to:
return array(
'app' => __DIR__.'~username/../app',
'public' => __DIR__.'~username/../public',
'base' => __DIR__.'~username/..',
'storage' => __DIR__.'~username/../app/storage',
)
I'm not sure if this will work. I haven't tried it.

Categories