1. 程式人生 > >rpmbuild打包php

rpmbuild打包php

安裝php依賴庫

mkdir -pv ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

php有一個依賴庫,在yum源於epel源中都沒有需要自己打包libiconv

編寫libiconv spec檔案

%define __os_install_post %{nil}
%define debug_package %{nil}
Name: libiconv
Version: 1.15
Release: 1%{?dist}
Summary: liconv
Group: liconv
License: GPL
URL: http://www.test.net
Packager: test
Vendor: test
Source0: libiconv-1.15.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
%description 
iconv

%prep
%setup -q

%build
./configure --prefix=/usr/share/libiconv-1.15 \

make

%install
make install DESTDIR=%{buildroot}


%files
%defattr(-,root,root,-)
%attr(0655,root,root) /usr/share/libiconv-1.15/*
%attr(0755,root,root) /usr/share/libiconv-1.15/bin/*


%clean
rm -rf $RPM_BUILD_DIR/%{name}-%{version}

%post
ln -sv /usr/share/libiconv-1.15/ /usr/share/libiconv

%changelog
* Sun Aug 24 2018 LC 1.15-1
- package libiconv-1.15

編寫php spec檔案

Name: php
Version: 7.1.17
Release: 1%{?dist}
Summary: php
Group: php
License: GPL
URL: http://php.org
Packager: php
Vendor: php
Source0: php-7.1.17.tar.bz2
Source1: php.ini
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
Requires: libiconv,zlib-devel,libxml2-devel,libjpeg-devel,libjpeg-turbo-devel,freetype-devel,libpng-devel,gd-devel,curl-devel,libxslt-devel,bzip2-devel,gmp-devel,readline-devel,mcrypt,mhash,libmcrypt-devel
%description 
php

%prep
id nginx || useradd nginx -s /sbin/nologin -M
%setup -q

%build
./configure \
--prefix=/usr/share/php-7.1.17 \
--with-config-file-path=/etc/php/ \
--exec-prefix=/usr \
--bindir=/usr/bin \
--sbindir=/usr/sbin \
--mandir=/usr/share/man \
--sysconfdir=/etc/php/ \
--with-mysqli=mysqlnd \
--with-iconv-dir=/usr/share/libiconv \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx 

make -j 4

%install
rm -rf %{buildroot}
make INSTALL_ROOT=%{buildroot} install
%{__install} -p -D %{SOURCE1} %{buildroot}/etc/php/php.ini

%files
%defattr(-,root,root,-)
/usr/share/php-7.1.17/*
%attr(0744,root,root) /usr/bin/*
%attr(0744,root,root) /usr/sbin/*
/usr/share/man/*
/etc/php/*


%pre
id nginx || useradd nginx -s /sbin/nologin -M

%post
cp /etc/php/php-fpm.conf.default /etc/php/php-fpm.conf
cp /etc/php/php-fpm.d/www.conf.default /etc/php/php-fpm.d/www.conf

%postun
userdel nginx

%changelog
* Sun Aug 10 2018 lc lc
- package php-7.1.71

構建PHP RPM包遇到的問題

RPM build errors:
    bogus date in %changelog: Sun Aug 10 2018 lc zhoushilong
    Explicit %attr() mode not applicaple to symlink: /root/rpmbuild/BUILDROOT/php-7.1.17-1.el7.centos.x86_64/usr/bin/phar
    Installed (but unpackaged) file(s) found:
   /.channels/.alias/pear.txt
   /.channels/.alias/pecl.txt
   /.channels/.alias/phpdocs.txt
   /.channels/__uri.reg
   /.channels/doc.php.net.reg
   /.channels/pear.php.net.reg
   /.channels/pecl.php.net.reg
   /.depdb
   /.depdblock
   /.filemap
   /.lock

解決方法如下:

方法1
生成的rpm包裡有前面在%files裡新增的這個檔案,如下:

/usr/local/php/.channels

方法二,下面是直接刪除的解決辦法,實踐OK(視具體情況是刪除還是新增選一個即可):

rm -rf %{buildroot}/{.channels,.depdb,.depdblock,.filemap,.lock} 

方法三,/usr/lib/rpm/macros修改巨集

# 構建根目錄中的未打包檔案是否應終止構建?
%_unpackaged_files_terminate_build 1 # 把1改為0只警告

%__check_files   %{_rpmconfigdir}/check-files %{buildroot} # 這一行,把這一行註釋掉,然後重新編譯