Home Wiki > User:Aeneas jaissle/PHP
Sign up | Login

User:Aeneas jaissle/PHP

tagline: From openSUSE


Packaging PHP is an introduction on how to build PHP software packages for openSUSE and others using the openSUSE Build Service. It is also a guideline on accepted standards and current practices in doing so.

Why provide software packages for PHP?

  • Deployment
  • Updates
  • Security

General Information

Each package consists of

  • at least one specification file (.spec)
  • one .changes file for every .spec
  • Some source file

PHP

"PHP is a popular general-purpose scripting language that is especially suited to web development."

SLE/openSUSE releasePHP release
SUSE:SLE-11:SP3PHP 5.3.x
SUSE:SLE-11:SP4PHP 5.3.x
SUSE:SLE-12:GAPHP 5.5.x
SUSE:SLE-12:SP1PHP 5.?.x
openSUSE:13.1PHP 5.4.x
openSUSE:13.2PHP 5.6.x
openSUSE:Leap:42.1PHP 5.?.x
openSUSE:TumbleweedPHP 5.6.x

Updated: 2015-09-16 12:45 UTC


Frameworks and Libraries

  • OBS project: server:php:applications

Frameworks and libraries put their content into /usr/share/php5/%{name}

A typical spec file should look like this:

#
# spec file for package roundcube-framework
#
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           roundcube-framework
Version:        1.1.3
Release:        0
Summary:        Basic library used for the Roundcube Webmail application
License:        GPL-3.0+ 
Group:          Productivity/Networking/Email/Clients

Url:            http://www.roundcube.net/
Source0:        %{name}-%{version}.tar.gz

BuildArch:      noarch
BuildRequires:  fdupes
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

Requires:       php-pear-Auth_SASL >= 1.0.6
Requires:       php-pear-Mail_Mime >= 1.8.1
Requires:       php-pear-Net_IDNA2 >= 0.1.1
Requires:       php-pear-Net_SMTP

Recommends:     php-mysql
Recommends:     php5-intl
Recommends:     php5-fileinfo

%description
The Roundcube Framework is the basic library used for the Roundcube Webmail
application. It is an extract of classes providing the core functionality for
an email system.


%package -n %{name}-doc
Summary:          Documenation for roundcube-framework
Group:            Documentation/HTML

%description -n %{name}-doc
The Roundcube Framework is the basic library used for the Roundcube Webmail
application. It is an extract of classes providing the core functionality for
an email system.

This package provides the documentation for roundcube-framework.


%prep
%setup -q

%build

%install
# install roundcube-framework
%{__install} -d -m 0755 %{buildroot}%{_datadir}/php5/Roundcube
cp -a * %{buildroot}%{_datadir}/php5/Roundcube

# install docs
%{__install} -d -m 0755 %{buildroot}%{_defaultdocdir}/%{name}
cp %{buildroot}%{_datadir}/php5/Roundcube/README.md %{buildroot}%{_defaultdocdir}/%{name}/
%{__install} -d -m 0755 %{buildroot}%{_defaultdocdir}/%{name}-doc
for i in README.md doc; do
    mv -v %{buildroot}%{_datadir}/php5/Roundcube/$i %{buildroot}%{_defaultdocdir}/%{name}-doc/
done

# fdupes
%fdupes %{buildroot}%{_defaultdocdir}/%{name}-doc/

%files
%defattr(0644, root, root,0755)
%doc README.md
%dir %{_datadir}/php5
%{_datadir}/php5/Roundcube/

%files -n %{name}-doc
%defattr(0644, root, root,0755)
%doc README.md
%doc doc/

%changelog

Web Applications

  • OBS project: server:php:applications
  •  %{name} (e.g. roundcubemail)

Web applications packaged in openSUSE should put their content into /srv/www/%{name} and NOT into /var/www. This is done because:

  • /var is supposed to contain variable data files and logs. /srv/www is much more appropriate for this.
  • Users may already have content in /var/www, and we do not want any openSUSE package to step on top of that.
  • /var/www is no longer specified by the Filesystem Hierarchy Standard.

Please do not use /srv/www/htdocs!

A typical spec file should look like this:

#
# spec file for package roundcube-framework
#
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           roundcube-framework
Version:        1.1.3
Release:        0
Summary:        Basic library used for the Roundcube Webmail application
License:        GPL-3.0+ 
Group:          Productivity/Networking/Email/Clients

Url:            http://www.roundcube.net/
Source0:        %{name}-%{version}.tar.gz

BuildArch:      noarch
BuildRequires:  fdupes
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

Requires:       php-pear-Auth_SASL >= 1.0.6
Requires:       php-pear-Mail_Mime >= 1.8.1
Requires:       php-pear-Net_IDNA2 >= 0.1.1
Requires:       php-pear-Net_SMTP

Recommends:     php-mysql
Recommends:     php5-intl
Recommends:     php5-fileinfo

%description
The Roundcube Framework is the basic library used for the Roundcube Webmail
application. It is an extract of classes providing the core functionality for
an email system.

%package -n %{name}-doc
Summary:          Documenation for roundcube-framework
Group:            Documentation/HTML

%description -n %{name}-doc
The Roundcube Framework is the basic library used for the Roundcube Webmail
application. It is an extract of classes providing the core functionality for
an email system.

This package provides the documentation for roundcube-framework.


%prep
%setup -q

%build

%install
# install roundcube-framework
%{__install} -d -m 0755 %{buildroot}%{_datadir}/php5/Roundcube
cp -a * %{buildroot}%{_datadir}/php5/Roundcube

# install docs
%{__install} -d -m 0755 %{buildroot}%{_defaultdocdir}/%{name}
cp %{buildroot}%{_datadir}/php5/Roundcube/README.md %{buildroot}%{_defaultdocdir}/%{name}/
%{__install} -d -m 0755 %{buildroot}%{_defaultdocdir}/%{name}-doc
for i in README.md doc; do
    mv -v %{buildroot}%{_datadir}/php5/Roundcube/$i %{buildroot}%{_defaultdocdir}/%{name}-doc/
done

# fdupes
%fdupes %{buildroot}%{_defaultdocdir}/%{name}-doc/

%files
%defattr(0644, root, root,0755)
%doc README.md
%dir %{_datadir}/php5
%{_datadir}/php5/Roundcube/

%files -n %{name}-doc
%defattr(0644, root, root,0755)
%doc README.md
%doc doc/

%changelog


Composer

Composer is a Dependency Manager for PHP

  • We want to let Composer know of installed RPM packages that have a composer dependency file (composer.json).

PEAR

PHP Extension and Application Repository

Packaging a PEAR package

Name schema: php5-pear-%{pearname} (e.g. php5-pear-Net_SMTP)

  • tests -> don't include. If needed, create a sub package *-tests
  • doc -> move all to %_docdir
  • examples -> move to %_docdir as well

How to handle these:

/usr/bin/php-shell.sh
/usr/share/php5/PEAR/php-shell-cmd.php
/usr/share/php5/PEAR/PHP/Shell.php

Provides/Obsoletes:

Name:           php5-pear-%{pear_name}
Provides:       php-pear-%{pear_name}   = %{version}
Provides:       php-pear(%{pear_name})  = %{version}
Obsoletes:      php-pear-%{pear_name}   < %{version}
Obsoletes:      php-pear(%{pear_name})  < %{version}


A typical spec file should look like this:

#
# spec file for package php5-pear-Crypt_GPG
#
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           php5-pear-Crypt_GPG
%define pear_name  Crypt_GPG
Summary:        PHP interface to GnuPG
Version:        1.4.0b4
Release:        0
License:        LGPL-2.1
Group:          Development/Libraries/PHP
Url:            http://pear.php.net/package/%{pear_name}
Source:         http://download.pear.php.net/package/%{pear_name}-%{version}.tgz

BuildArch:      noarch
BuildRequires:  php-devel >= 5.2.1
BuildRequires:  php-pear >= 1.4.0
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

#Dependencies:
# It requires the GnuPG executable to be on the system.
#    PHP Version: PHP 5.2.1 or newer
#    PEAR Package: PEAR Installer 1.4.0 or newer
#    PEAR Package: Console_CommandLine 1.1.10 or newer
#    PHP Extension: mbstring
#    Operating System: windows (conflicts with some versions)
#    PHP Extension: posix (optional)

Requires:       php >= 5.2.1
Requires:       php-mbstring
Requires:       php-pear >= 1.4.0
Requires:       php-pear-Console_CommandLine >= 1.1.10
Suggests:       php-posix

Provides:       php-pear-%{pear_name}   = %{version}
Provides:       php-pear(%{pear_name})  = %{version}
Obsoletes:      php-pear-%{pear_name}   < %{version}
Obsoletes:      php-pear(%{pear_name})  < %{version}

%description
This package provides an object oriented interface to GNU Privacy Guard (GnuPG). It requires the GnuPG executable to be on the system.

Though GnuPG can support symmetric-key cryptography, this package is intended only to facilitate public-key cryptography.


%prep
%setup -c

%build

%install
%{__mv} package*.xml %{pear_name}-%{version}
cd %{pear_name}-%{version}

PHP_PEAR_PHP_BIN="$(which php) -d memory_limit=50m"
%{__pear} -v \
        -d bin_dir=%{_bindir} \
        -d doc_dir=%{php_peardir}/doc \
        -d data_dir=%{php_peardir}/data \
        -d test_dir=%{php_peardir}/tests \
        install --offline --nodeps -P "%{buildroot}" package.xml

%{__install} -D -m 0644 package.xml %{buildroot}%{php_pearxmldir}/%{pear_name}.xml

cd ..

# We don't pack tests, remove cruft, move docs into %%_docdir
%{__mkdir_p} doc/
%{__mv} %{buildroot}%{php_peardir}/doc/%{pear_name}/* doc/
%{__rm} -rf %{buildroot}%{php_peardir}/{doc,tests}
%{__rm} -rf %{buildroot}%{php_peardir}/.{filemap,lock,registry,channels,depdb,depdblock}

%php_pear_gen_filelist

%post
# 1 == install
if [ "$1" = "1" ]; then
  %{__pear} install --nodeps --soft --force --register-only %{php_pearxmldir}/%{pear_name}.xml
fi
# 2 == upgrade
if [ "$1" = "2" ]; then
  %{__pear} upgrade --offline --register-only %{php_pearxmldir}/%{pear_name}.xml
fi

%postun
# 0 == uninstall
if [ "$1" = "0" ]; then
  %{__pear} uninstall --nodeps --ignore-errors --register-only pear.php.net/%{pear_name}
fi

%files -f %{name}.files
%defattr(-, root, root)
%doc doc/*
%{_bindir}/crypt-gpg-pinentry

%changelog

Packaging a PEAR channel

Name schema: php5-pear-channel-%{channelname}

A typical spec file should look like this:

%define peardir %(pear config-get php_dir 2> /dev/null || echo %{_datadir}/pear)
%define pear_xmldir  /var/lib/pear

Name:           php5-pear-channel-horde
Version:        1.0
Release:        0
Summary:        Adds pear.horde.org channel to PEAR
Group:          Development/Libraries/PHP
License:        BSD-3-Clause
Url:            http://pear.horde.org/
Source0:        http://pear.horde.org/channel.xml
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch
Requires:       php php5-pear
Requires:       php5-tokenizer
BuildRequires:  php5-tokenizer
BuildRequires:  php5-pear >= 5.1.1

%description
This package adds the pear.horde.org channel which allows PEAR packages
from this channel to be installed.


%prep
%setup -q -c -T

%build
# Empty build section, nothing to build

%install
%{__mkdir_p} %{buildroot}%{pear_xmldir}
%{__install} -pm 644 %{SOURCE0} %{buildroot}%{pear_xmldir}/pear.horde.org.xml

%post
if [ $1 -eq  1 ] ; then
   pear channel-add %{pear_xmldir}/pear.horde.org.xml > /dev/null || :
else
   pear channel-update %{pear_xmldir}/pear.horde.org.xml > /dev/null ||:
fi

%postun
if [ $1 -eq 0 ] ; then
   pear channel-delete pear.horde.org.xml > /dev/null || :
fi

%files
%defattr(-,root,root,-)
%{pear_xmldir}/pear.horde.org.xml

%changelog

PECL

PHP Extension Community Library

Naming: php5-pecl-%{pecl_name}


Aeneas jaissle/PHP #Category:Packaging documentation