Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mushr00m's avatar

Dev workflow (local / production website)

Hi guys !

I need some help to improve my work habits. Right now I develop websites on my local machine, then upload them on the server and when I have to make some changes I go directly on the server...BAD cowboy coding i now...

So I want to do it a better way and need to know how do you guys do. Specially now that we use things like Composer, Gulp, Grunt etc that need command lines, and not all hosts provide that. Do you always have a full copy on your local machine and only work on it then upload ? Right now I don't want to use Git, even if I know it's really powerfull, it's a step too far for me...

Thanks for any tips ;-)

0 likes
30 replies
austenc's avatar

My #1 recommendation would be to integrate git into your workflow (probably either using github or bitbucket). If you're not versioning any of your changes right now, learning to use git will change your life. Also, definitely use composer and make use of all the great packages out there so you don't have to re-invent the wheel!

In terms of pushing to a production server, there's often more that needs to be done with a laravel app than simply pushing up code. Often you'll want to run database migrations, optimization tasks, etc... Using something like laravel's forge and a VPS is often recommended.

3 likes
Devon's avatar

Yes, I always have a local copy that I checkout from my repository when I need to work on it. It's never a good idea to develop directly on your production site. Jeffrey does all of his work on a Mac in the videos, I do everything on Windows because I have yet to invest in a Mac. Either way, you should have a proper development environment where you can do your work, write/run tests, and enable debug mode without it being a security risk.

Several people are using Laravel Homestead, I've not yet made the switch as I really don't like working with VMs on Windows.

Do a search for environments and you can see that Jeffery has covered quite a bit. It's a good place to start.

Git is something that takes a getting used to. I only use the basic commands as it's still quite new to me. The basics, however, can be learned in a matter of seconds... If you're uncomfortable with the CLI, you can always use a GUI for Git too. However, at some point you should certainly make the transition to CLI as it's faster and more powerful. I doubt your project, nor mine, is this complex - but the graphics along with the commands from the article A Successful Git Branching Model is something that helped me better understand Git basics, in addition to Git-scm.

Mushr00m's avatar

Thanks for your answers. @devjack : No I'm using Mamp for the moment but will use VM in the future

I know that Git / Versioning is the way to go, but I want to make it step by step not to be lost. But even if using Git or not, you do all have a dev version of all your projects and only work on them then deploy/upload/merge...

So when using Gulp for example, you do all the minifying, compressing of your JS / Sass / Less on the local / VM machine then upload ? Nothing on the server...

devjack's avatar

I would highly recommend using Homestead, I switched from MAMP to using a VM and I never look back. I do all Gulp stuff on my local machine (VM) and then deploy using git. You should never do any of this stuff on a server, only on your local machine.

unitedworx's avatar

My workflow is not far from yours @mushr00m many times I do small php/html/css bug fixes directly on the server :) not the best way but it's faster than anthing else if you are confident your code won't break anything.

Other than that I use Coda 2 for light php/css/html coding and I have bothe local and remote sites setup so if I work locally Coda 2 shows me in a publish windows just the files I chnaged so once I get something done It shows me all the files I chnaged and with a hit of a button it will publish just those files that were changes ( not git or svn is involved here)

Of course since I some times do quick edits on the servers I first use rsync to grab only files that are different from my live server with my local setup. And then I start working on my changes in Coda 2 so I know I am starting with the same files in local/remote .

Of course the best way to do this it using git and pushing and pulling from local/remote but didn't really play with this much. although I started using git locally for versioning in some large projects I haven't yet went ahead to use git for deploying from local to production.

For heavy php coding I use phpStorm while waiting for Coda 2.5 which will bring project wide code auto completion.

Mushr00m's avatar

@unitedworx : You are actualy doing what I think I want to. I'm currently using Expresso and wait for Coda 2.5 to come to switch. You say you use RSync, is it directly in Coda ?

unitedworx's avatar

@mushr00m I used to use espresso as well, I was getting really addicted to css overrides but Coda 2 ended up better since whichever css,html,php file I edit it auto refreshes my preview window! Even without project wide php auto completion its damn good so I wouldn't wait for 2.5 to give it a go!

Rsync is a Unix command so it's available on your Mac and on your server as well. It helps synchronizing your remote server with your local folder damn fast!

Here is an example usage of rsync since it will help you keep your local version same with your server version especially if you do edits directly on the server.

For rsync open terminal on your Mac and run

rsync -rvphi --delete ftpusername@mysite.com:httpdocs/ /Users/paris/www/mysite.com

You just need to supply the ftp/sftp password and it will start its magic

P.S Google to see what those rsync flags do! :) don't worry about --delete it won't touch anything on the server but only delete files that are in your local version and are not in the remote!

unitedworx's avatar

@henrique I totally understand git and branches and stuff but when it comes to actually using git to deploy your project from local to remote I think you need to play a lot to find what works best since you can do this a million different ways. For one I don't want to reply on 3rd party services like github or bitbucket. I manage 150 projects and would cost me a fortune to rely on those services with that many private repos! Solution is to use git on the production server itself to do this, am on a Rackspace deticated server here. I have this bookmarked but haven't gottent into it yet a Thought it apers to follow the approach I am after http://deadlytechnology.com/web-development/deploy-websites-with-git/

henrique's avatar

I have about 50 private repos on bitbucket and never had a single problem, but I understand your concerns.

There are some opensource softwares that are similar to what github/bitbucket are but since it's opensource you can have it self-hosted (eg: https://about.gitlab.com/), that would give you a nice interface to work with.

But if you don't want to rely on that project also, you can create your own server using the approach the link you posted have, git have the advantage of being both the server and the client, so it's easy to create a server :)

But with 150 repos, it might be boring creating that many by hand, so an interface/script to automate things would help (look for selfhosted git and find the approach you like the best).

unitedworx's avatar

@Mushr00m I honestly don't know how I managed before rsync. It was a mess I think :)

@henrique Thanks for your pointers, I actually have a bitbucket account and a few private repos there but what would be the process of deploying from bitbucket to the production server? Do you have different branches for develop and for production and have hoocks to automatically push to production server when you push from e.g develop to production brach?

If you have a link with info on this I will surely look into this further. I want to use git for managing all my projects and deploying to the production server but I don't want to make my life complex :)

I already use Tower on Mac to manage a few repos just for the sake of versioning and rolling back if an idea involving a zillion changes does not pan out. Really helpful.

henrique's avatar

@unitedworx For branches, I use the workflow posted on my first post on this thread, which is basically: master branch = production branch develop branch = working state branch for development branch = branch for implementing feature X

And then I merge and tag the branches (take a look at the article, it's a really interesting approach to organizing branches).

As for deploy, the repo in production only pulls the master branch, but I don't like automated deployment because I don't have tests most of the time (shame, I know, currently working on fixing this bug), so I like to stay in control and, at least, push a button. My current deployment flow is like this (manually):

- ssh into server.
- php artisan down
- backup
- git pull
- composer install
- composer dumpautoload (in case there is nothing to install and I need to update something)
- php artisan migrate
- anything I may need to do
- php artisan up

One of the servers had nginx and I had to pull a lot of times a day, so I created a script that would git pull directly from a browser url (instead of forwarding the request to php-fpm, it ran a bash script).

I'm thinking about creating a command that would automate everything, but since I deploy just once a week and for only two projects (so about 2 deploys per week), I didn't get to it yet :P

For an easy to use push to deploy, you could try Forge https://forge.laravel.com/, I never tried it, but I will later this year, it looks awesome :)

unitedworx's avatar

thanks for the reply @henrique

I probably do 20+ deployments in a week so when I go ahead with git for deployments I want it to be as much automated as possible! Ideally just pushing from develop to master branch to trigger pushing to bitbucket private repo and then to the server.

Mushr00m's avatar

@unitedworx : I just have a question off topic, about Coda, how do you do not to upload the node_modules folder (inside your project created when using gulp) ? Thanks

unitedworx's avatar

You can tell Coda files or folders to exclude when uploading so you don't have to worry about them.

In any case you view the list of files it will publish and you can easily tell it to publish specific files or all of them or tell it to forget that a file was changed

unitedworx's avatar

@valorin many thanks, will look into laravel envoy although i will probably follow another root since most of my projects are not laravel based. Hopefully after some time I will switch all of the to laravel :)

NormySan's avatar

You should definitely get some kind of git going for your projects! It's not that hard, if you have a mac you can get the Tower client, it's super easy to use and github has some affordable options if you want to keep secure backups.

My own workflow recently involved having my projects on private Github repos, but because of the limited automatic deployment options i decided to move my repos over to beanstalk. With their service i can set up automatic deployments just the way i want, so right now i have automatic deployments whenever i push to the staging repository, production must be manually initiated. When the deployment is done beanstalk will run a few commands I've told it to run like minifying css/js updating dependencies etc.

And over to your question on gulp, composer and that stuff. If your server provider wont allow you to run these stuff when the best thing you can do is make sure everything is downloaded and up to date and run any minification script before uploading the code to your server.

unitedworx's avatar

@NormySan I had a look on beanstalk a while ago since it seems to cover more ground in terms of deploying to the server compared to both github and bitbucket , gets a bit pricy if you plan on using a lot of repos thought. If I move all my projects (100+) to a git workflow it will cost a lot yearly!

I think I found a starting sauce though!!! bitbucket with FTPloy

Am already using tower on my Mac so I can start adding all my projects there and push to private repos in bitbucket. Since its pricing is based on number of users then I won't need more than 5-10 users to start with so it will be inexpensive. Then I can connect bitbucket with FTPloy (which is inexpensive as well ) so I can have automated deployments via ftp/ssh.

Not a full git baked solution but will be inexpensive and should get me going fairly easy.

Shovels's avatar

I run Laravel Homestead locally with Gulp running to concatenate/minify javascript, compile SASS, compress and optimise images and then add file revisions to all static resources.

This is all in a git repo which I can push up to a private repo on BitBucket.

For deployment I use Laravel Forge and Linode Servers. Tying the services together is really quite easy (there are a couple of small gotchas along the way, but nothing major).

If I need to make a change all I do is:

  • Create a git branch
  • Make the necessary changes
  • Check that it's all running on my local dev environment
  • Merge the changes back to the master branch
  • Push the changes up to BitBucket

Laravel Forge takes care of deploying the changes to the live server.

It's soooo much easier than FTP'ing the changed files up, so would highly recommend spending the time to get a workflow similar to this running.

Valorin's avatar

will look into laravel envoy although i will probably follow another root since most of my projects are not laravel based.

@unitedworx - The best part of Envoy is that it's standalone, so you can use it with anything. Simply install as a global composer package, and you can run Envoy on any project. :-)

psmail's avatar

Along the lines of @NormySan, a gui can go a long way to easing the pain of git. There is a free GitHub git gui, if free stuff floats your boat.

Jazerix's avatar

I actually did the same, about a month ago, but I decided to change everything with the new school year. I currently have three environments:

A local one where i code using xampp and primarily Sublime Text (3) where I commit to my github repository. A testing environment using Laravel Forge And at last a production, which I'm currently moving to Laravel Forge as well.

Both my testing and production environments are automatically pulling from Git, and the production is also hooked up to New Relic for better analysis :).

unitedworx's avatar

WOW! i just setup on a project of mine the local git repo, the remote bitbucket repo and then connected ftploy with bitbucket! Although I use tower to setup my local git repo I can now manage it within Coda 2 so I can see changed files, commit them and then push my changes to bitbucket form within Coda 2 SVN panel. Ftploy will do its magic to deploy changes to my server!

This is neat!!! Not far from what I am already doing. surely It takes some extra steps to setup it up for each project but for my daily workflow its just an extra step to commit the changed files and then just push to the remote. I can now have a full history with all my commits/deployments for a project!

Why didn't i get to this earlier? :)

P.S. FTPloy even sends me a push notification on OS X when the deployment is done so i know it went all the way through!

Mushr00m's avatar

A little up on my own topic. I've some hard time figuring how to have a perfect sync from the server and the local. When I reopen an old project (like 6month ago) I want to be sure to work with the latest code. If someone else added some things directly on the server code. So I looked at RSync to do that, but it looks a pain to do it everytime I need to work on something. How do you guys cope with that ?

unitedworx's avatar

Rsync is fairy fast, it takes just a few seconds to sync a whole site from your remote server to your local machine. It only grabs the updated files and also if you have folders with user uploaded images you don't care having locally you can exclude that!

But overall it's a better practice to avoid direct edits on the server so that you know the local copy you save is up to date, that is if you work solo!

If you are part of a team and multiple people might change things on the live server then deploying centally with git is your best option. E.g a private repo in bitbucket where team members can push and pull from the dev brach and a single person allowed to push from the develop brach to the master brach to deploy to the live server.

I gave git a go for deployment but since I work solo it made things more complicated and crested problems rather than solving them!

Atm my workflow is to rsync a site from remote to local, then use navicat to to sync the remote db with my local version.the I am working on a copy of the site with actual data! Once done with my changes I simply push publish in Coda2 to publish my changes to the live server via sftp! I surely use git to version my changes however I don't use it for deployments, tried it and didn't work for me!

Mushr00m's avatar

@unitedworx : Hi and thanks for all your answers. I up this topic because it looks like FTPloy can be a good system but I was wondering how do you do for Vendors, on basic sharehosts where you can't use Composer nor NPM ?

Thanks

unitedworx's avatar

@Mushr00m I never used shared hosting since I publish all my projects on a dedicated server so I have full control. However you don't need to use composer or npm on the server! You can simply upload ALL project files via ftp including vendor etc etc!

Never settled with ftploy or deployhq btw since I have always been spoiled by direct server updates for little patches or adjustments clients need over time! I didn't manage to break that "bad" habit yet! :)

Will have a go with envoyer however and see it that helps a bit with my overall workflow!

Please or to participate in this conversation.