Symbolic link not working in Laravel and image not loading - laravel

My problem is that when I upload the archim with my site to the hosting and then unpack it there, I lose the symbolic link and the images stop working. How can this be fixed? Everything is fine on the local computer, and I use php artisan storage:link, but there is no terminal on the hosting.

If you have no ssh/terminal access, then create symbolic link with Route, run it once & delete it.
route/web.php :
Route::get('/sym', function () {
Artisan::call('storage:link');
});
Hope this helps

Well, if you have ssh access to the hosting, execute the command.
If you don't have ssh access, like basic hosting with cpanel, you need to configure a cronjob to execute the command. Example:
* * * * * /path/to/php /home/path/to/project/php artisan storage:link

Related

How to link public storage without ssh access or cron jobs?

I need to deploy a laravel app, which uses the storage folder as public storage but I don't have ssh access. I'm trying to find a substitute for:
php artisan storage:link
I've found this thread: Generating a link by putting this route into web.php:
Route::get('generate', function (){ \Illuminate\Support\Facades\Artisan::call('storage:link'); echo 'ok'; });
But it didn't solve the problem. Am I doing it wrong? How do I link public storage?
Edit: The shitty server I'm trying to deploy to doesn't offer cron jobs.
create a corn job if available and after the job run the first time. delete this
ln -s /home/user/laravel/storage/app/public /home/user/public_html/storage
The problem was that I didn't understand how to use the storage link route correctly. I had to add:
Route::get('/linkstorage', function (){
\Illuminate\Support\Facades\Artisan::call('storage:link');
echo 'storage linked!';
});
to web.php and actually navigate to domain-name/linkstorage to trigger the artisan call. After that the storage was linked and everything worked.

How to migrate tables on a running site for laravel?

Using laravel how to migrate table(if there are changes) on a running site?
We use CMD if working offline. My question is simple if I have a site running fine already (online) then how to migrate...we can't run CMD there, right?
one way is using Artisan command in routes like this:
Route::get('/migrate', function(){
\Artisan::call('migrate');
dd('migrated!');
});
and then call this route.
remember to REMOVE this route after MIGRATING...!
if your server is linux you can use ssh to access command environment.
If your personal system is Windows you can install putty to open ssh.
how it works is in this link :
https://mediatemple.net/community/products/dv/204404604/using-ssh-in-putty-(windows)
how to access ssh in mac system is in this link
https://www.servermania.com/kb/articles/ssh-mac/
after access ssh you most first install composer then locate your project folder and now you can call all php artisan command like
php artisan migrate
import Artisan at web.php
use Illuminate\Support\Facades\Artisan;
you can write migrate route like this
Route::get('migrate',function(){
Artisan::call('migrate');
});
you can write migrate:rollback route like this
Route::get('rollback',function(){
Artisan::call('migrate:rollback');
});
you can write routes & view clearing route like this
Route::get('vr-clear',function(){
Artisan::call('route:clear');
Artisan::call('view:clear');
});
Basically i will suggest you too use like this reboot route for clearing cache and route clear after deploying the Laravel project to live.
Because sometimes it can be show some error message.
Route::get('reboot',function(){
Artisan::call('view:clear');
Artisan::call('route:clear');
Artisan::call('config:clear');
Artisan::call('cache:clear');
Artisan::call('key:generate');
});
The answer is also simple. You're still going to use CLI or CMD while your site is online. If you use cPanel, go to Advanced tab and select terminal. Inside your terminal use cd to change drive. Default drive might probably be public_html. cd public_html, cd <your_project_folder>php artisan migrate.
This will process migration while your application is running.

Create symlink manually

I am in shared hosting. I am facing the problem to display image from my storage. I can't access through ssh so can't create symlink with php artisan . Can anyone teach me how to create symlink manually>
Add this to the route file.
Route::get('example',function() {
Artisan::call('storage:link');
});
And visit the example.

Xampp localhost not working

I am running laravel on xampp and I have problem with accessing pages,
http://localhost/laravel/public/ I get a login page which is good
however when I go for example http://localhost/laravel/public/smokeyard
I get 404 error with The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
Route:
Route::get('smokeyard', 'GuzzleController#smokeyard');
Controller:
function smokeyard(){
return view('smokeyard');
}
All my views are located in resources folder.
if you want to access laravel project without running artisan serve, you need to change few settings,
copy the .htaccess file from the public folder and paste it in the root folder of your application
rename the server.php in the root directory to index.php
now go to localhost/your_project_name/smokeyard for the url you want to check
hope this helps
Run php artisan serve and access your server at http://localhost:8000. Your routes should work fine then.
You can't access your laravel application routes straight away through the folder structure with xampp. You need to setup the web root to point to the public folder and access localhost or run the laravel server and use it. This is because the url rewriting would fail when you access the routes in laravel the way you do.
I tried this in MX Linux 21.xx. My xampp got messed up after installing larvel on it.
check MySQL status with command
mysql service status
stop the service using the command
service mysql stop
you will be prompted to provide your password, Enter password.
start xampp using command
sudo /opt/lampp/lampp start
All should be back to normal

How to run laravel 5.0 project on localhost without use php artisan serve

I have created a laravel 5.0 project with php artisan serve, now i need to know how to run laravel 5.0 project run without start php artisan serve, i have already browse lot of websites no one help me..
You need to change "server.php" to "index.php" then copy ".htaccess" from public to root directory.
See: https://stackoverflow.com/a/30053989/3948755
Laravel sever Folder is "public". There is an index.php so you can run you project from there.
Suppose if you using UbuntuOS then you have to create your local server in public directory. Suppose your folder name is laravel_test then go in that directory and run some thing like this
php -S localhost:8000 -t public
If you using windows then access public folder from URL.
localhost/laravel/public
Actually it's bad practise to access folder from URL but for local its good. You also can go with host entry. Just make sure that your target folder is "public" directory.
Normally you would have WAMP/XAMPP installed. You can access Laravel project like below
localhost/laravel/public
But this is not recommended. You should create Virtual host for example
laravel.local that pints to server-root/laravel/public.
this is how you create virtual host.
Or even better go for a Laravel Homestead .
How is your .htaccess file configured?
Try with localhost/laravel/public/index.php
Use http://localhost/projectName/public
It will be work. but in case if you have another Route and you can not access that Route and get the error like " Page Not Found " then please use the following command
sudo a2enmod rewrite
Now open the http://localhost/projectName/public/yourRoute
This is a little late but still applicable, what I like to do (using ubuntu 14.x+) is put my laravel project (let's say Project1) in my var directory, so it would be in /var/Project1, then symlink the public folder to somewhere in /var/www(+/html depending on apache version).
Symlink can be done something like this:
ln -s /var/Project1/public /var/www/html
This keeps your internal files off the grid so to speak, this is untested so if I've missed anything just comment and I will amend this post.
EDIT:
Obviously if your http root is /var/www/html you can put your project in /var/www/Project1
If you have access to xampp or wampp on your operating system you can more or less configure your virtual host like in the instruction below:
https://bestin-it.com/creating-virtualhost-on-your-local-computer-to-start-simple-index-php/
This instruction shows how to run it locally on your PC, but it works generally the same on any hosting portals. In most case in payed portals you have any web panels to configure your public folder that reference to /public folder in laravel folder's structure.

Resources