Cannot mkdir with git clone - php

Once I clone my repo, the folders don't have write access, and so my PHP code cannot use mkdir() to make a folder if it needs to.
I get this error:
mkdir(): Permission denied
Why is this? In my repo I have a pages folder, which has the following permissions after I git clone it to my /var/www/html folder.
drwxr-xr-x 4 me me 4.0K Jun 9 18:30 pages
Is this set in the repo itself? Or is there some command I can add to git clone that will allow me to fix this?

The only file permission that is tracked and handled by Git is the executable bit. Everything else is not tracked and not controlled by Git. This is one of the arguments against using Git as a deployment tool which it is not. You can find some hints on how you can utilize Git to make a deployment strategy at http://gitolite.com/deploy.html. The permssions of the files after cloning are simply the default on your linux system. You can change this in your linux environment to be something different.

Related

How to deploy basic php site on Openshift after pushing code?

I am trying to use Openshift for the first time to host a php site(PHP 5.4 cartridge) I am working on for a school project. I followed the directions here to push my existing repo to my gear, and can see that the code is on the gear by ssh-ing into the gear. What do I have to do now to host the website? I initially thought that I would just be able to see the index.php in my repo, but when I go to the provided url it is just a blank page. I think I may need to use the deploy action hook to cp the git repo somewhere, but not sure where. Any help would be appreciated.
With the PHP 5.4 cartridge the application root is the root of your application directory. Let me try and explain a bit further. If you create an application named "myphpapp" with the following command:
$> rhc app create myphpapp php-5.4
After the application is created, the git repository will be cloned to the directory you ran the create command. Change to that directory:
$> cd myphpapp
This is your application www root directory and is where you need to place files. For example, create a new test.php file like this:
$> echo "some php code" >> test.php
Add the file to your local git repository and then commit and push to your openshift server:
$> git add test.php
$> git commit -am "Adding a new file"
$> git push
When you run the git push command, the changes will be pushed to the remote git repository on the openshift server. Once the code is pushed, a hook on the server will see that a new file has been added to the repo and then deploy it to the www root on the openshift server. Once the deploy has finished, you can access the file by pointing to:
http://yourApp-yourDomain.rhcloud.com/test.php
Hope that helps.
--
gs
I did not read the documentation clearly enough. The root for the app is yourApp/php. So your repository has to have a php subdirectory inside of it, and that will be the app root. There is no need to copy your code from the repository to the root. As you have the correct structure, when you push your code the website will be live.

Directory Permission Problems When I Deploy PHP Script on Openshift

I am deploy a cf image host 1.6.5 on Openshift using Git. Some of the directories do not have write permission when I running installer script.
The cf image host 1.6.1 installer script will generate a setting file in a directory called "inc".
I have done git push for the zip file of cf image host 1.6.5(says cf_image_1.6.5.zip) onto Openshift using git,and unziped this file to app-root/repo/php directory. The installer script can run okay. If I unzip file at local machine, git add and git commit and git push,the setting file can not be generated in the directory inc. If I manually change permission to 777, it is okay.
But I check the file using ls -la, both two methods' the owner is myself.
How do I deploy the process work when git push? Which user of the remote machine is deploying these scripts?
Try something along this (adjust permissions)
git update-index --chmod=+w -- $(git ls-files folder/with/wrong/permissions/*)
and add, commit and push.
Deploy should happen under your default openshift user. (See uder Webinterface->App: Userpart of the ssh-git url displayed there.

Laravel mkdir and copy Errors

I'm trying to install a laravel application. This question might be specific to Wardrobe, or not. I'm not sure. The Laravel application I'm trying to install is called Wardrobe.
So, there are 2 options that can be used to install this application (or script, I don't know). The first one is with Composer, and the second one is with git.
I'm trying to install this script to my server for weeks. I failed all the time. I can do this on my local computer, but can't on my server.
So, to tell you the problems, I'm creating two subdomains. One is called w1, and the other one is called w2. I'm trying to install Wardobe to w1 using composer, and I'll use git clone on w2.
I cd into /var/www/w2.domain.com/ and execute composer create-project wardrobe/wardrobe public_html. This creates the project into /var/www/w1.domain.com/public_html.
Then, for w2,
I cd into /var/www/w2.domain.com/ and execute git clone https://github.com/wardrobecms/wardrobe.git
Then, I go into database.php of each folder and write my database information.
Then I execute
chmod -R 777 app/storage/
chmod 777 public/img/
After all this, I go to w1.domain.com from my browser. I get '500 Internal Server Error', so I update both (w1 and w2) my .htaccess file from Laravel Installation Doc.
Now, I enter to w1.domain.com. I see the Installer Step 1. I click on 'Install Database & Continue'. BAM! Permission denied!
Here's the error message for w1:
copy(/var/www/w1.domain.com/public_html/public/packages/wardrobe/core/.gitkeep): failed to open stream: Permission denied
Then I enter w2.domain.com. BAM! Permission denied!
Here's the error message for w2:
mkdir(): Permission denied
Then I go into w1 and w2 folders and chown all.
Nothing changes.
Do you have any idea how to fix this?
Thanks in advance.
Here's the fix:
chmod 777 everything.
Install script.
Turn privileges to normal values using chmod.
End of story.
Thank you everyone for being so helpful.

Allow Apache to execute git pull

Haven't been able to figure this out yet.. I've seen a few answers around but none of them help.
I'm trying to use Github Webhooks to have github hit a url on my server and have the server pull down newly committed items as soon as that hits. I have a php script with the following:
<?php `git pull git#github.com:my-user/myrepo.git`; ?>
However that script when hit is run as user apache so I tried:
chown -R apache:apache .
and it still has a permission denied error.
So then I tried editing the sudoers file and changing the following:
Host_Alias LOCAL=127.0.0.1
apache LOCAL=NOPASSWD: /var/www/html/git-hook.php
and that still doesn't work.
How can this be accomplished? If I run:
sudo php git-hook.php
it works just fine so nothing is wrong with the code in the php file. I just want that to be automated.
Any ideas?
Edit:
I also forgot to mention. I even created a folder /home/apache/.ssh and copied the public key for the git pull over and same result.
Change your PHP to run git via sudo
<?php `sudo git pull git#github.com:my-user/myrepo.git`; ?>
Then change your suoders to allow git to be run by the apache user
apache ALL = NOPASSWD: /usr/bin/git
There are already Git Wrappers and librarys. Maybe you can try one of them:
https://github.com/kbjr/Git.php and/or http://www.gitphp.org/projects/gitphp/wiki
I did this for a dev site -- i wouldnt advise this for a prd site although i cant think of anything particularly dangerous about it provided the scripts dont take parameters..
I created a php script that does a git pull. In the web browser I navigate to that script and any changes pushed by deisgners etc are automatically deployed.
http://.../gitpullscript/gitpullscript.php
This works by creating a git checkout that the apache user owns. You do this by creating a directory somewhere outside the document root belongs to the apache user (www-data in this case). Then a git clone into that directory, so all the files belong to www-data. afterwards soft link the directories i want into my document root so they can be accessed ni the web browser.
www-data is not in the git group, and the repositories are setup so that everyone can read (but not write).. therefore www-data can pull but not push
in the project heirarchy I created a directory to hold the gitpull script.. I use .htaccess to password protect this dir.
<?php exec('cd /var/www-data/projects/myrepo; git pull');
mkdir /var/www-data
sudo chown www-data-www-data
su www-data
mkdir /var/www-data/projects
cd /var/www-data/projects
git clone my-repo

Capistrano uploads the .git directory

I am using git with capistrano.
I initialized my project inside my folder on my local machine as such:
git init
I then pushed the project the server directory
I then called cap deploy
The deploy works, except that it uploads the local .git folder structure, as well as my .gitignore and Capfile to a publicly accessible folder.
Here's my gitignore file:
.DS_Store
uploads/**/*
Capfile
.gitignore
.git/**/*
This doesn't seem to do the trick. Any help?
Thanks!
Edit: updated .gitignore file:
Changed deployment strategy to export:
set :deploy_via, :export
This works for ignoring the .git folder, but the contents of my .gitignore file seen below are still not taken into account
.DS_Store
includes/php/config.php
/uploads
Capfile
.git
EDIT 2 (Solution): Edit 1 in combination with the following did the trick.
Files that were already added prior to being listed in the .gitignore file would constantly be uploaded. Say I had the following .gitignore file.
.DS_Store
includes/php/config.php
Then I ran the following commands:
git add .
git commit -a -m 'some commit'
Then I decided to add to my .gitignore file so it now looks like this:
.DS_Store
includes/php/config.php
Capfile
Then again, I ran:
git add .
git commit -a -m 'another commit'
Now I'd see that .DS_Store and includes/php/config.php have not been uploaded, but that the Capfile has... This is what happened to me in my original question.
The reason: I think the .gitignore file is taken into account only when adding (i.e. git add .). If I already added files, then put them in the .gitignore file, they would have already been added to the project. I'd need to use the git rm command to remove them.
I just started anew with a new .git repo and that solved the problem, but you don't have to - you can just remove whatever files you already added but now want to ignore with the git rm command.
I selected the answer that helped me get to this conclusion as the right one, though the complete solution was just detailed above.
What is your deploy strategy?
Do you have Capistrano setup to exclude the .git file?
if you are using set :deploy_via, :copy then make sure to add the following:
set :copy_exclude, [".git/*", ".svn/*", ".DS_Store"]
Otherwise use set :deploy_via, :export which should ignore your source control folders
http://www.capify.org/index.php/Understanding_Deployment_Strategies
Looking at a similar question, it appears you don't need the wild card selectors and can just have:
uploads/
You need to deploy via :git in Capistrano and do an export. It's essentially a git clone and then just deletes the .git directory afterwards.
Your problem isn't much to do with Cap really. Make sure your .gitignore file is working correctly.

Categories