symlink from public_html_source to public_html - linux

i'm trying to create a symlink between 2 folders on a server that has limited access so I can "deploy" my site.
This is the path to the git repo /home2/username/public_html_source and in there there is a folder named backend_code Instead of ftp uploading the files of backend_code into /home2/username/public_html, I would like to make a link to it.
I tried using ln but I keep getting a symlink folder inside of public_html.
So i'm trying to get
/home2/username/public_html
to point to
/home2/username/public_html_source/backend_code

First remove the /home2/username/public_html folder (after backing it up).
rm -R /home2/username/public_html
Then apply
ln -s /home2/username/public_html_source/backend_code /home2/username/public_html

If I'm not mistaken you'd can't link two folders already existing.
What i'd do is save the data in backend_code and then make a symlink.
ln -s /home2/username/public_html_source/backend_code /home/username/public_html
This should create a symlink called backend_code in side of public_html_source which links to /home/username/public_html
HTH

This solution works even if you don't have root privileges of server or using shared hosting...
Step:1 :: Change your config/filesystems.php
From
'links' => [
public_path('storage') => storage_path('app/public'),
],
To
'links' => [
base_path('public_html/storage') => storage_path('app/public'),
],
Step:2 :: Connect to SSH & Run the following commands
$ php artisan optimize
$ php artisan storage:link
$ php artisan optimize
it should work now.

Related

How can i link the mounted folder to Laravel project?

I have a Laravel project, which placed here:
/home/user/www/example.com
We attached a new storage to vds and mounted it for
/home/user/www/storage
folder.
After that we need add symbolic link from
/home/user/www/storage to /home/user/www/example.com/storage
, but we can not do it, because the last one is already exists and contains needed files.
How can we link it for more space to storage folder in the project?
terminal output:
ln -s /home/user/www/storage /home/user/www/example.com/
ln: failed to create symbolic link '/home/user/www/example.com/storage': File exists
Option 1
You can link it to another place inside the storage folder and create a separate disk
$ ln -s /home/user/www/storage/more-space /home/user/www/example.com/
Inside your config/filesystem.php you can add an additional disk
// config/filesystem.php
'disks' => [
'more-space' => [
'local' => [
'driver' => 'local',
'root' => storage_path('more-space'),
],
]
]
and work with it Storage::disk('more-space').
Option 2
You move everything that is inside your current storage folder into your new folder /home/user/www/example.com/
Remove your storage folder with rm -rf /home/user/www/storage
Symlink the new folder ln -s /home/user/www/storage /home/user/www/example.com/

Capistrano deployment with Amazon EFS (bind mounted folders) failing when using with :linked_dirs

I am having an issue trying to use Capistrano to deploy an application that requires having several Amazon EFS bind mounts inside of the deployment (current) folder.
I have a directory on the webserver in the root called /webroot inside of it is where all of our code currently is along with about 7 folders (bind mounts) that are shared across three nodes.
Inside of my deploy.rb I have the following line set :deploy_to, "/webroot/testingCap" in which Capistrano is deploying the code into the symlinked folder current. This is great but now when it gets to the step of symlinking the bind mount directories for example:/webroot/uploads it throws an error:
rm -rf /webroot/uploads
rm: cannot remove '/webroot/uploads'
Device or resource busy
I am not sure why it is trying to forcefully remove that directory? I thought it was supposed to just symlink to the directory.
My linked_dirs part looks like this inside of deploy.rb:
append :linked_dirs, "/webroot/uploads"
What am I doing wrong?
:linked_dirs only works with relative paths and always uses Capistrano's shared directory.
When you add e.g. "foo" to :linked_dirs, Capistrano will create a symlink within your deployed app. If anything already exists there, it will delete it first (that is why you are seeing the rm -rf).
The destination of that link will always be to the same name in Capistrano's shared directory. So the chain of events will be like this:
rm -rf /webroot/testingCap/current/foo
ln -s /webroot/testingCap/shared/foo /webroot/testingCap/current/foo
Thus if you look inside current, you will a link that points
foo -> /webroot/testingCap/shared/foo
Notice that the path relative to current is identical to the path relative to shared. This is how :linked_dirs works and you can't change it.
For example, if your app expects to store uploads in public/uploads, you will need the exact same relative path to exist inside shared in order for the link to be established. In other words, the link will point like this:
/webroot/testingCap/current/public/uploads -> /webroot/testingCap/shared/public/uploads
In your case, I suspect you can get this to work, but you'll need to make sure that your mount points are located exactly where Capistrano expects them to be.

AWS Linux CodeDeploy Permission Issues (w. Bitbucket, Tomcat, Shell Script)

I'm trying to deploy files using CodeDeploy to my AWS Beanstalk server with Tomcat installed. Everything is well configured except for an exception which occurs when appspec.yml calls my .sh script and mvn install command is executed. I've tried all combinations of permissions I've imagined (as well as every StackOverflow answer I've found), but nothing has worked.
Cannot create resource output directory: /opt/codedeploy-agent/deployment-root/f953d455-9712-454b-84b0-2533cf87f79a/d-3UFCDLD0D/deployment-archive/target/classes
I also expected the files section of appspec.yml to get executed before the .sh script gets executed. It should have been working like this:
appspec.yml moves all files to webapps folder
build.sh gets executed
mvn runs and creates the .war file
build.sh does some cleaning up
appspec.yml (I've tried multiple other)
version: 0.0
os: linux
files:
- source: /
destination: /var/lib/tomcat8/webapps
permissions:
- object: /opt/codedeploy-agent/deployment-root
pattern: "**"
owner: ec2-user
group: root
mode: 755
type:
- directory
- object: /var/lib/tomcat8/webapps
pattern: "**"
owner: ec2-user
group: root
mode: 755
type:
- directory
hooks:
BeforeInstall:
- location: scripts/build.sh
runas: ec2-user
build.sh
export LANG=en_US.UTF-8
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Script path: $SCRIPTPATH"
PROJECT_SOURCE_DIR=$SCRIPTPATH/../
cd $PROJECT_SOURCE_DIR
mvn clean install
cd $PROJECT_SOURCE_DIR/target
ls -a
for file in *.war; do
mv $file /usr/share/tomcat8/webapps/ROOT.war
done;
rm -rf $PROJECT_SOURCE_DIR/target
rm -rf $SCRIPTPATH
It's obvious from the exception that maven tries to create a folder target without having the permissions. So the questions are why on the first place it's trying to execute it in this folder and then how to gain proper access.
The way to solve the problem is to add command to change to proper directory before run "mvn clean install" instead of PROJECT_SOURCE_DIR.
Install is the lifecycle event that AWS CodeDeploy agent copies the revision files from the temporary location to the final destination folder. This event is reserved for the AWS CodeDeploy agent and cannot be used to run scripts. The related doc is here: http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
The directory that you are getting error is actually under the deployment archive directory as showing here: https://github.com/aws/aws-codedeploy-agent/blob/master/lib/instance_agent/plugins/codedeploy/hook_executor.rb#L174
The reason you got the error is because the build.sh script is running at the current directory which needs root privilege and scripts/build.sh only has ex2-user privilege, which caused the permission issue.

Openshift data dir access in NodeJS

I've been trying to make my user uploaded date on OpenShift accessible publicly. However, I run into the issue that I can't seem to make it work in any way.
I'm using NodeJS to upload the files to process.env.OPENSHIFT_DATA_DIR via express4 and fs.
The files upload just fine. However, I've read plenty of messages saying that I should link the folders together using "ln -sf ../route/to/app-root/data/folder linked_folder". Which I've done, but I cannot still access them publicly.
I honestly don't know what else should I do. Do the files automatically sync? Because that doesn't seem to be the case. Or should I be uploading to my repo folder and then OpenShift automatically links it to the data dir folder?
My current exact setup when doing "ln" is:
01| cd app-root/repo/public/
02| ln -sf ../../data/user-files user-files
Doing this to link the user-files folder in repo/public with the openshift data/user-files folder.
So the thing is that I can't access the files in the front end by doing "ln" at all. No clue where to go from here.
All what you need is:
1. store all your files in OPENSHIFT_DATA_DIR directory
2. write a script that run before server.js or app.js it's function is to copy all data from OPENSHIFT_DATA_DIR to your desired directory inside your repo like public directory or whatever you want.
SAMPLE: initDataBeforeRun.js
var fs = require('fs');
fs.writeFileSync('./public', fs.readFileSync(process.env.OPENSHIFT_DATA_DIR));

Two different project in one git repo

I'm fairly new to GIT and I'm trying to figure out if I can do as follow,
I'm developing an app which has a front-end and a back-end.
Let's say the front-end contains 10 files located in this path.
Eg:
/home/front_end/file1 , /home/front_end/file2 ...... /home/front_end/file10
While, the back-end contains 100 files located in a different path.
Eg:
/home/app/code/file1, /home/app/code/file2 ,................./home/app/code/file99
How can I create a repo which has two different locations?
You can't really.
What you can do is:
setting up a repo wherever you want, with 'front_end' and 'app_code' folders in it
symlink /home/font_end to yourRepo/front_end
(as in ln -s /path/to/yourRepo/font_end /home/front_end)
symlink /home/app/code to yourRepo/app_code
(as in ln -s /path/to/yourRepo/app_code /home/app/code)

Resources