0

I have my Laravel application deployed under /var/www/<host's name>/, whereas /var/www/<host's name>/public is the web-accessible directory. I'm using GitHub now for quite a while, however, I seem to have never made use of more of its potential (than just using it as a code backup source). What I want to achieve:

  • I'm working on my application on localhost
  • I'm pusing to my Git's master
  • Somewhere in my server (perhaps outside the /var/www/ directory), I want to clone my Git and have everything pulled from GitHub, so that the web application is 'updated' so to speak

However, I don't want existing data (such as <laravel>/storage/app/users/, which contains folders of all users and their files) to be deleted or something. I just want the most current version of my code running, patching while running so to speak. I know git clone <url>, and I know symlinks.

I just thought of a folder, perhaps in my home folder, named after my application's name (e.g. "/home/myuser/laravel") and now running git clone ... shall automatically do what I described, so that accessing the webpage returns with the code we updated just before.

I hope I decently crossed my point, am looking forward to seeing suggestions on this.

1

1 Answer 1

1

I would suggest to allow the new deployments to start from scratch every time, even in the storage directory and use Laravel's Filesystem to store your files: https://laravel.com/docs/5.6/filesystem

This alternative not only solve your problem, but also give you the opportunity to escalate, sharing files amount multiple server instances.

The options for the filesystem configuration are multiple, from third party services such as Amazon S3, as well as your local disk (that could be mounted disk, symlink, or whatever suits you better).

The beauty of it is that you can not only have different filesystems depending on your needs, but also you can change from one driver / configuration any time without change a single line of code.

Do not forget to use the object to get the final url (Ex: Storage::url('file.jpg')).

If you are worried about the url host or path, you can use load balancers, domain / subdomain zones, servers rules to prettify mask ip's, and paths.

A good approach could be keep all the last deployments in a directory, let say /opt/<project>/<version>+<commit> and a symlink to /opt/<project>/current whenever the deployment it's finished. In your case, it could be a link to /var/www/<host's name> or link /var/www/<host's name> to /opt/<project>/current.

You can get the version from composer.json or from a git release tag.

You can use ci (continuous integration), such as circleci, to:

  1. composer install as a dev version and run your tests (if it doesn't pass the tests, the deployment would be cancelled).
  2. composer install as a production version.
  3. composer archive to compress it.
  4. create a new pre-relase tag in git.
  5. Attach the compressed project to the release.

This way you don't even need to have git installed in your server, just download the compressed file and extract it in /opt/<project>/<version>+<commit>.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.