Tutorials for making PHP rpm packages

Source: Internet
Author: User
Tags mcrypt rpmbuild value store
Sometimes in order to facilitate the installation of the source package, we need to customize the software package requirements, we will be some source packages according to our needs to make RPM package, when the source package can be directly compiled to get the binary installation package and any other package. Spec file is the most important part of making RPM package, the RPM package is made according to spec file. Here's how I'll start by making php rpm. The following operations are performed on the CentOS6.6 64-bit system.

Let's start by making PHP's RPM introduction to how it's made. The following operations are performed on the CentOS6.6 64-bit system.

Installing Rpm-build

[root@linuxeye.com sources]# yum-y Install Rpm-build



Create a Workshop Catalog

[root@linuxeye.com sources]# vim ~/.rpmmacros%_topdir/root/rpmbuild



[Root@linuxeye.com sources]# MKDIR-PV ~/rpmbuild/{build,rpms,sources,specs,srpms}



Under Redhat, the default production path for RPM packages is under/usr/src/redhat, but CentOS does not have that directory, so we have to customize the working directory, which contains 6 directories (all caps are required)

BUILD: The location of the source code after decompression RPMs: After the completion of the RPM package storage directory, for a specific platform to specify subdirectories (x86_64) SOURCES: Collected source files, source materials, patch files, such as location    SPECS: Store the spec file, As a post file to make RPM package, in RPM name. specsrpms:src format RPM package location, since is the SRC format package, there is no platform concept of           Builtroot: rhizoids, using install temporary installation to this directory, This directory is used as the root, so the directory file under this directory is the real directory file. When the package is complete, the directory will be deleted during the cleanup phase



[root@linuxeye.com sources]# rpmbuild--SHOWRC | grep topdir  #工作车间目录: _topdir/root/rpmbuild-14: _builddir  %{_topdir}/build-14: _buildrootdir      %{_topdir} /BUILDROOT-14: _rpmdir    %{_topdir}/rpms-14: _sourcedir%{_topdir}/sources-14: _specdir   %{_topdir}/SPECS-14: _srcrpmdir%{_topdir}/srpms-14: _topdir    /root/rpmbuild

RPMBUILD–SHOWRC displays all the macros, beginning with an underscore, an underscore: Define the usage of the environment, two underscores: usually define a command, why define a macro, because different systems, the location of the command can be different, so through the definition of macros to find the real location of the command

Collect source File script file

[root@linuxeye.com sources]# pwd/root/rpmbuild/sources[root@linuxeye.com sources]# lsphp-5.4.45.tar.gz

Writing spec Files

[root@linuxeye.com spec]# pwd/root/rpmbuild/sources[root@linuxeye.com spec]# vim php.spec #内容如下:




%define _user www%define _group www%define _prefix/usr/local/phpname:php #软件包名称Version: 5.4.45 #版本号 (cannot use-) release:1%{ ? dist} #release号, corresponding to the following changelog, such as php-5.4.45-1.el6.x86_64.rpmsummary:php is a server-side scripting language for Creati ng Dynamic Web pages #简要描述信息, preferably not more than 50 characters, if you want to detail, use the following%descriptiongroup:development/languages #要全用这里面的一个组: less/usr/ Share/doc/rpm-version/groupslicense:gplv2 #软件授权方式URL: http://www.php.net #源码相关网站Packager: Yeho
 
  
  #打包人的信息Vendor: Oneinstack #发行商或打包组织的信息Source0:%{name}-%{version}.tar.gz #源代码包, can take more than Source1, Source2 and other sources, can also be used after%{ Source1},%{source2} reference buildroot:%_topdir/buildroot #安装或编译时使用的 "virtual directory" Requires:libmcryptRequires:mhashRequires: MCrypt requires:libiconv #定义php依赖的包, yum installation required (Epel source used here)%description #软件包详述PHP is a widely-used general-purpose scriptin G language that's especially suited for Web development and can being embedded into html.%prep #软件编译之前的处理 such as decompression%setup-q #这个 The role of macros in silent mode decompression and Cd%build #开始编译软件%configure--prefix=%{_prefix}--with-config-file-path=%{_prefix}/etc \--with-fpm-user= %{_user}--with-fpm-group=%{_group}--enable-fpm--enable-fileinfo \--with-mysql=mysqlnd--with-mysqli=mysqlnd-- With-pdo-mysql=mysqlnd \--with-iconv-dir=/usr/local--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib \ --WITH-LIBXML-DIR=/USR--enable-xml--disable-rpath--enable-bcmath--enable-shmop--enable-exif \--enable-sysvsem-- Enable-inline-optimization--with-curl--enable-mbregex--enable-inlIne-optimization \--enable-mbstring--with-mcrypt--with-gd--enable-gd-native-ttf--with-openssl \--with-mhash-- Enable-pcntl--enable-sockets--with-xmlrpc--enable-ftp--enable-calendar \--with-gettext--enable-zip--enable-soap --disable-ipv6--disable-debugmake zend_extra_libs= '-liconv '%{?_smp_mflags} #%{?_smp_mflags} %install #开始安装软件, such as Make Installrm-rf%{buildroot}make install_root=%{buildroot} installrm-rf, if you are compiling in parallel on multi-processor. {Buildroot}/{.channels,.depdb,.depdblock,.filemap,.lock,.registry}%{__install}-p-d-M 0755 sapi/fpm/ INIT.D.PHP-FPM%{buildroot}/etc/init.d/php-fpm%{__install}-p-d-M 0644 php.ini-production%{buildroot}/%{_prefix}/ etc/php.ini#rpm scripts executed before installation%preecho '/usr/local/lib ' >/etc/ld.so.conf.d/local.conf/sbin/ldconfigif [$ = = 1-a-Z ' grep ^%{_user}/etc/passwd ' "]; Then # there are 3 values, representing the action, installation type, processing type Groupadd%{_group}-G 10000 # 1: Means installation useradd-u 10000-                G 10000-m%{_user} # 2: Indicates upgrade fi                                           # 0: Indicates a script executed after uninstalling #rpm installation%postif [$ = = 1];then [-z] ' grep ^ ' Export path= '/et C/profile ' "] && echo" Export path=%{_prefix}/bin:\ $PATH ">>/etc/profile [-N" ' grep ^ ' Export path= '/et C/profile ' "-a-z" ' grep '%{_prefix} '/etc/profile ' "] && sed-i" S@^export path=\ (. *\) @export Path=%{_prefix}/bin : \1@ "/etc/profile/sbin/chkconfig--add php-fpm/sbin/chkconfig php-fpm on mem= ' free-m | awk '/mem:/{print "#下面主要是参数的优化 if [$Mem-le 640];then mem_level=512m memory_limit=64 elif [$M EM-GT 640-a $Mem-le];then mem_level=1g memory_limit=128 elif [$Mem-gt 1280-a $Mem-le 2500];        Then mem_level=2g memory_limit=192 elif [$Mem-gt 2500-a $Mem-le 3500];then mem_level=3g memory_limit=256 elif [$Mem-gt 3500-a $Mem-le 4500];then mem_level=4g memory_limit=320 elif [$ MEM-GT 4500-a $Mem-le 8000];then Mem_level=6g memory_limit=384 elif [$Mem-gt 8000];then mem_level=8g memory_limit=448 fi sed -I "s@^memory_limit.* @memory_limit = ${memory_limit}m@"%{_prefix}/etc/php.ini sed-i ' s@^output_buffering = @output_bu ffering = on\noutput_buffering =@ '%{_prefix}/etc/php.ini sed-i ' s@^;cgi.fix_pathinfo.* @cgi. fix_pathinfo=0@ '%{_prefi X}/etc/php.ini sed-i ' S@^short_open_tag = Off@short_open_tag = on@ '%{_prefix}/etc/php.ini sed-i ' s@^expose_php =    on@expose_php = off@ '%{_prefix}/etc/php.ini sed-i ' s@^request_order.* @request_order = "CGP" @ '%{_prefix}/etc/php.ini Sed-i ' s@^;d ate.timezone.* @date. TimeZone = asia/shanghai@ '%{_prefix}/etc/php.ini sed-i ' s@^post_max_size.* @post_m Ax_size = 50m@ '%{_prefix}/etc/php.ini sed-i ' s@^upload_max_filesize.* @upload_max_filesize = 50m@ '%{_prefix}/etc/php. INI sed-i ' s@^;upload_tmp_dir.* @upload_tmp_dir =/tmp@ '%{_prefix}/etc/php.ini sed-i ' s@^max_execution_time.* @max_ Execution_time = 5@ '%{_pRefix}/etc/php.ini sed-i ' s@^disable_functions.* @disable_functions = Passthru,exec,system,chroot,chgrp,chown,shell _exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_ socket_server,fsocket,popen@ '%{_prefix}/etc/php.ini sed-i ' s@^session.cookie_httponly.* @session. cookie_httponly = 1@ '%{_prefix}/etc/php.ini sed-i ' s@^mysqlnd.collect_memory_statistics.* @mysqlnd. Collect_memory_statistics = On@ '%{ _prefix}/etc/php.ini Cat >%{_prefix}/etc/php-fpm.conf <
  
   /dev/null 2>&1/sbin/chkconfig--del PHP-FPM If [-E '/etc/profile.d/custom_profile_new.sh '];then sed    -I ' s@%{_prefix}/bin:@@ '/etc/profile.d/custom_profile_new.sh else sed-i ' s@%{_prefix}/bin:@@ '/etc/profile Scripts executed after Fifi#%postun rpm unload%clean #clean的主要作用就是删除BUILDrm-rf%{buildroot}%files #指定哪些文件需要被打包, such as/usr/local/php%defattr (- , root,root,-)%{_prefix}%attr (0755,root,root)/etc/init.d/php-fpm%changelog #日志改变段, the main description of the software development record * Sat OCT 24 2015 Yeho
   
    
     5.4.45-1-Initial Version
    
   
  
 

Here's php-redis.spec.

[root@linuxeye.com sources]# pwd/root/rpmbuild/sources[root@linuxeye.com sources]# lsredis-2.2.7.tgz[ Root@linuxeye.com sources]# CD. /spec[root@linuxeye.com spec]# Vim Php-redis.spec
%global Php_extdir% (/usr/local/php/bin/php-config--extension-dir 2>/dev/null | | echo "undefined") name:php-redisversion:2.2.7release:1%{?dist}summary:the Phpredis Extension provides an API for commun Icating with the Redis Key-value store. Group:development/languageslicense:phpurl:http://pecl.php.net/package/redissource0:redis-%{version}. Tgzbuildroot:%_topdir/buildrootrequires:phpbuildrequires:php >= 5.4.40%descriptionthe Phpredis Extension Provides an API for communicating with the Redis key-value store.%prep%setup-q-N redis-%{version}%build/usr/local/php/bi N/phpize%configuremake%{?_SMP_MFLAGS}%INSTALLRM-RF%{buildroot}mkdir-p%{buildroot}%{php_extdir}make Install Install_root=%{buildroot}find%{buildroot}-name redis.so-exec/bin/mv {}%{buildroot}%{php_extdir} \; #rpm安装后执行的脚本% postif [= = 1];then [-Z ' grep ' ^extension_dir '/usr/local/php/etc/php.ini ' "] && echo" extension_dir = \ " %{php_extdir}\ "" >>/usr/local/php/etc/php.ini sed-i ' s@^Extension_dir\ (. *\) @extension_dir \1\nextension = "redis.so" @ '/usr/local/php/etc/php.inifi#rpm script executed before%preunif [$ = = 0];THEN/ETC/INIT.D/PHP-FPM stop >/dev/null 2>&1 sed-i '/redis.so/d '/usr/local/php/etc/php.inifi#%p Ostun rpm executed script if [= = 0];then/etc/init.d/php-fpm Start >/dev/null 2>&1fi%cleanrm-rf%{buildroot}%fi  Les%defattr (-,root,root,-)%{php_extdir}/redis.so%changelog* Sat Oct Yeho
 
  
   2.2.7-1-Initial Version
  
 

Compiling RPM Packages

[root@linuxeye.com spec]# rpmbuild-bb php.spec making php rpm binary package [root@linuxeye.com spec]# rpmbuild-bb Php-redis.spec production php- Redis RPM Binary Package
Original: https://blog.linuxeye.com/431.html
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.