We just got new servers for our new system and I want to know what I should do to make my new code as efficient as possible, and how to organize it.
I want a good solution so I don't have to reorganize it one year from now on (for example) and I want the best practices and techniques to make sure my code will survive long enough to avoid redesigning it later. no framework use here
Here's my new environment:
My idea was to mirror them (the web servers) and then push the code from the SVN to all servers. Is this good?
Click Servers > Server types > PHP servers. Select the servers that you chose as deployment targets, and click Start. You can also start the application from Applications > All applications in the administrative console. However, doing so from this panel will start all the servers associated with this application.
Deployer is a PHP cli application which can deploy your PHP application over multiple protocols, SSH being widely used. After installation, a separate project specific deploy. php file is used to deploy the application from the Git repository to server via command line.
You can centralize your code in one common folder (either create a script that copies all the code to the eight servers or use NFS).
This centralized code can be in one or more repositories in your SVN installation. So when you push, you only push what you need to push.
For example, you can create one repository for your own PHP libraries (database class, XML, IMAP, etc.). In a simple structure and when you call these files, you simply do:
require('/web/lib/DatabaseMySQL.class.php');
This way, you know all your required files at in the same place and very easy to maintain. Specially if your code requires required files that requires files.
You can create as many repository as you want and repeat this if you don't want to mix up files - for example third-party (Smarty, PHPMailer) with the code you create.
The other thing is, don't reinvent the wheel. There's plenty of good code out there that probably do what you already need to do. Like sending email (PHPMailer or any others) or template system (Smarty or any others). This way you same development time and when an update if available, you simply download, copy (commit if you have it in a repository) and push.
Script VS NFS.
Create a script to push all your code in eight web servers is easy to make. The downside of this is you need to make sure all the folders and all the files you have on each servers are identical in order to avoid errors.
Also, if there's a lag on your network or the connection drop during the push some server won't have the same code. Again, more errors. This is a little faster to run versus the NFS solution.
Createing an NFS fixes the problem above since you only use one location, but if that location drops, all of your servers won't run correctly. So, when you push the code, you push only to one place and all the other servers automatically have the new code. Something you need to know also: this will be a little slower than if the code is directly on the hard drive.
Here's a sample script you can use:
You can create a .sh script that will copy the code from your repository (for example, code you checked out from the repository) to all server like this:
// file: pushcode.sh
#!/bin/bash
/usr/bin/rsync -avz --exclude='.svn' -e ssh /path/to/code/checkedout/ user@server1:/path/to/code
/usr/bin/rsync -avz --exclude='.svn' -e ssh /path/to/code/checkedout/ user@server2:/path/to/code
Make this script executable and run it:
./pushcode.sh
To make sure the code copy correctly without prompting the password each time, you will have to bypass the SSH login.
Here's a good one you might like: https://serverfault.com/questions/195035/linux-nfs-performance-vs-other-file-systems
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With