I am writing an app in Laravel that will interact with the server by executing bash scripts.
These scripts will create ftp users and manage directories.
What are the best practices when approaching this? I was thinking of writing a standard php function in laravel that would execute the bash script. Is there anything better or a bridge that would allow me to interact with server management through a php backend?
I have found that laravel has SSH tasks built in, would this be suitable?
https://laravel.com/docs/4.2/ssh
I would recommend looking into Envoy which is made for this kind of tasks. Using Blade style syntax, you can easily setup tasks for deployment, Artisan commands, and more.
https://laravel.com/docs/5.6/envoy
Related
This is just a general question, how does Laravel Artisan able to create proper .php file e.g. make:controller with the correct formatting and line breaks?
Is there a good PHP script which can help one develop similar php codes.
Thanks
Ultimately, Artisan relies on Shell scripts included with Laravel. Which are written in the language of Shell and reside in files ending with the extension .sh. Here is a website that contains more explanation of what those are and how to develop them: https://www.shellscript.sh/ If this is ever unavailable simply searching "How to create a shell script" will get you the answer.
PHP can execute these scripts, for example, when you visit that PHP page in your browser, or you trigger it from the command line, assuming you have PHP installed on your server.
Artisan, is custom built to allow you to extend it with more commands, and there are tutorials available to show you how to do that, but it's a completely separate process from creating custom shell commands.
PHP files are just text files, you can easily create them with any language. Also in Laravel usually used so called stubs, templates for classes like migrations, controllers etc.
Just go and look how as Laravel does that under the hood.
I have seen Jenkins being used as CI for Docker containers. Is Dokku also a CI platform like Jenkins?
If, what is the difference when I want to do CI with Docker containers for a PHP application?
Are you maybe confusing drone with Dokku? Dokku is a platform for execution of heroku apps drone is a docker based CI. I don't know much about drone but since docker can't be run inside a docker container without some hacking you are better off sticking to a traditional CI like jenkins, bamboo, team city or such.
Continuing from Usman Ismail's answer...
If you look at dokku-alt, the distinction is less clear. In particular dokku-alt allows you to use a Dockerfile for the build rather than buildstep, so it's not specific to Heroku like apps.
Dokku-alt is not in itself a CI system, but out of the box it does verify that the build completes without error before it's deployed, and using git hooks you could connect in your test-suite to run on every git push and block deployment when it fails.
CI typically is a bit more than this. You'd normally have multiple deployments for test, staging and live, and to some extent it also encompasses a set of practices. Dokku-alt gives you some very useful parts of CI, and a fairly clear path to building more of it fairly easily, but it's not a complete CI system in itself.
You might well prefer to keep your main git repository elsewhere, and keep jenkins in the picture for automating transfer to dokku-alt.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 months ago.
Improve this question
I'm starting to use Laravel 4 seriously in my projects. I understand that this framework offers many advantages when developing RESTful applications. But I understand that there is no consensus about how do deployment / publishing and app using Laravel. I am still using FTP to transfer files to my Production host. But my question is, Is there any standard way to do the same but from Laravel? I am faithful believing that with a little ingenuity one can create something like php artisan publish [Production server name and SSH credentials] as parameters.
I have read something interesting from Anahkiasen/rocketeer and Christopher Pitt, both great sources but there is a consensus or standard way to publish applications using laravel?
This is not really a Laravel problem/question, you have to ask on a dev-ops forum what they would do to deploy a PHP application like yours.
Your Laravel application is basically PHP application, some packages are provided by Composer, so it's more a Composer application than a Laravel one, but you might have some Laravel needs, like executing php artisan migrate, or any other artisan command to post-deploy your application, or not, so, it's more a requirement of your application than Laravel, right?
I developed a package to do my deployments, Deeployer. The intent of this package is, everytime I push my application to the production (or staging) branch, Github will fire a hook that tells my server to do whatever it needs to deploy my application to my own VPS. In a basic deployment it will:
1) git pull the repository
2) Execute composer update to update my vendor folder
3) Execute bower update to download whatever js or css I've installed
4) Execute php artisan migrate to upgrade my database schema
5) Execute chmod and chown to fix whatever permission mess those commands might have made to my directories while downloading files
See? Those are things that are very particular to my deployment structure, that's why I don't really think you are going to find consensus about a deployment app. When Anahkiasen first build Rocketeer, someone shout: "Why are you doing this if we already have Capistrano?".
Yesterday I bumped into this one: http://www.deployhq.com/packages, used by Ben Corlet from Cartalyst and other nice guys.
There's also Rocketeer: http://rocketeer.autopergamene.eu/.
Don't forget that Laravel itself has it's own SSH Remote component (I used it on Deeployer and Rocketeer uses it too), that might help you do whatever you need to deploy your app.
So, you better think what are your deployment needs and find your way, using a package, app or just Laravel.
There are a lot of deployment tool, like Capistrano. I recommend you to take a look at Deployer: it's has simple api, bundled with recipes for popular frameworks and apps, and can do 100% parallel task execution. Also it requires only for PHP.
deployer.org
github.com/deployphp/deployer
How to deploy Laravel
Here is an example of simple task:
task('my_task', function () {
// Your tasks code...
});
Also it has a good quality code:
You may want to check out Rocketeer:
http://rocketeer.autopergamene.eu/
If you are asking for a standard, I don't think there is one. But an alternative from FTP, well, have you considered using git as a way to deploy your site to production?
Here is how you do it:
http://danbarber.me/using-git-for-deployment/ (Link is broken)
https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps
Basically the summary is that you have a bare git repository, your own local repository and your production repository.. now by configuring the correct hooks, when you push to the bare git repository, a hook in it will tell the production repository to pull the most recent changes you commited down to the production. And in addition, setting up the correct credentials in your config depending on the environment.. you can create a new folder ex. app/config/production and app/config/stage so that you can easily run the application even while switching on both servers..
I'm not so sure about a standard way either. You do have Forge and Envoyer that work with Laravel, so that is something to look into.
Here is a way to deploy Laravel using Rocketeer and Git. It is very easy to setup and allows you to use multiple servers (think staging, production, etc.)
http://dericcain.com/blog/deploying-laravel-5-with-rocketeer
Hp: having the possibility of running an application server with both a Py interpreter with Django and a PHP engine...
It would be possible to run a PHP script into a Django template?
Is it possible to implement such application server through Apache 2.0 mods?
How would the views and the template file look like?
It is awful idea, but you can check this project.
Because ZF depends on mod rewrite for all it's URLs, it's not immediately apparent to me where I should store local scripts for use with a cron job.
Does anyone have any recommendations, or is there an "officially accepted" way?
I use the Modular Directory Structure in the design of my websites so that I have controllers, views, etc created for each separate module of my websites. Included within each module I have a scripts (or a cron) directory that stores all of the cron scripts for that particular module.
Personally I find that this keeps things simple when it comes to access resources from Zend Framework as well as from the actual web application.
I had to create a script that would be run via cron (and I was not using modules) so I stuck mine in something like library/Myproject/cronscripts
Here is a pertinent article.