PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

RPM Packaging - Building and Deploying your own PHP

Note: This article was originally published at Planet PHP on 19 April 6040.
Planet PHP

I've been building all sorts of RPM's lately, from vim 7.3 to mirroring the zend server repository and building pecl extensions. In the PHP world, one might ask why not just build it from source? Well, an RPM IS built from source and then distributed to many servers - we can ensure that we have the same packages on each, we can maintain the same versions and if you've read my previous post on Pirum you will know that I also like mirroring PEAR packages. It allows us to simply maintain our versions on each server and lower the maintenance in a larger environment. Not to mention, since it is on the inside of our network, it is insanely quick for the downloading of the packages and maintaining our servers.

If you are not doing packaging, I hope this entices you to start doing some packaging. I will show you an example of building a PHP RPM based on the distribution (as it is actually how I ensure this server is versioned appropriately and I don't lose my build from source scripts). Oh; and I've only been promising this blog post for approximately 6+ months - so those expecting it; here it is!

Overview

To build an RPM is fairly easy, however, there are a few tools that you will need in order to build everything out:

  • rpmbuild
  • rpm-devel
  • rpm-libs

Once you have these packages, you have everything that you will need to start building out your package.

The Mechanics of a Package

There are a few parts of an RPM package that you will need to know in order to build it.

  • A Specification File
  • The Source

The specification file will explain to the rpmbuild utility how we are going to be building out the package and the source is what we are going to be building from. Pretty plain and simple, right?

Specification File

When we are building out an RPM specification file, there are many components that we need to think through as well as a large amount of macros. We will be avoiding many of the macros as they do sometimes change the path as to where we may be installing from. Let's start with the full spec file and we will explain from there. This file needs to be in ao/usr/src/redhat/SPECSa.

Name: php Version: 5.3.8 Release: 1%{?dist} Summary: PHP is a widely-used general-purpose scripting language. Group: Development/Languages License: PHP License v3.01 URL: http://www.php.net Source0: http://www.php.net/distributions/php-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot Obsoletes: php %description PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into html. %prep %setup -q -n %{name}-%{version} %build EXTENSION_DIR=%{_libdir}/php/modules; export EXTENSION_DIR %configure --with-layout=GNU --with-libdir=lib64 --with-enchant \ --enable-fpm --with-gd --enable-intl --enable-mbstring --enable-pcntl \ --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-zip --with-zlib \ --with-curl --with-jpeg-dir --with-png-dir --with-zlib-dir --with-gettext \ --with-mcrypt --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \ --with-pdo-sqlite --with-tidy --with-pear=%{_datadir}/php/pear --disable-debug make %{?_smp_mflags} %install rm -rf %{buildroot} mkdir -p %{buildroot}%{_initrddir} install -Dp -m0755 sapi/fpm/init.d.php-fpm.in %{buildroot}%{_initrddir}/php-fpm %{__make} install INSTALL_ROOT="%{buildroot}" %clean rm -rf %{buildroot} %post %/sbin/chkconfig --add php-fpm %/sbin/chkconfig --level 2345 php-fpm on %preun if [ "$1" = 0 ] ; then /sbin/service php-fpm stop /dev/null 2&1 /sbin/chkconfig --del php-fpm fi exit 0 %postun if [ "$1" -ge 1 ]; then /sbin/service php-fpm condrestart /dev/null 2&1 fi exit 0 %files %defattr(-,root,root,-) %{_bindir}/* %{_sbindir}/* %{_includedir}/* %{_libdir}/* %{_mandir}/man1/php* %{_sysconfdir}/* %{_datadir}/* %{_initrddir}/* %exclude /.channels %exclude /.depdb %exclude /.depdblock %exclude /.filemap %exclude /.lock %changelog * Wed Dec 21 2011 Mike Willbanks - 5.3.8-1 - Updated to 5.3.8 * Tue Feb 23 2011 Mike Willbanks - 5.3.5-1 - Initial Package

The Header

Name: php Version: 5.3.8 Release: 1%{?dist} Summary: PHP is a widely-used general-purpose scripting language. Group: Development/Languages License: PHP License v3.01 URL: http://www.php.net Source0: http://www.php.net/distributions/php-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot Obsoletes: php %description PHP is a widely

Truncated by Planet PHP, read more at the original (another 5824 bytes)