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

Axeia's avatar
Level 1

Publish/Deploy site - best practices?

Hello,

I've developed a site using Laravel and I'm finally ready to deploy it to the live (shared) server. I've currently just uploaded everything through sftp (with WinSCP), exported/imported the database. Put laravels /public / folder in the servers public_html/ folder and fixed anything that broke due to environment changes (different MySQL versions). So basically I did what this video by Traversy Media also tells you to do: https://www.youtube.com/watch?v=6g8G3YQtQt4

However uploading a new version is a bit of a nightmare, simply dragging the folders over in WinSCP and applying what database changes are needed takes a long time, surely there must be a faster way to do this? Just the file uploading can take 20 minutes. Zipping things up and then unzipping it through the cpanel takes less time to upload but adds additional steps slowing things down.

Tools at my disposal: A linux (openSUSE) local server that stores the files and acts as the local webserver that I have full access to, my own Windows 10 desktop. And I can connect to the remote shared host/server through WinSCP (FTP/SFTP), putty, cpanel.

[edit] Ideallly I'd just run a script that uploads only files that have changed, doesn't overwrite the .htaccess that's different between the local and remote server, minifies the CSS/javascript etc. Seen some guides recommending to use git to speed things up. I'd like some advice/examples of what other people are doing and what the best approach is. Thank you :).

0 likes
12 replies
lostdreamer_nl's avatar

The easiest way is to go with git push / git pull and a free gitlab account.

Setup your project in gitlab, use local git to push your changes to it, and setup git on your server to pull the newest version.

markotitel's avatar

A lot of ways.

If you have GIT installed on the WHM server, and if you have SHELL access to the server you can setup a CRON job which will do git pull for example.

And you should put .htaccess in gitignore that way you will not overwrite it. In the cronjob you can also add migrate --force so if you have any new migrations they will be run also.

primordial's avatar

@axeia If you have SSH access you may find https://capistranorb.com/ useful for deploying from your desktop else the solution described by @talinon is pretty cool. Please do not "git pull" from your remote server to get the latest version. Criminally bad practice.

Axeia's avatar
Level 1

Thank you all I ended up putting my project on bitbucket in a private repository. However getting it to the server would be a lot easier if I could use git pull if you don't mind me asking @primordial why would this be such criminally bad practice.If it helps - I'm the only developer so I know exactly what would get pushed/pulled.The easiest/most streamlined way to proceed from here (in my eyes at least) would be

  1. Create a symlink from the shared hosts "public_html" folder to laravels "public" folder
  2. Create a (PHP) script on the webserve that does a "git pull" to update everything and run migrations
  3. Create a webhook on bitbucket that after receiving a push calls the PHP script from step 2.

What would the alternative be for the git pull? Because I can only think of solutions that would download a bunch of unchanged files resulting in longer wait times and lots of network traffic. I am however very new to git.

Zenith2012's avatar

Hi,

I know this might not be an option for everyone but I'm just starting out with Laravel and managed to get my boss go purchase a Forge subscription for me.

We use ESXi servers already for test/development environments so I fired up a new ubuntu server, linked it to the forge account and the source gets synced with github automatically.

It's nice, simple and seems to work really well. I fully understand sometimes the cost means this isn't an option for everyone (myself included, I'm not paying) but if it's an option you should definitely look into it.

Axeia's avatar
Level 1

Laravel forge definitely sounds like a no-messing about solution, not to mention it supports laravel to boot! But I am messing about and doing things as cheap as possible so sadly it's not the solution for me in this case.

For now from what I've described earlier I've done step 1 and doing step 2 manually as I think git pull in my script is choking on the password prompt. Still - it's a heck of a lot faster than uploading things manually through WinSCP :) and with enough dedication/time Step 2 and 3 could probably be made to work. I found the article below for example that seems to do pretty much that http://abhisheksachan.blogspot.com/2014/04/setting-up-godaddy-shared-hosting-with.html

lostdreamer_nl's avatar

"as I think git pull in my script is choking on the password prompt"

You can setup ssh key's so you dont have to type in passwords and can use it from scripts as well ;)

Simply follow this tutorial for example: https://ourcodeworld.com/articles/read/654/how-to-create-and-configure-the-deployment-ssh-keys-for-a-gitlab-private-repository-in-your-ubuntu-server

After that you can do a git pull without having to type your password on the server end (same goes for git push on your dev box by the way)

ravenshill's avatar

I use forge with a free bitbucket account for this. I have a box on digital ocean that is extremely easy to to deploy to. There is a monthly fee involved , what forge does you can do yourself but for the money the forge product is smooth and reliable without you doing all the grunt work. I would recommend.

If you are restricted to using a server that is not supported by forge you may have to do something a bit more custom. Before using forge I was uploading my files with rsync (which is super fast) and remotely exec-ing commands with laravel/envoy.

duncanmcclean's avatar

Personally, I would use something like Laravel Forge or CodePier. CodePier has a free plan that can setup your server and do deployments from Git etc. I would recommend using that.

Zenith2012's avatar

@RAVENSHILL - Before forge I would just git pull on the production server. Similar to OP I'm the only dev and it's just me messing about with laravel to get to grips with it. Although I am working on a couple of projects that will go into production now.

Someone mentioned it's not a good idea to git pull on a production server but I'm not sure why? In my situation it's a private repo that only myself has access to.

Now I use forge and it streamlines the process a lot!

Next for me is looking at having a dev branch on my local machine, a forge staging server and forge production server each automatically deploying the correct branch when code is pushed.

Axeia's avatar
Level 1

I did go with a git pull, however trying to optimize it further by putting the vendors folder in the .gitignore and then running composer install on the server gives me a 500 Internal Server Error. I've no idea what is causing it and the helpdesk of the host tells me there is no error logs that would explain what is causing this. (definitely can't find any error log myself).

So I guess I'll go back to having /vendors/ included in my git repository - it seems to be choking things though as commands such as git status take a long time to execute.

[edit] Ah it just dawned on me.. having removed /vendors/ and then having recreated it through composer undid the permissions on it. This is causing errors by laravel itself that are in /storage/logs rather than any apache error log.

Please or to participate in this conversation.