Deployer to deploy on file edit - php

I have php deployer set up which will deploy all my files to staging server whenever I run dep deploy:staging. Now I want to know if there is a way to run that deployer command whenever the file got changes.
I have tried using Facebook's watchman, I managed to watch the file changes but I couldn't run the deployer command. This is how I tried.
watchman watch /my/project/folder
watchman -- trigger /my/project/folder deployme '*.php' -- dep deploy:staging
I am not sure exact reason but I think dep command was not runnable with watchman because I try running batch commands like "cd","ls" and it seems to shows the result on the log file.
So I want to know if there is any other way of watching the file change and run the deployer command automatically? One example of what I want to do would be exactly how Shopify works with the deployment.

Related

Laravel PHP run php artisan serve automatically if something changes

I am using laravel for a php webproject.
Yesterday I noticed an issue:
Everytime I make changes f.e. in the controller files I need to rerun php artisan serve, which consumes a lot of time (close CMD, open it again and type php artisan serve)
I am trying to find a way, so this command will automatically rerun when I test my application on localhost.
I could probably write a script or something with Python, which will automatically open CMD and execute php artisan serve whenever I click f.e. CTRL + F5, but that feels very hacky, is there a cleaner solution?
I also found a guide on how to edit the hosts file in system32 folder and the httpd-vhosts.conf in the apache folder, but after doing all steps, if I try to reach my application I get "It works" instead, which is simply an indicator for a successfull apache installation.
You should avoid php artisan serve cause it's just a shortcut to run your Laravel project. For a better development environment, you should use Laravel Homestead which offers a complete solution.

Codeception install problem - vendor/bin/codecept vendor not recognised as internal... windows10

When I download codeception with composer and run vendor/bin/codecept from project directory, it says vendor not recognized as internal or external program.
There is a folder inside vendor codeception/codeception/codecept bootstrap and it works if I run it from in there but when creating a class test and running the tests I get weird results like isAngularTest....??
I have tried quite a few different commands but cant get it to work they way the codeception website indicates or how my lecture says it should. I am using windows 10.
You need to run vendor\bin\codecept.bat and not vendor\bin\codecept - the latter one is a Bash script, it won't start in Windows command line.
I am not sure why you tagged this question with PhpStorm, so I'll put this here just in case.

Linking Storage folder without using Artisan [duplicate]

I want to test some Laravel applications on my basic shared host.
Currently I just upload my complete application including the vendor files, however this takes quite long.
Since I do not have ssh access to my host I'd like to know whether there's an option to run composer / artisan commands without this.
I found this link: Use Composer without ssh access to server (Second Answer) which describes how to run composer using http://phpshell.sourceforge.net/
However, I can change folders in the console etc. But I cannot run php commands - I always get internal server error.
Check if your shared hosting provider has console feature in their CP which allows to run shell commands. Maybe you'll be able to run commands from there.
As alternative, you could right your own artisan runner and call artisan commands from the code:
Artisan::call('migrate');
To run composer command from PHP code, use shell_exec:
shell_exec('composer update');

Hot reload when working with Vue

Is there a way to enable something like hot reload when working with single file Vue components in laravel? The laravel docs suggest gulp watch, but doesn't that mean I will have to kill the laravel dev server each time I make a change to a component? Is there a way to reload when I add (or make a change to) a component without having to stop the server and run the gulp command?
You should only need to issue the gulp watch command once, then it will continue to run. I don't know what system you're on but if you're using a Bash Terminal you can run it as a background task using the Ampersand. You could also be running your development server as a backgrounded task, use homestead, or open up two terminal windows.

GITHUB : I want to add project from local to live server through github [duplicate]

Is there any way to set up git such that it listens for updates from a remote repo and will pull whenever something changes? The use case is I want to deploy a web app using git (so I get version control of the deployed application) but want to put the "central" git repo on Github rather than on the web server (Github's interface is just soooo nice).
Has anyone gotten this working? How does Heroku do it? My Google-fu is failing to give me any relevant results.
Git has "hooks", actions that can be executed after other actions. What you seem to be looking for is "post-receive hook". In the github admin, you can set up a post-receive url that will be hit (with a payload containing data about what was just pushed) everytime somebody pushes to your repo.
For what it's worth, I don't think auto-pull is a good idea -- what if something wrong was pushed to your branch ? I'd use a tool like capistrano (or an equivalent) for such things.
On unix-likes you can create cron job that calls "git pull" (every day or every week or whatever) on your machine. On windows you could use task scheduler or "AT" command to do the same thing.
There are continuous integrations programs like Jenkins or Bamboo, which can detect commits and trigger operations like build, test, package and deploy. They do what you want, but they are heavy with dependencies, hard to configure and in the end they may use periodical check against git repository, which would have same effect like calling git pull by cron every minute.
I know this question is a bit old, but you can use the windows log and git to autopull your project using a webhook and php (assuming your project involves a webserver.
See my gist here :
https://gist.github.com/upggr/a6d92e2808e9628ebe0d01fd93569f4a
As some have noticed after trying this, if you use php exec(), it turns out that solving for permissions is not that simple.
The user that will execute the command might not be your own, but www-data or apache.
If you have root/sudo access, I recommend you read this Jonathan's blog post
When you aren't allowed/can't solve permissions
My solution was a bit creative. I noticed I could create a script under my username with a loop and git pull would work fine. But that, as pointed out by others, bring the question of running a lot of useless git pull every, say, 60 seconds.
So here the steps to a more delicate solution using webhooks:
deploy key: Go to your server and type:
ssh-keygen -t rsa -b 4096 -C "deploy" to generate a new deploy key, no need write-permissions (read-only is safer). Copy the public key to your github repository settings, under "deploy key".
Webhook: Go to your repository settings and create a webhook. Lets assume the payload address is http://example.com/gitpull.php
Payload: create a php file with this code example bellow in it. The purpose of the payload is not to git pull but to warn the following script that a pull is necessary. Here the simple code:
gitpull.php:
<?php
/* Deploy (C) by DrBeco 2021-06-08 */
echo("<br />\n");
chdir('/home/user/www/example.com/repository');
touch(GITPULLMASTER);
?>
Script: create a script in your preferred folder, say, /home/user/gitpull.sh with the following code:
gitpull.sh
#!/bin/bash
cd /home/user/www/example.com/repository
while true ; do
if [[ -f GITPULLMASTER ]] ; then
git pull > gitpull.log 2>&1
mv GITPULLMASTER GITPULLMASTER.`date +"%Y%m%d%H%M%S"`
fi
sleep 10
done
Detach: the last step is to run the script in detached mode, so you can log out and keep the script running in background.
There are 2 ways of doing that, the first is simpler and don't need screen software installed:
disown:
run ./gitpull.sh & to put it in background
then type disown -h %1 to detach and you can log out
screen:
run screen
run ./gitpull.sh
type control+a d to detach and you can log out
Conclusion
This solution is simple and you avoid messing with keys, passwords, permissions, sudo, root, etc., and also you prevent the script to flood your server with useless git pulls.
The way it works is that it checks if the file GITPULLMASTER exists; if not, back to sleep. Only if it exists, then do a git pull.
You can change the line:
mv GITPULLMASTER GITPULLMASTER.date +"%Y%m%d%H%M%S"`
to
rm GITPULLMASTER
if you prefer a cleaner directory. But I find it useful for debug to let the pull date registered (and untracked).
For our on-premises Windows test servers, we use Windows Task Scheduler tasks, set to run every 3 minutes, pulling from Bitbucket Cloud to repositories on those servers. While not instantaneous, it meets our needs, and has proven to be reliable.

Categories