We have just launched a new website which being deploy exactly from our development server. There are constant changes on the source code where our programmer always need to do some debugging stuff which being reported from our users. The problem I face frequently is every time they want to sync the new PHP code, I need to manually sync the file for them. My boss do not allow anyone except him to have FTP access to the server.
I am using rsync to do the file syncing from development server to the live server. Both servers are having identical file path for the PHP code, which means in production server, the Apache document root is /home/mywebs/public_html as well as development server. So I need a tool to help me solve this problem. Instead of me doing this for them, why dont they sync the files to the live server by themselves?
In order to achieve this, I will be using rsync with Webmin and Usermin, a web-based interface for system administration for Unix. Both servers run CentOS 6.2 64bit. My server architecture and variable is as below:
Notes: All steps below should be completed in the development (source) server. No need to setup anything on the production (target) server.
1. Download and install Webmin:
$ cd /usr/local/src $ wget http://prdownloads.sourceforge.net/webadmin/webmin-1.590-1.noarch.rpm $ rpm -Uhv webmin-1.590-1.noarch.rpm
2. Download and install Usermin:
$ cd /usr/local/src $ wget http://cdnetworks-kr-1.dl.sourceforge.net/project/webadmin/usermin/1.510/usermin-1.510-1.noarch.rpm $ rpm -Uhv usermin-1.510-1.noarch.rpm
3. Install rsync using yum:
$ yum install -y rsync
4. Open Webmin, Usermin and rsync ports in iptables. Open iptables and add following lines at /etc/sysconfig/iptables using text editor before any REJECT rules:
-A INPUT -p tcp -m tcp --dport 10000 -j ACCEPT -A INPUT -p tcp -m tcp --dport 20000 -j ACCEPT -A INPUT -p tcp -m tcp --dport 873 -j ACCEPT
5. Save and restart iptables:
$ service iptables restart
6. Open Webmin using web browser. In my setup, I will use this URL http://18.104.22.168:10000. Login as root user and navigate to Webmin > Others > Custom Commands > Create a new custom command.
7. Add required information as highlighted below:
8. Now we need to create a user to be used by programmer team. Go to Webmin > Webmin Users > Create a new Webmin user.
Under “Available Webmin modules” section, tick for the “Custom Commands” as screen shot below:
9. Edit the user again. We just want them to choose files under /home/mywebs directory. Go to Webmin > Webmin Users > choose user ‘developer’ > Permissions for all modules and choose as below:
10. Lets create user developer. Go to Webmin > System > Users and Groups > Create a new user and fill up required information as screenshot below:
11. Now as for the last step, we need to setup shared SSH keys between these 2 servers so the rsync can be executed without user mywebs’s password authentication in destination server:
$ su - mywebs $ ssh-keygen -t dsa # just press enter for all questions $ ssh-copy-id -i ~/.ssh/id_dsa firstname.lastname@example.org
Done. Now ask your developer to access to Usermin at http://22.214.171.124:20000 and go to Usermin > Others > Custom Commands. The rsync script that we have create before is now available for the developer. They can use this features to sync the file to live server whenever they want: