Using PHP to execute `git pull` command - deploy with github - php

I have been able to connect a local repository to a private Github repo (using the Github for Windows GUI), which should then automatically deploy to a development server. Everything is running smoothly until I make an attempt at the following:
<?php `git pull -f`;
Source: http://net.tutsplus.com/tutorials/other/the-perfect-workflow-with-git-github-and-ssh
Once I commit then sync/push through Github for Windows, this script is supposed to call the Linux command 'git pull -f'. I have used a SSH key without a passphrase in an effort to make it easier but to no avail. However, if I were to execute the command via command-line, everything works perfectly.
File & folder permissions are set to 777 throughout the root directory (including the /.git folder), which is what I thought was the reason for not being able to see updates when viewing the website I am developing.
If anyone has had a similar experience with this I would be grateful for a solution.
Note: I have searched high and low on SO and elsewhere on the web for a potential fix to this but any resources will be met with open arms.
Thanks,

Related

How to push new local dependencies to shared hosting with Laravel?

My website is running smoothly with Laravel in a sub-domain, but now I have added a new dependency https://github.com/PHPOffice/PHPExcel to my local project using composer require phpoffice/phpspreadsheet.
The code is already working fine in my local environment, but now I need to push my new changes to the website.
Pushing the controllers, routes, views, etc it's easy, but how do I push the dependency?
I have full access to the cPanel
I can create SSH keys
The project is running in a sub-domain
I'm using Visual Studio Code
I have generated a private and public key for SSH
I have initially deployed my Laravel project to the server using FTP Filezilla
For what I have read so far, I should be using SSH with PuTTY, but if I could use an extension in Visual Studio Code, would be great.
Composer stores all the imported libraries in the /vendor folder. When you push your local copy of the website up, it will push up the vendor folder and you'll be set.
If you're working on a remote server and you need to still download the dependencies, run
php composer.phar update
That will download the dependencies for the project. You'll need to run it from the command line (ssh) and be in the website directory.
Some companies don't allow ssh access to the server. In that case, you can run php composer.phar update on your local machine, assuming you have a php runtime install (WAMP, XXAMP, ect). Then when you push or copy your code to your server, the libraries will be included.
Well I can create SSH keys but don't have access to login with them. With that said I follow the tutorial here https://laraveldaily.com/laravel-and-shared-hosting-working-with-ftp-and-phpmyadmin/ that teaches how to use FTP to upload/update the application.

How to upgrade a website without or less down time?

I want to upgrade my website without downtime. I made researches and didn't find a way to upgrade it without downtime (few seconds are fine). I was thinking a way as follows, but I am not sure whether any good professional way is there. Please help me out on how to improve this.
Add new tables/CFs to the database (database is Cassandra,
we are not supposed to do any changes in existing tables/CF)
Deploy the project in online server in different Directory, so that
users can still use the existing site.
Point the uploaded project in different port and check whether
everything is working properly.
If everything is working change the symlink to the uploaded directory
Please let me know any other good methodology if you have.
I am using SVN in my local server
UPDATING THE SERVER ALMOST INSTANTANEOUSLY
Ok for this one of the best and the easiest method is using Git. So, what you should do is host your code in Git and then whenever you want to update the site, just SSH into the server and do a Git Pull. It's instantaneous and it would update it. Also you can use Git Hooks to further solve your problem as well.
There are a few ways you can go about it, but one of the easier methods would be this.
Let me explain it in detail on how to do it:
The source for your web site should live in a Git repository on the local workstation. I shall describe how I set things up so that I can make changes live by running just "git push online".
The local repository
It doesn't really matter how the local repository is set up, but for the sake of argument, let's suppose you're starting one from scratch.
$ mkdir somesite && cd somesite
$ git init
Initialized empty Git repository in /home/sankalpsingha/somesite/.git/
$ echo 'Test!' > index.html
$ git add index.html
$ git commit -q -m "This is the first push."
The remote repository
I assume that the web site will live on a server to which you have ssh access, and that things are set up so that you can ssh to it without having to type a password (i.e., that your public key is in ~/.ssh/authorized_keys and you are running ssh-agent locally).
On the server, we create a new repository to mirror the local one.
$ mkdir coolsite.git && cd coolsite.git
$ git init --bare
Initialized empty Git repository in /home/sankalpsingha/coolsite.git/
Now lets make and define the hoolks as a post-receive hook that checks out the latest tree into the web server's DocumentRoot (this directory must exist; Git will not create it for you):
$ mkdir /var/www/www.somesite.org
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/www.somesite.org git checkout -f
$ chmod +x hooks/post-receive
Back on the workstation, we define a name for the remote mirror, and then mirror to it, creating a new "master" branch there.
$ git remote add online ssh://server.somesite.org/home/sankalpsingha/coolsite.git
$ git push online +master:refs/heads/master
On the server, /var/www/www.somesite.org should now contain a copy of your files, independent of any .git metadata.
The update process
Just run :
$ git push online
This will transfer any new commits to the remote repository, where the post-receive hook will immediately update the DocumentRoot for you.
(This is more convenient than defining your workstation as a remote on the server, and running "git pull" by hand or from a cron job, and it doesn't require your workstation to be accessible by ssh.)
You can use some CI or deployment tools. I'm doing this manually. Here is the way i'm doing it.
I have a workcopy directory from git, and git hook to sync it on push.
Then i sync worckopy directory with site using rsync.
All database changes done with migrations, so 1 command yiic migrate is enough to make new tables or alter existing.
With this methodology there is no actuall downtime, some pages can be unavailable for 5-10 sec max, but all system works on this time.
Point the uploaded project in different port and check whether
everything is working properly. If everything is working change the
symlink to the uploaded directory
It's bad way, for testing you need test server, or test it on local machine with same configs and params as on server. For example Vagrant can make any environment on your local machine for testing.
If you need to pass tests (e.g. unit tests or functional), then watch on CI tools.

NetBeans + FTP + BitBucket

I know this has been asked before, but I couldn't get the answer I needed.
Currently I'm developing an website using PHP and was using Notepad++ before, and it all worked well because I'm developing with a co-worker so we both keep on changing different files on the FTP.
Switched to NetBeans. All went ok, pulled the entire website via FTP to my local computer and everytime I edited a file and saved it uploaded to the FTP. But, there is a problem. If my colleague updates a file, it doesn't update on my local folder. So, I thought: "Let's try versioning".
Created a team on bitbucket, created a repository. All went ok.
But now, I'm in a struggle to get everything up and running on both NetBeans (mine and colleague's) so that my colleague is editing a file on his NetBeans and constantly saving so that it gets saved on FTP and only when he stops working on that file push it to BitBucket so that I can pull after.
Suggestions?
About setting up your work environment :
In order to set up your bitbucket repository and local clone, go read this link (official doc).
You will need to repeat the cloning part once for each PC (e.g : once on yours, once on your colleague's).
Read the account management part to see how you can tag your actions with your account, and your colleague's action with his own account.
Start using your git workflow ; when you are tired of always typing your password to upload modifications to your bitbucket account, take the time to read the ssh keys setup part - read carefully, you will need to execute the procedure once for you and once for your colleague.
Using your local git repository with Netbeans is pretty straightforward :
From netbeans, run the File > New Project ... command (default: Ctrl+Shift+N),
Select PHP application with Existing Sources and click Next >,
For the Sources Folder: line, select your local git directory,
Fill the remaining fields, and if you want the last Run configuration screen, then click Finish.
After the project is created in netbeans, you can modify the Run configuration part by right clicking on the project's icon, selecting the Properties menu entry, and going to the Run configuration item.
About solving your workflow "problem" :
Your current FTP workflow can lead you to blindly squash your colleague's modifications (when uploading), or have your colleague's modification blindly squash your own local modifications (when downloading). This is bad, and you will generally notice it only after the bad stuff happened - too late.
Correctly using version control allows you to be warned when this could potentially happen, and to keep an almost infinite undo stack on the modifications of the project's files. The cost, however, is that both of you will have to add several actions in your day to day workflow - some choices can not be made automatically.
You may find it cumbersome in the beginning, but it really pays off, and quite quickly - we're talking big bucks here. So use it and learn.
On top of using Ctrl+S to save your modifications on disk, you and your colleague will need to integrate 3 extra commands in your daily work :
Save your work to your local repository (git add / git commit)
Download the latest modifications shared by your colleague (git pull)
Upload your work to the central repository (git push)
You can access these commands :
from a terminal,
from a GUI frontend : you can try TortoiseGit for windows, or gitk for linux,
from Netbeans :
in the contextual menu of the files/folders in the project tree (right click on the item, there is a "Git" entry),
using the Team > Git > ... menu
Since you provided a git tag, I'll describe what's to do for Git.
set up a remote bare repo on a server that you both could access (BitBucket in your case):
http://git-scm.com/book/en/Git-on-the-Server-Getting-Git-on-a-Server
you both clone that remote repo to your local machines:
http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository#Cloning-an-Existing-Repository
each of you works in her part of the application. When one is done, publish the work to the server:
http://git-scm.com/book/en/Git-Basics-Working-with-Remotes#Pushing-to-Your-Remotes
By now, the remote server holds the version that was just pushed. What's missing is the deployment of the website. This has been discussed here:
Using GIT to deploy website
Doing so, you will decouple your work from that of your colleague since you're not changing files over FTP all the time. You work in your part, your partner works on her part. The work is getting merged and then a new version of the website gets published.
You can create git or Mercurial repositories in Atlassian Bitbucket (http://bitbucket.org). If your team is new to version control, i advise you no forks in your first project.
The easy solution ins to use Atlassian SourceTree (http://www.sourcetreeapp.com/) to control your code since there is a bug in netbeans. See NetBeans + Git on BitBucket
You need to create a new repository in bitbucket. I assume you already configure the ssh2 keys. Using Git you need:
git clone --bare --shared php_project php_project.git
git commit
Using Mercurial you need:
hg init
hg commit
Good luck / boa sorte
Pedro

Issues Deploying Site with Git & PHP (Cpanel/WHM Server)

We are trying to automatically deploy our web application using Git, GitHub, and PHP on a Cpanel/WHM server.
I've tried, using the information in the article below, to set up a deploy script on our server that GitHub posts to when we push to the repo.
https://gist.github.com/1809044
Unfortunately, it seems that the fact that apache is running scripts as "nobody" is preventing the script from running. We created SSH keys as the account's user, and the git pull command is not running.
Is there any way to successfully pull a git repo from GitHub on a deploy hook and have it update without installing something complex like Jenkins?
Do you have control over how apache runs? I'm dealing with some e-mail/spam issues. I've also been reading that if you run suPHP, your apache will run as the user of that account. Sounds like that might be what you need.

Magento - using "mage" command line tool locally

I currently have Magento set up on a development server (remote, SSH access) and production server (Cloud instance, SSH access). The current set up is a subversion export to update the development/production servers. This works swell.
If I SSH into the dev server, I can navigate to the Mage root directory and run the following command:
./mage install community Namespace_Module
This works well on the dev server. However, when I navigate to my local path (on my machine, where I've svn co'd Magento), running the mage tool always chokes when a channel is involved. As an example, I tried:
./mage download community Namespace_Module
And received the following response:
Error:
download: Uri doesn't contain host part
I don't understand why this error occurs. I have looked into the mage tool's code and found that the error occurs when the channel URL is malformed. (The mage tool is basically a PHP script, and it uses parse_url to separate the channel URL into the appropriate parts for processing.) However, I am absolutely certain that the setup is identical locally, as it's all in svn, and I have tried many iterations of channels in an attempt to make it work locally.
The ultimate goal of all of this is to be able to run the ./mage tool to install modules on the local system, and commit them to svn from there. Ideally, running an svn status command should show me all the files that would be added/modified during the installation of the module.
Anyone have any ideas as to why this might be happening and how to make it run locally? Thanks!
UPDATE
For anyone wondering, the way I handled this was using the old pear command line tool, then running svn status to extract the downloaded package pieces into the way our systems are organized. It's definitely not ideal and I am still eagerly hoping to get an answer to my original question, but it's the ugly and painful workaround I'm using in the interim.
You should check whether you have all necessary php extentions installed localy.
Missing php5-curl might be the problem.
As you have gotten the code from another server, you might need to reinit things using:
./mage mage-setup
You could also try:
./mage channel-add http://connect20.magentocommerce.com/community

Categories