RSS
 

Archive for the ‘Howto’ Category

Application Deployment – web and other with php-packager

30 May

Introduction

Deployment of applications on a server is always an issue for developers of applications that need to be installed in some way. Applications like this include specifically web applications built with or on top of Drupal, SilverStripe, Symfony or other PHP web application frameworks. But this is not limited to PHP. Linux server applications can also be Java EE or other JVM applications that run on a server or even C(++), Python, Ruby (on Rails) and any other software. There are usually files that have to be generated or/and copied from a development machine to a test machine and ultimately to a production machine. This process is usually error prone and tedious and needs a lot of documentation. With good documentation this can be reasonably easy, but it is never trivial and humans make mistakes. On top of that one often needs to compile ones own or third party applications and so on, because there is no package for that software yet, because it is far from trivial to roll your own packages. Whether that is a C++ application or a Java application doesn’t really matter. However, we’ve learned that compiling your source code on a production machine is really bad practice, despite it being the easiest way to do things. The main reason for this being bad is that this implies that there is a compiler on a production machine. This is a security risk because if an attacker gains any kind of access to the machine, they can compile their own software on it and run it at their will and possibly compromise the production machine.

However, to compile and/or deploy ones applications there are usually a series of steps that can be bundled into a script. For a while I was using deployment scripts so that I could track a version number within git tags. These deployment scripts were individual to specific applications and never easy to write. Some stuff was generic and other stuff very specific to the application.

PHP-Packager was born

So, I’ve been conversing with my colleague about how we should go about deploying our applications in a repeatable manner. While there are things like Juju, Puppet, Maven, Gradle and so on, we are using mainly Linux as a platform for servers and specifically a Debian based distribution you might have heard of called Ubuntu. As you might know Ubuntu and other Debian based distros (actually also Red Hat/CentOS/Fedora as well) manage their software with packages and ultimately with APT or YUM and the like. For Ubuntu and other Debian based distributions like Linux Mint these are usually .deb packages with dependencies and install/uninstall scripts. For Red Hat based distros, this is usually .rpm.

Finally, we decided to make our own APT repositories for all our VMs, even though we had feared and avoided it in the past. One test and one production repository. Technically, you can make a development repository as well, but for now that would be overkill. For that we needed a mechanism to package and deploy our applications to the repository while still keeping track of versions in our source code repository so we could roll back to a known version. For version control we use Git and for that reason we decided the current Git commit should simply be tagged with the current version over which we have some power, but we don’t want to keep track of every minor version manually.

There is already a solution out there to make packages. It is called FPM, by jordansissel (https://github.com/jordansissel/fpm). It greatly simplifies the process of making packages for all major distributions. However, since I am most comfortable with PHP as a scripting language and not Ruby, Python or even Groovy, I came up with the idea to wrap it with PHP and some little convenience automation, so I don’t have to do the generic stuff. PHP is a powerful, object oriented language and is one of the easier high-level scripting languages. It is itself open source and free and has many other advantages. The name seems to imply that it is only for the web, but apart from the opening <?php tag there is not much more that enforces it to be used only for web apps. It can easily be used from the command line as well.

PHP-Packager or packager for short, is a little script/application that allows for as-easy-as-it-can-get deployment of software via packages. Packages can have dependencies and basically bundle a set of files and scripts triggered by events/actions.

PHP-Packager requires one folder and at least one file within your repository. You can read more details on how to use it on its Github page at https://github.com/geekdenz/packager.

There is more potential for it like more generic tools which one might need in the deployment process, but currently it has the following features:

  1. Package files into a bundled deb or rpm package.
  2. Add after-install and before-remove php scripts for custom procedures like setting up a database for an application or creating symlinks or other files.
  3. Tag your git repository with a version tag. The version is kept track of and can be changed at any time in version.txt in the root of your application’s source code.
  4. Automatically upload the deb or other package to a repository with scp.

There are probably many other things that could be simplified or improved. But this is the current state of this application.

 

SMTP Postfix Server Setup for your home development

18 Mar

EDIT:

This is much easier if not trivial to achieve with your ISP’s smtp server and configuring postfix as a smart host and simply supplying your ISP’s smtp server as the smart host. A simple:

sudo apt-get install postfix

and then configuring you server as a smart host relaying mail to smtp.yourisp.com.

If you already installed postfix, you can follow the following:

Note that You might not want to use dnsexit if security is a concern for you. I stumbled upon this now (28 July 2012) and realised that if you use dnsexit, you are basically giving them your credentials. So, be warned. I used my own server for this.

Source: http://www.dnsexit.com/support/mailrelay/postfix.html

This document describes 5 easy steps to setup your Postfix email server as smarthost to relay on DNS Exit mail relay server for all email sending.

The mail relay service from dnsExit.com can be found at here

1. Create password maps file (it assigns username/passwords to
specified mail servers). You can choose any name, let's say it
is /etc/postfix/relay_passwd. It's content should be as follows:
 relay.dnsexit.com USERNAME:PASSWORD 

 Note: Replace USERNAME and PASSWORD with your DNS EXIT mail
relay username and PASSWORD.   

2. Set proper permissions for that file:
# chown root:root /etc/postfix/relay_passwd
# chmod 600 /etc/postfix/relay_passwd     

3. Create hash from maps file (remember to do it each time
you change your maps file):
#  postmap /etc/postfix/relay_passwd   

4. Configure your /etc/postfix/main.cf:
relayhost = [relay.dnsexit.com]  # this is the important line!
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/relay_passwd
smtp_sasl_security_options =    

Note: If your ISP blocks outgoing port 25. You can choose to
use alternative SMTP ports by appending the port at the end:
relayhost = [relay.dnsexit.com]:26

5. Reload or restart your postfix:
# /etc/init.d/postfix restart

The thing to note here is that you can easily use your ISP’s smtp server as the relayhost. You can find out easily what your ISP’s smtp server is by going to their support pages.

 
2 Comments

Posted in Howto, Linux

 

Howto: Install Apache Tomcat 6 on Ubuntu 11.10

21 Feb
  1. Download Tomcat 6 from http://tomcat.apache.org/download-60.cgi or a mirror listed there.
  2. Extract it in the /usr/local directory:
    cd /usr/local/
    sudo tar xvfz ~/apache-tomcat-6.0.35.tar.gz # or wherever you downloaded tomcat to
    sudo ln -s apache-tomcat-6.0.35 apache-tomcat-6 # or whatever your tomcat version is

This post is incomplete, but might get you going. More docs can be found @ http://www.eclipse.org/forums/index.php/t/272457/

 
No Comments

Posted in Howto, Java, Linux

 

Ubuntu on Asus N53S(V)

08 Oct

To install Ubuntu with a working NVIDIA card on this laptop. Follow these instructions:

  1. Follow https://help.ubuntu.com/community/Asus_N53
  2. Add this to your modules blacklist in /etc/modprobe.d/blacklist.conf:
    blacklist nouveau
    blacklist fbcon
    blacklist vga16fb
  3. Run 3D Graphics intensive applications like Google Earth with
    optirun google-earth
  4. Optional: Mount Windows NTFS partition in /etc/fstab:
    /dev/sda5       /d      ntfs    noexec,nosuid   0       0

Edit: You might not need to add the blacklist. I’ve just setup 11.04 64 bit and did not black list the drivers and it works! Remember to NOT enable the additional drivers in this setup because it will override your Intel Drivers, which are good because you can still run 3D apps but with less power consumption.

 
 

Howto: Solving problem with logrotate

25 Dec
/etc/cron.daily/logrotate:
 
error: error running shared postrotate script for /var/log/mysql.log
/var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log
 
run-parts: /etc/cron.daily/logrotate exited with return code 1

Have you been getting this cryptic error message before?

Here is how to get rid of it:

View /etc/mysql/debian.cnf. Look for

user     = debian-sys-maint
password = newpass

Log into mysql as root

mysql -uroot -p
SET PASSWORD FOR `debian-sys-maint`@`localhost` = PASSWORD('newpass');
SET PASSWORD FOR `debian-sys-maint`@`%` = PASSWORD('newpass');
FLUSH PRIVILEGES;

Log out and it should be fixed.

 
No Comments

Posted in Howto, Linux

 

Howto: Postfix aliases setup email account

25 Dec

Edit /etc/postfix/virtual.cf .

vim /etc/postfix/virtual.cf

Add line:

user@example.com localusername

postmap /etc/postfix/virtual.cf

vim /etc/aliases

Add line:

localusername: someother@othersite.com

newaliases

 
No Comments

Posted in Howto, Linux