Is there a good, simple solution for PHP "one-click" deployment to a production server? And also with a functionality to reverse back if needed.
In particular, I am interested in this with regards the PHP code itself. But if you know a good solution for MySQL, it is also welcome.
For deploying easily, we use Capistrano (its a Ruby tool, but deploys anything really) and its great, just need
cap deploy
from the command line (at its simplest)
If you want something written in PHP I can't name any I'm afraid.
For MySQL, I guess you would need some kind of migration tool, or build your db changes into SQL files that can be run by your deployment script.
Related
I've recently launched a linux EC2 instance with Apache + php. My php code eventually watered down to merely calling python from the shell, and nothing more. It's quite an ugly solution, but it works. So, basically my questions are:
Just how bad/inefficient/silly is it to have a php code that
repeatedly calls exec(python my_script.py) rather than a solution
that's more native to python? I'm assuming it's wasteful, but I'm trying to understand if I ought fret about it or just keep on chugging.
I managed to get bottle.py up and running, and was just on the brink of replacing my "stupid" solution with a continuously running bottle script, that seems more natural. But I failed to integrate this solution with Apache via mod_wsgi, I think it has to do with python versions incompatibility issue that I'm loath to deal with.
Considering (2), what are the repercussions of bypassing Apache entirely and simply calling a bottle script with a "run" command to listen to all incoming communication? It seems ugly, but is it inefficient or bad in any way? If not, I'll just go ahead and call that my solution... But I'm concerned that there might be a reason for people to integrate with Apache.
Any input would be appreciated. A decent amazon AMI that already runs python 2.7 and processes incoming request by python by default would be nice. Someone saying authoritatively that I shouldn't mess about with this whole apache/mod_wsgi business and just call "bottle" as a script would be best :-)
EDIT: I have python 2.7 running bottle with paste as my webserver. Do I have any REAL reason to prefer apache over this solution? and while I'm at it, does anyone have experience with enabling ssl in this enviornment?
Cheers,
Uri
Why don't you just spin up a Beanstalk instance with Python and let Amazon deal with those details? Beanstalk runs on EC2. Seams silly to make your own spaghetti when Amazon has already made you penne vodka! Lame metaphors aside, I think you'll save yourself the added stress and no need to mix PHP/Python.
If you need to update python version on beanstalk I would recommend two options:
Create custom ami based on standard ami of beanstalk. Good article here: http://blog.jetztgrad.net/2011/02/how-to-customize-an-amazon-elastic-beanstalk-instance/
Customize instance with help of elastic beanstalk configuration files. Have a look here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html.
Disclaimer: I work for OpDemand.
Most painless would be to use a pre-rolled AMI, but those become impossible to manage.
If you're looking for something more flexible, OpDemand offers EC2 templates for Python applications that you can deploy with one click. They're vanilla Ubuntu 12.04 LTS boxes with Nginx in front of Procfile-defined web workers. It's a lot like Heroku, but it's all run out of your own EC2 account. The example Python application uses Flask, but it's trivial to switch to Bottle.
Best of luck!
I've finally committed to really learning the software design process correctly in order to advance my skills and grow my business. This means embracing version control (git), setting up a development-staging-production environment and keeping these environments as similarly configured as possible.
I'm getting really caught up with the last step, in picking a solution to automate and sync my server settings. I've looked into Chef, Puppet & Fabric, but for my purposes they all seem overly complex. I am:
Developing a small web app on a single server
Will be developing in a LAMP environment with intermediate PHP & UNIX skills
Won't be heavily modifying environmental variables (primarily php.ini, apache configs)
I would appreciate any recommendations on solutions that would be easier to implement than mastering the complex Chef environment or learning Python to use Fabric. I can do this if necessary, but am hoping there is a more basic / elegant solution given my very simplistic needs.
In the company I work for, where we have more or less the same needs, we just setup a couple of bash script.
Basically it sets up the git repo (local, and distant bare), install apache2 and PHP5 (and some php extensions), configure the apache's vhost, php.ini, install frameworks and bootstrap project if needed (for us it's symfony).
We have another script, that fire some EC2 instance, run the previously mentionned script, launch the test suite, and download the report of these scripts.
Chef & Puppet works well, but it's a little overkill, unless you have many projects that runs in the same time.
Edit :
If you want to run a script after commiting/pushing (like deploy to staging/pre-production server, launching your continuous integration build, etc), there's a way to do this using git call post-hook, see Deploy a project using Git push
I'd strongly recommend having a look at Ansible for this purpose.
It is a full solution, which means it can handle configuration management, deployment and so forth. However, it is far easier to learn in my experience than Chef or Puppet as you can start by doing basic shell command execution and move on from there.
There's no need to learn a new language; all the configuration and specification you would be doing is done in YAML, which is just structured text.
Overall, Ansible will give you much of what Chef or Puppet will at your level and hopefully you will find it more straightforward to get started with.
If you're serious about professional web development, I would strongly recommend taking a second look at Chef. It works really great for us (me and my co-workers). I know it may seem like overkill, but in my opinion, the advantages far outweigh the learning curve. It's a lot more work to try to maintain different server environments (and local development environments among co-workers). Plus, Chef makes it super easy to install Apache, PHP, and MySQL since there are already cookbooks/recipes available.
Also, make sure you check out Vagrant. It works with Chef and VirtualBox, making it really simple to set up a local development environment.
Also, if you're working on a Zend Framework project, you may be interested in the Zend Framework Boilerplate project which is an all-in-one LAMP development environment which uses Vagrant.
For Simple LAMP Development you don't need anything at all. It is not that simple development can't be automated, it's because for simple development it is usually sufficient (easier and faster) to write some scripts yourself (even in Python).
When you realise that your custom scripts are hard to maintain or not enough, you are ready for tools like Fabric (shell command automation) and/or Chef/Puppet (server configuration management). They are not easy to learn, because system interconnections that they are managing are not simple (which is not your case, obviously).
For your single server, I'd say README + Mercurial (Git if you need GitHub) plus some symlinking should be more than enough to manage configs, sources and server setup. For automation and deployment just write a script that uploads your site to FTP/SSH, restarts server, executes tests, whatever - you decide. That is Simple Deployment for Simple Development. If you'd rather avoid writing PHP for that and don't know shell - then Fabric will save some time for you.
Once your scripts are ready, you already know your problems, you can learn Chef/Puppet in background to see if it is worth complicating things for your environment.
If you choose to try Chef - don't start with Chef Solo - it's a poisonous snack for a starter - use Hosted Chef + Client - it is free for your setup. Can't say anything for Puppet - I chose Chef because my mom said I need to know how to cook.
I'm doing PHP development and I'm thinking of using one of these. I have both PHP and Java installed on my machine. In theory I could use any of the two.
What are the compelling arguments to pick Phing over Ant?
The greatest argument I have in favor of Phing is that it's fully developed in PHP ; which means, at least :
You can debug it / submit patches if you want
You can develop tasks in PHP
including tasks which are specific to your project
that can use stuff from your project (I've written a couple of tasks that use functions of Drupal, in a drupal-based project)
And, if you are working on a PHP project, your team probably knows PHP well -- while they might not know Java
No need to install Java on your servers
The main argument (for me) for using Phing when doing PHP development is
staying inside the PHP Ecosystem.
When using Phing on shared hosts, you can be sure it works when PHP works.
And you can easily extend Phing with your own task in PHP.
And since it's a PHP tool you will sometimes find it in other applications as well.
For my web application running on LAMP, I need to be able to deploy database migrations and code changes on multiple servers and be able to test deployment afterwards, all of this automatically done by scripts.
Currently I'm torn between using directly my build tool (Phing) with some special deployment/test tasks, or shell scripts, or a scripting language like Ruby or Python.
The problem is that I feel that a build tool should be used to build, not to deploy. I also feel that shell scripts are hard to maintain and not very readable.
Do you have any good advice on this subject ?
For PHP projects, Phing is the way to go. Deployment is definitely one of its intended usage, considering that in PHP there isn't any "real" build process - as scripts are not compiled.
From the official site:
If you find yourself writing custom
scripts to handle the packaging,
deploying, or testing of your
applications, then we suggest looking
at the Phing framework.
Phing can do everything shell/python/ruby scripts can do, and can be extended in PHP which is its major draw for PHP developers. Why would you want to use ruby/python if you are a PHP developer?
Rasmus Lerdorf (creator of PHP) released a deployment tool called WePloy.
A lot of people here on stackoverflow seem to really like Capistrano.
To deploy web applications, PHP or other, in some click, you can use fredistrano.
What have I used?
svn post-commit hook
shell script to rsync
perl cgi script to svn switch across systems
It doesn't seem like any of these would be acceptable for you though, given your statement "I also feel that shell scripts are hard to maintain and not very readable."
Personal script which uses
Svn export + rsync
We currently use a hand-rolled setup and configuration script and a hand-rolled continuous integration script to build and deploy our application. I am looking at formalizing this somewhat with a third party system designed for these purposes.
I have looked into Phing before, and I get that it's basically like Ant. But, my Ant experience is somewhat limited so that doesn't help me much. (Most of the Java work I have done was just deployed as a jar file).
I have looked into Cruise Control before, and I understand that phpUnderControl is a plug-in for CC. But, Phing says it also works with CC. So I am not clear on the overlap here. Do I need both Phing and phpUnderControl to work with CruiseControl, or are they mutually exlclusive?
What I need exactly is something that can:
Check out source from SVN
Install the database from SQL file
Generate some local configuration files from a series of templates and an ini file
Run all of our unit tests (currently ST, but easy to convert to PHPUnit) and send an email to the dev team if any tests break (with a stack trace of course)
Generate API documentation for the application and put it somewhere
Run a test coverage report
Now, we have just about all of this in one form or another. But, it'd be nice to have it all automated and bundled together in one process.
phing is pretty much ant written in PHP where phpUnderControl adds support for PHP projects to CruiseControl and uses phing or ant on the backend to parse the build.xml file and run commands.
I just set up CruiseControl and phpUnderControl and it's been working great. It checks out my SVN, runs it through phpDocumentor, PHP_CodeSniffer, and PHPUnit whenever we do a check in. Since it's all based off of the build.xml file you can run just about any software you want through it.
I'm sure lots of people will say this by the time I've typed this but...
I know it's not PHP but we're finding Capistrano just the job for this kind of thing. It really is an excellent piece of software.
We've been using Phing, and the cost to set it up has been very low; it's really easy to learn even if you don't know ANT. I've had very bad experiences with CruiseControl (instability - going down randomly) - so I like the simplicity of Phing. Plus, it's easily extensible using PHP (in case you have a custom task that they don't support out of the box).