Uploaded laravel project to production server with problem can't find storage folder in public_html
can anyone help me ?
i have tried with php file to make symlink but it's not working
<?php
$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
$linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
symlink($targetFolder,$linkFolder);
echo 'Work Done';
?>
If you have ssh access, You can run the given command to create a symlink, before running the command make sure you don't have any symlink already.
ln -s /home/USER/public_html/storage/app/public /home/USER/public_html/public/storage
For your reference, the syntax of the command is as ln -s source destination.
If you don't have access to ssh, You can do the same using cron job. Create a cron job with the above-given command and you'll get the symlink.
Use like this
$_SERVER['DOCUMENT_ROOT']."/ProjectName/FileName/../..
Related
I have an application in php that works on the docker. I would like to send a command from php code to container that should create files (some_dir/certs/cert.crt etc.). This command i run like this (by system/exec/shell_exec or symfony/process)
system("traefik-certs-dumper file --source acme.json --dest some_dir --version v2");
When php run this code then directory has been created but not files, also i don't have any error.
This command works when i make it from terminal via docker exec but not from php. This is probably some permission problem between php and docker container, but i don't know how can i set it.
I'm trying to set in docker file this, but not working:
RUN chmod 777 /go/bin/traefik-certs-dumper
RUN usermod -u 1000 www-data
also standard command works like this:
system("mkdir -p some_dir_1234");
system("touch some_dir_1234/some_file_1234");
How can I allow an installed library to create files?
I finally was able to find a solution. In a separate container, I had a process supervisor running, who saw this file, because it was mounted to the main application directory also. What had to be done was to mount the file to the main container and the supervisor container.
Try
exec("traefik-certs-dumper file --source acme.json --dest some_dir --version v2");
intead of system()
I am running Ubuntu 16.04 and I am programming in PHP. Here is my problem:
I have a need to use the wget linux command to download all files from a website. So I am using PHP's shell_exec() function to execute the command:
$wgetCommand = "wget --recursive --page-requisites --convert-links $url 2>&1";
$wgetCommandOutput = shell_exec($wgetCommand);
This command downloads all files and folders from a website, recursively, to the current working directory (unless otherwise specified). The problem is that when these files and folders are downloaded, I do not have permissions to read them programmatically after that.
But if I do something like sudo chmod 777 -R path/to/downloaded/website/directory after they are downloaded with the wget command and before they are read programmatically, they are read just fine and everything works.
So I need a way to download folders and files from a website using wget command and they should have read permissions for all users, not just sudo.
How can I achieve that?
This sounds like a umask issue with the user running the PHP script.
Normally, Ubuntu would have a default umask of 0002. This would create a file with (-rw-rw-r--).
From the console you can check and set the umask for the PHP user via:
$umask
And inside the PHP script, do a
<?php
umask()
If you are on a running webserver, it would, however be better to alter the files permissions of the downloaded files afterwards, via
<?php
chmod()
The reason is, that the umask handles file creation for all files - not just your script.
I've setup my production server on a shared hosting my directory structure looks like this (my project is placed at same level as public):
/home/user/my-laravel-project/
/home/user/public_html
This is how I'm storing my data in Storage > Public Disc
$data->store('path/to/data', 'public');
On production, using SSH, when I run this command php artisan storage:link.
It creates a symlink between storage/app/public and my-laravel-project/public
I want this link to be created between storage/app/public and /home/user/public_html
What I've tried
Tried removing my-laravel-project/public then tried php artisan
storage:link .. it failed with an error No file or directory
I tried changing storage path from storage_path('app/public) to
public_path() under config/filesystem.php but no success
I've also tried to create symlink using shell command ln -nsf
/home/user/my-laravel-project/storage/app/public
/home/user/public_html but no success
Tried many other little tweaks but nothing works for me .. I'm looking for a proper solution to create a symlink between storage/app/public and /home/user/public_html on my shared server
Note I don't want to change paths in config/filesystems.php as that's not a proper solution
My current server is setup on Siteground with php version 7.0.32 and Laravel 5.5.43
If you want to create defaults symlinks you should create one for yourself.
This is the symlink pattern:
ln -s target source
So in your case you have to do following:
ln -s /home/user/public_html storage/app/public
Simply run php artisan storage:link on SSH terminal.
It will create a symbolic file(storage) on public folder and move it to the public_html/
This answer from Sudaraka Senevirathne works on siteground.
Simply run php artisan storage:link on SSH terminal. It will create a symbolic file (storage) on a public folder and move it to the public_html/.
I'm making a laravel webapp and I'm trying to access a image in a storage symbolic link /storage/images/face-ph.png.
It works when I do it locally like this:
<img src="/storage/images/face-ph.png>
However when I upload it to Heroku it can't find the path.
Adnan's answer has two issues;
If you use heroku run bash to execute a command, it's only executed in a one-off dyno. So this won't effect the live dyno.
The php artisan storage:link command generates a symlink with an absolute path. So when you'd run this during build, it'd map the absolute path of a temp build directory, instead of the final app's directory on the dyno.
I used a simple relative symlink to link both directories and add it to your git repository:
cd public/ && ln -s ../storage/app/public storage && cd ..
if you are using Heroku for your deployment you can try
heroku run bash
php artisan storage:link
OR
heroku run /app/php/bin/php /app/www/artisan storage:link
you can use an absolute path or relative path to run binaries
Hope this helps
I have used the following command to create symnlink for storage public folder for my project which I'm doing in Lumen .
=> php artisan storage:link
But I am getting this error in terminal =>
There are no commands defined in the "storage" namespace.
Another query is though I'm able to upload file in storage folder , how I'm able to access, I need some sample code for this. Kindly help.
I created by this unix command :
ln -s sourceforwhich symnlinkfolderpath
e.g.:
ln -s /data/html/projectfolder/storage/app/public /data/html/projectfolder/public/storage
This is for windows,
First of all run cmd with administrator if you are on another user not in admin and then go to your project's public path e.g. project/path/public.
Then run below command,
mklink /D "storage\" "E:absolute/static/path~/storage/app/public/"
For e.g.,
mklink /D "storage\" "E:/User Name/Work/My Projects/storage/app/public/"
Hopefully it will help for Lumen windows users.
More simple and short way using unix command :
Go to the lumen/public folder in the terminal or via ssh etc.
Run :
ln -s ../storage/app/public storage
I am using Lumen 8.0 on Mac and Linux machine. I did not find any solution for lumen but we can create symbolic link by using full/complete path in command line:
ln -s /var/www/storage/app /var/www/public/storage
If you are on Windows, running below command in a Lumen project folder simply helps:
mklink /J public\storage storage\app\public
It does not require any Administrator privileges.
Lumen's artisan doesn't support "storage", that's why you got an error. Try to upload your file to app/public folder instead.
Change your upload path to app/public, too.