Creating php rpm packages sometimes requires customized software packages to facilitate the installation of source code packages. we will make some source code packages into rpm packages according to our needs, with the source code package, you can directly compile the binary installation package and any other packages. Spec file is the core part of the rpm Package. The rpm Package is created based on the spec file. The following describes how to create a php rpm. The following operations are performed on the 64-bit CentOS6.6 system.
Next we will begin to introduce the method of making php rpm. The following operations are performed on the 64-bit CentOS6.6 system.
Install rpm-build
[root@linuxeye.com SOURCES]# yum -y install rpm-build
Create a workshop Directory
[root@linuxeye.com SOURCES]# vim ~/.rpmmacros %_topdir /root/rpmbuild
[root@linuxeye.com SOURCES]# mkdir -pv ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
In redhat, the default path of the rpm package is in/usr/src/redhat, but CentOS does not. Therefore, we have to customize the working directory, this includes 6 directories (all uppercase letters are required)
BUILD: place where the source code is extracted and put RPMS: directory where the rpm Package is stored after preparation, specify the subdirectory (x86_64) SOURCES for a specific platform: collected source file, source material, storage location of patch files, such as SPECS: The spec file is used as the Post file for making the rpm Package, with the rpm name. specSRPMS: location of the rpm Package in src format. since it is a src package, there is no platform concept. BuiltRoot: fake root. use install to temporarily install it to this directory, this directory is used as the root, so the directory files under this directory are the real directory files. After the package is completed, the directory will be deleted during the cleanup phase.
[Root@linuxeye.com SOURCES] # rpmbuild -- showrc | grep topdir # workshop Directory: _ 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 macros, starting with an underscore (_). It defines the environment usage and underscores (_). generally, commands are defined. why define macros, because different systems may have different storage locations for commands, you can find the real storage location of commands through macro definition.
Collect source code file script files
[root@linuxeye.com SOURCES]# pwd/root/rpmbuild/SOURCES[root@linuxeye.com SOURCES]# lsphp-5.4.45.tar.gz
Write a SPEC file
[Root@linuxeye.com SPEC] # pwd/root/rpmbuild/SOURCES [root@linuxeye.com SPEC] # vim php. spec # The content is as follows:
% Define _ user www % define _ group www % define _ prefix/usr/local/phpName: php # package name Version: 5.4.45 # Version number (-unavailable) Release: 1% {? Dist} # release number, corresponding to the following changelog, such as php-5.4.45-1.el6.x86_64.rpmSummary: PHP is a server-side scripting language for creating dynamic Web pages # brief description information, preferably not more than 50 characters, for details, use the following % descriptionGroup: Development/Ages # to use all of the following groups: less/usr/share/doc/rpm-version/GROUPSLicense: GPLv2 # Software authorization URL: http://www.php.net # Source Code related websites Packager: yeho
# Package owner Information Vendor: OneinStack # publisher or package Organization information Source0: Zookeeper name1_-zookeeper version=.tar.gz # Source Code package, which can contain multiple sources such as Source1 and Source2, you can also use % {source1} and % {source2} to reference the "virtual directory" Requires: libmcryptRequires: mhashRequires: mcrypt Requires: libiconv # defines the php dependent package and Requires yum installation (the epel source is used here) % description # Software package details PHP is a widely-used general-purpose scripting language that is especially suited for Web development and Can be embedded into HTML. % prep # process before Software Compilation, for example, extract % setup-q # The role of this macro. decompress the macro in silent mode and run cd % build # to compile the software. % 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-zli B \ -- 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 --- openssl \ -- with-mhash -- enable-pcntl -- enable-sockets -- with-xmlrpc -- enable-ftp -- enable-calendar \ -- with-gettext -- enabl E-zip -- enable-soap -- disable-ipv6 -- disable-debugmake ZEND_EXTRA_LIBS = '-liconv' % {? _ Smp_mflags }#% {? _ Smp_mflags} indicates that if multi-processor is used, make will compile in parallel % install # start to install the software, for example, make installrm-rf % {buildroot} make INSTALL_ROOT =%{ buildroot} installrm-rf % {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 # script run before rpm installation % preecho '/usr/local/lib'>/etc/ld. so. conf. d/local. conf/sbin/ldconfigif [$1 = 1-a-z "'grep ^ % {_ user}/etc/passwd" ']; then #$1 has three values, which represent the action, installation type, and processing type groupadd % {_ group}-g 10000 #1: indicates installing useradd-u 10000-g 10000-m % {_ user} #2: indicates upgrading fi #0: indicates to uninstall # script executed after rpm installation % postif [$1 = 1]; then [-z "'grep ^ 'export PATH ='/etc/profile" '] & echo "export PATH =%{_ prefix}/bin: \ $ PATH ">/etc/profile [-n" 'grep ^ 'export PATH ='/etc/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 $2} ''# The following mainly describes the parameter optimization if [$ Mem-le 640]; then Mem_level = 512 M Memory_limit = 64 elif [$ Mem-gt 640-a $ Mem-le 1280]; 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_buffering = On \ noutput_buffering = @ '% {_ prefix}/etc/php. ini sed-I's @ ^; cgi. fix_pathinfo. * @ cgi. fix_pathinfo = 0 @ '% {_ prefix}/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 @ ^; date. timezone. * @ date. timezone = Asia/Shanghai @ '% {_ prefix}/etc/php. ini sed-I's @ ^ post_max_size. * @ post_max_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, delimiter, callback, 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 fifi # % postun the script % clean executed after the rpm is uninstalled # The main function of clean is to delete BUILDrm-rf % {buildroot} % files # specify which files are required packaged, for example,/usr/local/php % defattr (-, root, root,-) % {_ prefix} % attr (0755, root, root)/etc/init. d/php-fpm % changelog # log change section, which mainly describes the software development record * Sat Oct 24 2015 yeho
5.4.45-1-Initial version
Below is the 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 communicating 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/bin/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 }\; # script executed after rpm installation % postif [$1 = 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 # script executed before rpm uninstallation % preunif [$1 = 0]; then/etc/init. d/php-fpm stop>/dev/null 2> & 1 sed-I '/redis. so/D'/usr/local/php/etc/php. inifi # % postun rpm the script executed after uninstalling if [$1 = 0]; then/etc/init. d/php-fpm start>/dev/null 2> & 1fi % cleanrm-rf % {buildroot} % files % defattr (-, root, root ,-) % {php_extdir}/redis. so % changelog * Sat Oct 24 2015 yeho
2.2.7-1-Initial version
Compile the rpm Package
[Root@linuxeye.com SPEC] # rpmbuild-bb php. spec make php rpm binary package [root@linuxeye.com SPEC] # rpmbuild-bb php-redis.spec make php-redis rpm binary package
Original article: https://blog.linuxeye.com/431.html