Image not working after uploading Laravel project to server - php

I have uploaded my laravel project on shared hosting and my images will not work.
I have added .htaccess in the root directory and every thing works file except images. My .htaccess file is below.
RewriteEngine On
RewriteBase /
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
My image link is mydomain.com/storage/facilities/May2017/BYKdbdIQCezQ6Gsh05EK.jpg
and it shows
You don't have permission to access /public/storage/facilities/May2017/BYKdbdIQCezQ6Gsh05EK.jpg on this server.403 ERROR
Is this symlink error? I do not have ssh access so is there any way to link storage folder?

Here is the simple solution
you can create symlink using cron job what you have to do is.
1) php (absolute path to artisan) storage:link
like php /home/(yourusername)/public_html/artisan storage:link
OR
2) ln -s /home/(yourusername)/public_html/storage/app/public/ /home/(yourusername)/public_html/public
go to public folder and rename public to storage.

Two things:
1) I recommend you put your images in your assets folder
2) It's common knowledge that Laravel doesn't like you having access to your Storage folder. You can change permissions for it, if need be, but I highly recommend you know what you're doing before you decide what to set it to.

Related

How to deploy a Laravel-Vue project on shared server (GoDaddy)

This is the first time I am developing a Laravel Vue app. When I use php artisan serve, everything works fine. But when I load it with http://localhost/myProject/public, assets are not loaded. My images are in img directory inside public folder. I was using blade templating to manage this issue when I use Laravel alone. But now I can't use blade since it is a Vue component. How can I run the project without php artisan serve? My Ultimate aim is to deploy the project in godaddy shared server. Please help me.
Debug your application using 'php artisan serve' while you develop from your local machine.
When you publish it into godaddy,
compress the project folder (say 'my_project') and upload the zip file ('my_project.zip') to 'public_html' directory in godaddy.
unzip the folder.
Now the directory structure will be 'public_html/my_project...'
you will have a 'public' directory inside 'my_project'.
Now create a subdomain which points to the 'public' directory.
That's it. Now load the subdomain.
The assets and api's will work perfectly.
just rungit clone [your_project_address] in the www folder and then run 'php artisan migrate', of course, you should have configured well.
#ThasheelApps this is your solution to access api's.
Create a .htaccess file in root folder and paste the following code there:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This issue occurs many times due index.php in url. if you try your api endpoint including index.php, it will work perfectly. to prevent this issue we need to follow above soution htaccess
Follow these steps:
zip your project after npm run dev and php artisan serve without
any error.
Go to your shared hosting location and outside fo public_html
make a folder name say myproject. Inside this folder extract all
your project files.
cut your public folder from project folder on root, go to your
subdomain folder under public_html and paste.
go to index.php inside public folder and
require DIR.'/../vendor/autoload.php'; and
$app = require_once DIR.'/../bootstrap/app.php'; pointing to your project location on root.
That is all. Enjoy, if you have properly created and attached your DB to your project.

Moving Laravel Project to a Sub Directory

I am a newbie to Laravel.
I want to upload Laravel project from local to shared hosting server.
Scenario is like below:
I have a site (abc.com).
I want to deploy Laravel project inside this site so that URL will be like abc.com/xyz
I have moved Laravel project files and folders inside xyz folder.
But site is not running.
What paths needs to change and in which files?
Please help.
It will run as abc.com/xyz/public
This can be done, but keep in mind that having the Laravel files in your web server root is not recommended.
How you can accomplish abc.com/xyz:
In folder xyz where laravel is installed you can add this in a .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Again, this setup is not recommended, because the Laravel files should never be in or above your root.
A better way would probably be to install Laravel in the dir below the root and set xyz as your public directory. You would just have to change the paths in index.php to make sure it searches for the Laravel files below your web root.

Setup laravel in shared hosting

I'm trying to setup laravel (5.4.12) in shared hosting. Following this tutorial I had deleted my public_html and created soft-link for public_html to public folder of laravel project. I had successfully setup laravel (5.3.29) following the same tutorial for my previous project. But this time when I try to open base url it downloads index.php file of public directory of laravel folder. Can anyone help me out.
You can do it without deleting public_html folder.
for routing to public forlder just add these lines to .htaccess files
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
Normally PHP files are downloaded when the web server isn't configured to serve PHP files. Sounds like you need to talk to your hosting provider.
Finally found the solution. The issue was with PHP version. I had selected PHP version 7.1.0RC4,I changed it to 7.0.12 and the problem is gone.
Laravel 5 setup without artisan serve command
Rename the server.php in the your Laravel root folder to index.php
copy the .htaccess file from /public directory to your Laravel root
folder.

Deploy CakePHP application to webserver

I am having trouble deploying my CakePHP application onto a shared web server. Here's what I've done:
1) I zipped the application from my local machine: application.zip
2) I then uploaded the zip file on to my public_html on the server and extracted it
So now my application sits at www.mydomain.com/application which works fine, but once I move the contents of the application folder onto public_html (so that my application sits at www.mydomain.com) it doesn't load the application properly. It only loads SOME of the links of the home page and none of the styles.
So to sum it up.. the app works fine right after extracting to public_html/application/
But once I move the contents of the application folder to public_html it doesn't work.
How am I supposed to set up the folder structure so that my application sits at www.mydomain.com?
Any help would be greatly appreciated.
I just happened to try deploying a Cake app in the same way to a shared server using CPanel and had exactly the same problem. What I discovered is that somehow (I think when I extracted the zip to the public_html directory there was an empty .htaccess file that didn't want to be replaced) the .htaccess file in the root of the application was empty.
Just make sure the .htaccess file in the root of your application (i.e. in public_html) contains this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Worked fine for me and I'm all set now!
You could also try deleting cache files in app/tmp/cache
Not the folders but the files in the folders

How to route request to codeigniter project outside document root

I have the following shared hosting file structure using a codeigniter project:
myTLD.com/sites/mysite
mysite contains: application, system , index.php ... ( standard CI2 setup )
myTLD.com/public_html - contains : index.php
I have symlinked myTLD.com/public_html/index.php to myTLD.com/sites/mysite/index.php
Unfortunately I am getting:
Your system folder path does not appear to be set correctly. Please open the following file and correct this: index.php
I have set it up this way to avoid placing the actual site in the document root for security purposes . I don't want to change mysite/index.php because I want to keep the entire project in its mysite directory where it can easily be revised etc.
The application and mysite/ folder are set to 755 so I don't think this is a permission problem .
My myTLD.com/public_html/.htaccess folder directs all requests to index.php:
RewriteEngine On
RewriteRule ^(.*)$ index.php
Can someone advise me on an approach to sending requests through to the codeigniter index file without causing this error?
Thank you
You can try following way
1) Remove the symlink
2) Use this in htaccess at myTLD.com/public_html/.htaccess
RewriteEngine on
RewriteRule ^(.*)$ myTLD.com/sites/mysite/index.php?/$1 [L]
Use absolute system path if you are aware of it.

Categories