rpmbuild对php-7.0.8进行打包

spec结尾文件详解:

%define _user wanson
%define _group ebsig
%define _prefix /usr/local/inonesoft/php7
Name: php
Version: 7.0.8
Release: 1%{?dist} #release号,对应下面的changelog,如php-5.4.45-1.el6.x86_64.rpm
Summary: PHP is a server-side scripting language for creating dynamic Web pages
Group: Development/Languages #要全用这里面的一个组:less /usr/share/doc/rpm-version/GROUPS
License: GPLv2 #软件授权方式
URL: http://www.php.net #源码相关网站
Packager: cuibobo
Vendor: OneinStack #发行商或打包组织的信息
Source0: %{name}-%{version}.tar.gz #源代码包,可以带多个用Source1、Source2等源,后面也可以用%{source1}、%{source2}引用
BuildRoot: %_topdir/BUILDROOT #安装或编译时使用的“虚拟目录”
Requires: libmcrypt-devel
Requires: mhash
Requires: mcrypt
Requires: libevent
Requires: pcre
Requires: pcre-devel
Requires: openssl
Requires: openssl-devel
Requires: freetype-devel
Requires: libpng-devel
Requires: libjpeg-turbo-devel
Requires: libcurl-devel
Requires: libxml2-devel

%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
%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-debug
make ZEND_EXTRA_LIBS='-liconv' %{?_smp_mflags}
%install
rm -rf %{buildroot}
make INSTALL_ROOT=%{buildroot} install
rm -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

#rpm安装前执行的脚本
%pre
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
/sbin/ldconfig
if [ $1 == 1 -a -z "`grep ^%{_user} /etc/passwd`" ]; then # $1有3个值,代表动作,安装类型,处理类型
groupadd %{_group} -g 10000 # 1:表示安装
useradd -u 10000 -g 10000 -m %{_user} # 2:表示升级
fi # 0:表示卸载
#rpm安装后执行的脚本
%post
if [ $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}'` #下面主要是参数的优化
if [ $Mem -le 640 ];then
Mem_level=512M
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,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
fi
fi
#%postun rpm卸载后执行的脚本
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
%{_prefix}
%attr(0755,root,root) /etc/init.d/php-fpm
%changelog
* Tue Jun 27 2017 cuibobo 7.0.8-1
- Initial version

posted @ 2017-08-09 13:46  Mansoncui  阅读(480)  评论(0编辑  收藏  举报