php rpm打包spec文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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