php rpm打包spec文件

作者: ropon 分类: 经验分享 发布时间: 2019-07-23 09:59
Name: php
Version: 7.0.33
Release: 1%{?dist}
Summary: php-7.0.33 RPM
Group: applications/php
License: GPL
URL: https://www.php.net
Source0: %{name}-%{version}.tar.gz
#Source1: libiconv-1.15.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires: gcc-c++ libxml2-devel openssl-devel libcurl-devel gd-devel libmcrypt-devel libxslt-devel mhash mcrypt icu libicu libicu-devel libzip
Requires: libxml2-devel openssl-devel libcurl-devel gd-devel libmcrypt-devel libxslt-devel mhash mcrypt icu libicu libicu-devel libzip
#php7.3 协助原cmake重新安装cmake-3.13.3

Packager: ropon@west.cn
AutoReqProv: no

%description
%{name}-%{version}
%define _phpflag 70
%define _runuser www
%define _prefix /usr/local/%{name}-%{version}

#构建前的准备
%prep
%setup -q

#构建
%build
./configure --prefix=%{_prefix} \
--with-config-file-path=%{_prefix}/etc \
--with-config-file-scan-dir=%{_prefix}/etc/php.d \
--with-fpm-user=%{_runuser} \
--with-fpm-group=%{_runuser} \
--enable-fpm \
--disable-opcache \
--disable-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 \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-exif \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl=/usr/local \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-ftp \
--enable-intl \
--with-xsl \
--with-gettext \
--enable-zip \
--enable-soap \
--disable-debug

make %{?_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%{_phpflag}-fpm
install -p -D -m 0644 php.ini-production  %{buildroot}/%{_prefix}/etc/php.ini

#rpm安装前执行的脚本
%pre
id -u %{_runuser} >/dev/null 2>&1
[ $? -ne 0 ] && useradd -M -s /sbin/nologin %{_runuser}
echo '/usr/local/lib64
	/usr/local/lib
	/usr/lib
	/usr/lib64'>>/etc/ld.so.conf
ldconfig -v

#rpm安装后执行的脚本
%post
[ -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
. /etc/profile

sed -i 's@^;date.timezone.*@date.timezone = Asia/Shanghai@' %{_prefix}/etc/php.ini
sed -i 's@^short_open_tag = Off@short_open_tag = On@' %{_prefix}/etc/php.ini
sed -i 's@^post_max_size.*@post_max_size = 100M@' %{_prefix}/etc/php.ini
sed -i 's@^upload_max_PhpFilesize.*@upload_max_PhpFilesize = 50M@' %{_prefix}/etc/php.ini
sed -i 's@^max_execution_time.*@max_execution_time = 300@' %{_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

wget -O /etc/init.d/php%{_phpflag}-fpm http://panel.ropon.top/panel/lnmp/init.d/php-fpm.txt
sed -i "s@^prefix=.*@prefix=%{_prefix}@" /etc/init.d/php%{_phpflag}-fpm
sed -i "s@php-fpm.pid@php%{_phpflag}-fpm.pid@" /etc/init.d/php%{_phpflag}-fpm
chmod +x /etc/init.d/php%{_phpflag}-fpm
chkconfig --add php%{_phpflag}-fpm
chkconfig php%{_phpflag}-fpm on
wget -O %{_prefix}/etc/php-fpm.conf http://panel.ropon.top/panel/lnmp/config/php-fpm.txt
sed -i "s@www@%{_runuser}@" %{_prefix}/etc/php-fpm.conf
sed -i "s@php@php%{_phpflag}@" %{_prefix}/etc/php-fpm.conf
service php%{_phpflag}-fpm start

#rpm卸载前执行的脚本
%preun
service php%{_phpflag}-fpm stop
chkconfig --del php%{_phpflag}-fpm
id -u %{_runuser} >/dev/null 2>&1
[ $? -eq 0 ] && userdel %{_runuser}

#卸载后执行的脚本
%postun
[ -d %{_prefix} ] && rm -rf %{_prefix}
#[ -f /etc/init.d/php%{_phpflag}-fpm ] && rm -f /etc/init.d/php%{_phpflag}-fpm

%clean
rm -rf %{buildroot}

%files
%defattr(-, %{_runuser}, %{_runuser})
%attr(744, %{_runuser}, %{_runuser}) %{_prefix}/*
%attr(0755,root,root) /etc/init.d/php%{_phpflag}-fpm

%changelog

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!