What's the ideal way of deploying CodeIgniter projects (or any PHP projects for that matter) from your local machines to the live site? I've been using subversion for checking out and updating the code from live sites for quite some time now. But there are others who say that this practice is not good since you do not need the svn metadata in the live site. I've also read a couple of articles where they use Capitrano to deploy PHP projects. What's your practice in PHP project deployment?
I use Phing for all my building needs.
I've created several tasks like, prod, staging, debug. When i want to push all data to my production server, i just use phing prod. This will checkout all code from my repo, do some config changes, run all static files like css and javascript through a minifier etc.
More info on Phing here:
Phing.info
http://www.slideshare.net/hozn/phing-building-with-php
I asked a similar question and a lot of people seemed to like Phing:
What is your preferred php deployment strategy?
I took a look at it and the config files were pretty intimidating. I'm interested to hear more on this subject.
Related
Good day to you all,
I am currently developing a project on Laravel. So far I have always developed online, directly editing my files on the webserver throuh FTP (using PSPad or similar simple editing tools).
What I want to do now (and what i believe most people actually do) is setup a (W)LAMP stack on my local machine and program locally. However it is a little bit unclear to me how to keep my local code (including databases) in sync with the live website. How do you folks do that? I know there's probably lots of ways and tools to do that, but what would be your advice for a best practice? Any advice would be very welcome :)
What many companies do is build offline, then push their edits up to a server using git.
Im no expert on the software so ill describe what you do in a basic form:
My advice would be to create an online repo (repository) to store your project while you edit/update.
There are several git project management systems such as github or bitbucket. I personally use bitbucket
What git does, is when you have built or added what you need offline on local (w)lamp, you then git push them up to your repo or server. The changed files then get merged with the existing on the repo or the server. If you'd like the most recent version of your project you'd simply just git pull them down.
Read the full documentation here to see the wide range of options available when using git
We have a settings array within our platform available as $res::Config.
At runtime, a variable is changed from 'dev' to 'live' after checking the HTTP Host, obviously depending on the IP address.
Within our framework bootstrapping, depending on the value of $res::Config->$env, or the environment set previously as either dev or live, the settings for the database connection are set. You store these settings in the Config array as db_live or db_dev.
However you do it, use an environmental variable to figure out whether you want live or dev, and set up and array of settings accordingly.
We also have sandbox and staging for intermittent development stages.
As for version control, use git or subversion.
Edit: It's also possible that within our vhost file, we setup an environmental variable as either live or dev, and our application reads from this accordingly. I'd suggest this approach :)
There are a number of ways of doing this. But this is a deceptively HUGE question you've asked.
Here is some good practice advice - go and research these items, then have a look at my approach.
Typically you use a precess called version control which allows you to create "versions" or snapshots of your system.
The commonly used "SVN" software is good, but the new (not really any more) kid on the block is GIT, and I personally recommend that.
You can use this system to push the codebase live in a controlled fashion. While the files/upload feature is essentially similar to FTP, it allows you to dump a specific version of your site live.
In environments where there are multiple developers, this is ideal - you can compare/test and work around each other, and version control tends to stop errors between devs.
So - advice part 1: Look up and understand version control, then use it to release CODE to the live environment.
Part 2: I use database dumps and farm them back to my machine to work with.
If the live database needs updating, I can work locally and simply export, then re-import on the live system.
For example: on a recent Moodle project I worked on, to refresh the whole database took seconds... I could push a patch and database update in a few minutes.
However: you should think about maintenance and scheduling... if the site is live and has ongoing data changes then you need to be careful with this. Consider adding a maintenance page.
Advice 2: go research SQL dump/export and importing.
I personally use phpmyadmin to dump and re-import, as it's very convenient.
Advice 3: Working locally then pushing live is MUCH BETTER PRACTICE. You're starting down a much safer and better road than you're on!
Hope that helps... but bear in mind - this is a big subject, so you'll need to research a fair bit.
I need to know which are my options when deploying codeigniter/laravel apps.
I develop locally all the time at my home and when i go to work i need some quick way to push all the changes to the server.
Application code needs to be updated, database schemas need to be migrated, and application servers must be restarted.
I do all of this manually wasting a lot of time and i need some automated way kinda like capistrano in Rails environment.
What are my options here ??
Update:
I got my own server machine, and everything needs to work on an intranet environment without internet connection.
I've used the following:
Salt - http://www.saltstack.org/
Worked well, a bit fiddly to setup. Super fast deployment. Lots of control. Less learning overhead that Puppet & Chef, has some level of native MySQL tools.
GitHub
Requires a internet connection to/from your machine - one where, at some level, the end point as write permissions to interactive scripts.... Works, but makes me nervous. Pulls are better than pushes, and it's better than most other solutions.
Custom shell scripting
Yeah - this is the most common, just tar up the entire CI dir once it's been validated on staging and push out using Salt...
Scalextreme
We've been looking at this for a few months - the interface is from the 1990's, but it's got really nice functionality, including system-independent script library that you can target at any machine.
Turnkey Linux
The hammer - this will migrate an entire system image from a desktop to EC2 is something like 5 minutes. Works great and you can also move stuff between VM systems. In the end, I think that updating AMI's on EC2 is so easy that this might be one of the answers...
Nothing has truly been satisfactory and DB schema changes are a huge pain. So much so that for client configs, we're moving from MySQL to Cassandra, which is basically schemaless. CI installer is interesting, but I'm not sure how it handles updates.
I recently came across this CodeIgniter Installer on GitHub. I've played around with it a few times and it works like a charm for me.
It's as simple as putting it in your root directory (alongside your system folder), generating a MySQL dump, and editing a few files. Full instructions are here
I hope it works for you as well as it did for me.
I found this Laravel Installer on Github which might be useful. (First I came across this question after searching for Laravel installer in Google, then searched Github for Laravel Installer)
Hello
I am not super experienced with PHP and large projects using it, most of my tinkering around has been in Rails with EngineYard (life seemed simpler back then). But in PHP, I haven't found anything that comes really well integrated with GitHub right out of the box. So I am looking for an easy solution to deployment for now and hopefully setting the stage for continuous integration in the future when I get around to writing the tests and such.
Here's what I have so far:
GitHub repo with my codebase
Alpha version of the app in CodeIgniter in PHP
Run of the mill webhost account with Site5 for staging/development
Currently, I deploy by uploading the latest batch of code via FTP onto my site.
For one, I would like to get to a one-step deployment process. Just a simple git push would do the trick. Is Phing overkill for now?
What are the steps you might recommend as best practices?
Thank you.
I recommend creating deploy script(s), especially at the beginning. It's a lot easier to start working on them since there are not that many things to do. Not to mention running a single deploy command is easier than doing all the steps manually. Even for small projects. Projects tend to complicate the deployment with time.
If it helps, we are currently using ANT (well, switching), we have dropped Phing due to not being developed/maintained anymore.
I use Beanstalk, and they have great deployment methods available. Once you commit, you can set up auto deployment settings, with a simple click.
I use Git to track local changes in my PHP web applications, and I was wondering if it would be a good idea to use Git on the server as well, so that I could just use git push to deploy my changes. Would there be any pitfalls with this approach?
This seems like a nice way to do things. If you're tagging and branching properly it will enable you to quickly switch back to working versions of your site too in the event that something breaks.
I think this is a fine way to do it. I handle things in a similar manner, where live sites are just a checkout from the repository, and i update them as necessary.
Git is fine but you can do a lot better then just using git pull. Take a look at railess deploy for capistrano.
Capistrano basically does a combination of rsync and git pull to deploy copies of your website. It supports roleback, staging and distributed deployments.
And online hotfixes can be pushed back to development.
Being able to do a git status on a live system can be a live saver.
Go for it!
Caveats
Make sure the the ".git" folder isn't accessible from the web.
With PHP the source code is usually present on the webserver, so that doesn't add additional risk in case the server is hacked.
I would be in favor of using a technique like this if only because you can be sure anything on your deployed site is also being tracked in git. That is, it encourages a best practice and discourages ad hoc changes that aren't under source control.
For another alternative, check out this article about how Twitter uses BitTorrent to manage deployment: http://torrentfreak.com/twitter-uses-bittorrent-for-server-deployment-100210/
It's probably most useful when you need to deploy quickly across a large collection of servers.
I think its a great solution. I have been using it to deploy my website for a long time... Its nice because you can almost instantly push your changes into production just by updating the folder. I have encountered no security issues or anything with it.
Enjoy!
What would be a good tool-for-the-job to do automated deployments of LAMP-based applications(MySQL, PHP, Zend Framework) to integration and staging environments?
I am looking specifically for tools that handle deployes to remote hosts. I assume building tools such as phing and ant I assume could be used for that, but I was wondering if there is something better for this case.
For integration, especially for continuous integration, I like phpUnderControl (which is a tool for PHP projects, but is itself based on CruiseControl, which is quite know in the JAVA World) : it deals with :
fetching the last revision from SVN
launching the automated tests (PHPUnit)
php_CodeSniffer
Generation of the PHP Documentation (phpDocumentor)
and provides a nice interface for users to see the results of each build.
And, to begin, here's an article that explains how to set phpUnderControl up : Getting started with phpUnderControl
(Each time I, or some colleagues, have installed phpuc, we did almost as explained in that article, from what I remember)
For staging, I generally go with a couple of phing tasks to build a tar.gz archive, that I deploy to the staging server once in a while, using another phing task to un-tar the archive, and create the required symlinks (or stuff like that).
The idea being that Continuous Integration happens all the time, and has to be fully automatic, while deploying to staging is done only one in a while (once per week, for instance), and can be done semi-automatically.
Configure a build server, something like CruiseControl is excellent for this and roll your own custom Nant scripts if needed or use Exec tasks to take care of the deployment.
For these things like specific deployments each with their configuration issues and intricacies, there is hardly ever something out-of-the-box.
Look at it this way, rolling your own scripts and batch files definitely means you know all about the steps and can configure and modify it anyway you like, rather than some magic fairy dust going on, and when things break - having no idea where to fix it.