{"id":8019,"date":"2022-07-21T10:10:26","date_gmt":"2022-07-21T02:10:26","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=8019"},"modified":"2022-07-22T01:01:38","modified_gmt":"2022-07-21T17:01:38","slug":"php-rpm-instance","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/php-rpm-instance.html","title":{"rendered":"\u5236\u4f5cPHP\u7684RPM\u5305\u5b9e\u4f8b"},"content":{"rendered":"
\u672c\u6587\u7531lrxjmw.cn\u56e2\u961f\u6210\u5458\u9b4f\u4e3d\u733f<\/span>\u6574\u7406\u53d1\u5e03\uff0c\u539f\u6587\u6765\u81ea\uff1aLinux\u8fd0\u7ef4\u7b14\u8bb0<\/a>\u3002<\/p>\n<\/div>\n \u6709\u65f6\u5019\u4e3a\u4e86\u65b9\u4fbf\u6e90\u7801\u5305\u7684\u5b89\u88c5\uff0c\u6211\u4eec\u9700\u8981\u81ea\u5df1\u8ba2\u5236\u8f6f\u4ef6\u5305\u7684\u9700\u6c42\uff0c\u6211\u4eec\u4f1a\u628a\u4e00\u4e9b\u6e90\u7801\u5305\u6309\u7167\u6211\u4eec\u7684\u9700\u6c42\u6765\u505a\u6210rpm\u5305\uff0c\u5f53\u6709\u4e86\u6e90\u7801\u5305\u5c31\u53ef\u4ee5\u76f4\u63a5\u7f16\u8bd1\u5f97\u5230\u4e8c\u8fdb\u5236\u5b89\u88c5\u5305\u548c\u5176\u4ed6\u4efb\u610f\u5305\uff0cspec file\u662f\u5236\u4f5crpm\u5305\u6700\u6838\u5fc3\u7684\u90e8\u5206\uff0crpm\u5305\u7684\u5236\u4f5c\u5c31\u662f\u6839\u636espec file\u6765\u5b9e\u73b0\u7684\u3002\u4e0b\u9762\u662f\u6211\u4ee5\u5236\u4f5cphp\u7684rpm\u5f00\u59cb\u4ecb\u7ecd\u5176\u5236\u4f5c\u65b9\u6cd5\uff0c\u4ee5\u4e0b\u64cd\u4f5c\u5728CentOS6.6 64\u4f4d\u7cfb\u7edf\u8fdb\u884c\u3002<\/p>\n \u5728redhat\u4e0b\uff0crpm\u5305\u7684\u9ed8\u8ba4\u5236\u4f5c\u8def\u5f84\u5728\/usr\/src\/redhat\u4e0b,\u4f46CentOS\u5e76\u6ca1\u6709\u8be5\u76ee\u5f55\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u4e0d\u5f97\u4e0d\u81ea\u5b9a\u4e49\u5de5\u4f5c\u76ee\u5f55\uff0c\u8fd9\u5176\u4e2d\u5305\u542b\u4e866\u4e2a\u76ee\u5f55\uff08\u8981\u6c42\u5168\u90e8\u5927\u5199\uff09\uff1a<\/p>\n rpmbuild --showrc\u663e\u793a\u6240\u6709\u7684\u5b8f\uff0c\u4ee5\u4e0b\u5212\u7ebf\u5f00\u5934\uff0c\u4e00\u4e2a\u4e0b\u5212\u7ebf\uff1a\u5b9a\u4e49\u73af\u5883\u7684\u4f7f\u7528\u60c5\u51b5\uff0c\u4e8c\u4e2a\u4e0b\u5212\u7ebf\uff1a\u901a\u5e38\u5b9a\u4e49\u7684\u662f\u547d\u4ee4\uff0c\u4e3a\u4ec0\u4e48\u8981\u5b9a\u4e49\u5b8f\uff0c\u56e0\u4e3a\u4e0d\u540c\u7684\u7cfb\u7edf\uff0c\u547d\u4ee4\u7684\u5b58\u653e\u4f4d\u7f6e\u53ef\u80fd\u4e0d\u540c\uff0c\u6240\u4ee5\u901a\u8fc7\u5b8f\u7684\u5b9a\u4e49\u627e\u5230\u547d\u4ee4\u7684\u771f\u6b63\u5b58\u653e\u4f4d\u7f6e<\/p>\n \u539f\u6587\u6765\u81ea\uff1ahttps:\/\/blog.linuxeye.com\/431.html<\/a><\/p>\n[root@linuxprobe SOURCES]# yum -y install rpm-build<\/pre>\n
[root@linuxprobe SOURCES]# vim ~\/.rpmmacros\r\n%_topdir \/root\/rpmbuild\r\n[root@linuxprobe SOURCES]# mkdir -pv ~\/rpmbuild\/{BUILD,RPMS,SOURCES,SPECS,SRPMS}<\/pre>\n
BUILD\uff1a\u6e90\u4ee3\u7801\u89e3\u538b\u4ee5\u540e\u653e\u7684\u4f4d\u7f6e\r\nRPMS\uff1a\u5236\u4f5c\u5b8c\u6210\u540e\u7684rpm\u5305\u5b58\u653e\u76ee\u5f55\uff0c\u4e3a\u7279\u5b9a\u5e73\u53f0\u6307\u5b9a\u5b50\u76ee\u5f55\uff08x86_64\uff09\r\nSOURCES\uff1a\u6536\u96c6\u7684\u6e90\u6587\u4ef6\uff0c\u6e90\u6750\u6599\uff0c\u8865\u4e01\u6587\u4ef6\u7b49\u5b58\u653e\u4f4d\u7f6e\r\nSPECS\uff1a\u5b58\u653espec\u6587\u4ef6\uff0c\u4f5c\u4e3a\u5236\u4f5crpm\u5305\u7684\u9886\u5c97\u6587\u4ef6\uff0c\u4ee5rpm\u540d.spec\r\nSRPMS\uff1asrc\u683c\u5f0f\u7684rpm\u5305\u4f4d\u7f6e \uff0c\u65e2\u7136\u662fsrc\u683c\u5f0f\u7684\u5305\uff0c\u5c31\u6ca1\u6709\u5e73\u53f0\u7684\u6982\u5ff5\u4e86\r\nBuiltRoot\uff1a\u5047\u6839\uff0c\u4f7f\u7528install\u4e34\u65f6\u5b89\u88c5\u5230\u8fd9\u4e2a\u76ee\u5f55\uff0c\u628a\u8fd9\u4e2a\u76ee\u5f55\u5f53\u4f5c\u6839\u6765\u7528\u7684\uff0c\u6240\u4ee5\u5728\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u7684\u76ee\u5f55\u6587\u4ef6\uff0c\u624d\u662f\u771f\u6b63\u7684\u76ee\u5f55\u6587\u4ef6\u3002\u5f53\u6253\u5305\u5b8c\u6210\u540e\uff0c\u5728\u6e05\u7406\u9636\u6bb5\uff0c\u8fd9\u4e2a\u76ee\u5f55\u5c06\u88ab\u5220\u9664\r\n<\/pre>\n
[root@linuxprobe SOURCES]# rpmbuild --showrc | grep topdir #\u5de5\u4f5c\u8f66\u95f4\u76ee\u5f55\uff1a_topdir \/root\/rpmbuild\r\n-14: _builddir %{_topdir}\/BUILD\r\n-14: _buildrootdir %{_topdir}\/BUILDROOT\r\n-14: _rpmdir %{_topdir}\/RPMS\r\n-14: _sourcedir %{_topdir}\/SOURCES\r\n-14: _specdir %{_topdir}\/SPECS\r\n-14: _srcrpmdir %{_topdir}\/SRPMS\r\n-14: _topdir \/root\/rpmbuild<\/pre>\n
[root@linuxprobe SOURCES]# pwd\r\n\/root\/rpmbuild\/SOURCES\r\n[root@linuxprobe SOURCES]# ls\r\nphp-5.4.45.tar.gz<\/pre>\n
[root@linuxprobe SPEC]# pwd \r\n\/root\/rpmbuild\/SOURCES\r\n[root@linuxprobe SPEC]# vim php.spec \r\n%define _user www\r\n%define _group www\r\n%define _prefix \/usr\/local\/php\r\nName: php #\u8f6f\u4ef6\u5305\u540d\u79f0\r\nVersion: 5.4.45 #\u7248\u672c\u53f7\uff08\u4e0d\u80fd\u4f7f\u7528-\uff09\r\nRelease: 1%{?dist} #release\u53f7\uff0c\u5bf9\u5e94\u4e0b\u9762\u7684changelog\uff0c\u5982php-5.4.45-1.el6.x86_64.rpm\r\nSummary: PHP is a server-side scripting language for creating dynamic Web pages #\u7b80\u8981\u63cf\u8ff0\u4fe1\u606f\uff0c\u6700\u597d\u4e0d\u8981\u8d85\u8fc750\u4e2a\u5b57\u7b26\uff0c\u5982\u8981\u8be6\u8ff0\uff0c\u4f7f\u7528\u4e0b\u9762\u7684%description\r\nGroup: Development\/Languages #\u8981\u5168\u7528\u8fd9\u91cc\u9762\u7684\u4e00\u4e2a\u7ec4\uff1aless \/usr\/share\/doc\/rpm-version\/GROUPS\r\nLicense: GPLv2 #\u8f6f\u4ef6\u6388\u6743\u65b9\u5f0f\r\nURL: http:\/\/www.php.net #\u6e90\u7801\u76f8\u5173\u7f51\u7ad9\r\nPackager: yeho #\u6253\u5305\u4eba\u7684\u4fe1\u606f\r\nVendor: OneinStack #\u53d1\u884c\u5546\u6216\u6253\u5305\u7ec4\u7ec7\u7684\u4fe1\u606f\r\nSource0: %{name}-%{version}.tar.gz #\u6e90\u4ee3\u7801\u5305\uff0c\u53ef\u4ee5\u5e26\u591a\u4e2a\u7528Source1\u3001Source2\u7b49\u6e90\uff0c\u540e\u9762\u4e5f\u53ef\u4ee5\u7528%{source1}\u3001%{source2}\u5f15\u7528\r\nBuildRoot: %_topdir\/BUILDROOT #\u5b89\u88c5\u6216\u7f16\u8bd1\u65f6\u4f7f\u7528\u7684\u201c\u865a\u62df\u76ee\u5f55\u201d\r\nRequires: libmcrypt\r\nRequires: mhash\r\nRequires: mcrypt\r\nRequires: libiconv #\u5b9a\u4e49php\u4f9d\u8d56\u7684\u5305\uff0c\u9700\u8981yum\u5b89\u88c5(\u6b64\u5904\u4f7f\u7528epel\u6e90)\r\n%description #\u8f6f\u4ef6\u5305\u8be6\u8ff0\r\nPHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.\r\n%prep #\u8f6f\u4ef6\u7f16\u8bd1\u4e4b\u524d\u7684\u5904\u7406\uff0c\u5982\u89e3\u538b\r\n%setup -q #\u8fd9\u4e2a\u5b8f\u7684\u4f5c\u7528\u9759\u9ed8\u6a21\u5f0f\u89e3\u538b\u5e76cd\r\n%build #\u5f00\u59cb\u7f16\u8bd1\u8f6f\u4ef6\r\n%configure --prefix=%{_prefix} --with-config-file-path=%{_prefix}\/etc \\\r\n--with-fpm-user=%{_user} --with-fpm-group=%{_group} --enable-fpm --enable-fileinfo \\\r\n--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \\\r\n--with-iconv-dir=\/usr\/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \\\r\n--with-libxml-dir=\/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif \\\r\n--enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-inline-optimization \\\r\n--enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl \\\r\n--with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-calendar \\\r\n--with-gettext --enable-zip --enable-soap --disable-ipv6 --disable-debug\r\nmake ZEND_EXTRA_LIBS='-liconv' %{?_smp_mflags} #%{?_smp_mflags} \u7684\u610f\u601d\u662f\uff1a\u5982\u679c\u5c31\u591a\u5904\u7406\u5668\u7684\u8bddmake\u65f6\u5e76\u884c\u7f16\u8bd1\r\n%install #\u5f00\u59cb\u5b89\u88c5\u8f6f\u4ef6\uff0c\u5982make install\r\nrm -rf %{buildroot}\r\nmake INSTALL_ROOT=%{buildroot} install\r\nrm -rf %{buildroot}\/{.channels,.depdb,.depdblock,.filemap,.lock,.registry}\r\n%{__install} -p -D -m 0755 sapi\/fpm\/init.d.php-fpm %{buildroot}\/etc\/init.d\/php-fpm\r\n%{__install} -p -D -m 0644 php.ini-production %{buildroot}\/%{_prefix}\/etc\/php.ini\r\n#rpm\u5b89\u88c5\u524d\u6267\u884c\u7684\u811a\u672c\r\n%pre\r\necho '\/usr\/local\/lib' > \/etc\/ld.so.conf.d\/local.conf\r\n\/sbin\/ldconfig\r\nif [ $1 == 1 -a -z \"`grep ^%{_user} \/etc\/passwd`\" ]; then # $1\u67093\u4e2a\u503c\uff0c\u4ee3\u8868\u52a8\u4f5c\uff0c\u5b89\u88c5\u7c7b\u578b\uff0c\u5904\u7406\u7c7b\u578b\r\n groupadd %{_group} -g 10000 # 1\uff1a\u8868\u793a\u5b89\u88c5\r\n useradd -u 10000 -g 10000 -m %{_user} # 2\uff1a\u8868\u793a\u5347\u7ea7\r\nfi # 0\uff1a\u8868\u793a\u5378\u8f7d\r\n#rpm\u5b89\u88c5\u540e\u6267\u884c\u7684\u811a\u672c\r\n%post\r\nif [ $1 == 1 ];then\r\n [ -z \"`grep ^'export PATH=' \/etc\/profile`\" ] && echo \"export PATH=%{_prefix}\/bin:\\$PATH\" >> \/etc\/profile\r\n [ -n \"`grep ^'export PATH=' \/etc\/profile`\" -a -z \"`grep '%{_prefix}' \/etc\/profile`\" ] && sed -i \"s@^export PATH=\\(.*\\)@export PATH=%{_prefix}\/bin:\\1@\" \/etc\/profile\r\n \/sbin\/chkconfig --add php-fpm\r\n \/sbin\/chkconfig php-fpm on\r\n Mem=`free -m | awk '\/Mem:\/{print $2}'` #\u4e0b\u9762\u4e3b\u8981\u662f\u53c2\u6570\u7684\u4f18\u5316\r\n if [ $Mem -le 640 ];then\r\n Mem_level=512M\r\n Memory_limit=64\r\n elif [ $Mem -gt 640 -a $Mem -le 1280 ];then\r\n Mem_level=1G\r\n Memory_limit=128\r\n elif [ $Mem -gt 1280 -a $Mem -le 2500 ];then\r\n Mem_level=2G\r\n Memory_limit=192\r\n elif [ $Mem -gt 2500 -a $Mem -le 3500 ];then\r\n Mem_level=3G\r\n Memory_limit=256\r\n elif [ $Mem -gt 3500 -a $Mem -le 4500 ];then\r\n Mem_level=4G\r\n Memory_limit=320\r\n elif [ $Mem -gt 4500 -a $Mem -le 8000 ];then\r\n Mem_level=6G\r\n Memory_limit=384\r\n elif [ $Mem -gt 8000 ];then\r\n Mem_level=8G\r\n Memory_limit=448\r\n fi\r\n sed -i \"s@^memory_limit.*@memory_limit = ${Memory_limit}M@\" %{_prefix}\/etc\/php.ini\r\n sed -i 's@^output_buffering =@output_buffering = On\\noutput_buffering =@' %{_prefix}\/etc\/php.ini\r\n sed -i 's@^;cgi.fix_pathinfo.*@cgi.fix_pathinfo=0@' %{_prefix}\/etc\/php.ini\r\n sed -i 's@^short_open_tag = Off@short_open_tag = On@' %{_prefix}\/etc\/php.ini\r\n sed -i 's@^expose_php = On@expose_php = Off@' %{_prefix}\/etc\/php.ini\r\n sed -i 's@^request_order.*@request_order = \"CGP\"@' %{_prefix}\/etc\/php.ini\r\n sed -i 's@^;date.timezone.*@date.timezone = Asia\/Shanghai@' %{_prefix}\/etc\/php.ini\r\n sed -i 's@^post_max_size.*@post_max_size = 50M@' %{_prefix}\/etc\/php.ini\r\n sed -i 's@^upload_max_filesize.*@upload_max_filesize = 50M@' %{_prefix}\/etc\/php.ini\r\n sed -i 's@^;upload_tmp_dir.*@upload_tmp_dir = \/tmp@' %{_prefix}\/etc\/php.ini\r\n sed -i 's@^max_execution_time.*@max_execution_time = 5@' %{_prefix}\/etc\/php.ini\r\n 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\r\n sed -i 's@^session.cookie_httponly.*@session.cookie_httponly = 1@' %{_prefix}\/etc\/php.ini\r\n sed -i 's@^mysqlnd.collect_memory_statistics.*@mysqlnd.collect_memory_statistics = On@' %{_prefix}\/etc\/php.ini\r\n cat > %{_prefix}\/etc\/php-fpm.conf < \/dev\/null 2>&1\r\n \/sbin\/chkconfig --del php-fpm\r\n if [ -e '\/etc\/profile.d\/custom_profile_new.sh' ];then\r\n sed -i 's@%{_prefix}\/bin:@@' \/etc\/profile.d\/custom_profile_new.sh\r\n else\r\n sed -i 's@%{_prefix}\/bin:@@' \/etc\/profile\r\n fi\r\nfi\r\n#%postun rpm\u5378\u8f7d\u540e\u6267\u884c\u7684\u811a\u672c\r\n%clean #clean\u7684\u4e3b\u8981\u4f5c\u7528\u5c31\u662f\u5220\u9664BUILD\r\nrm -rf %{buildroot}\r\n%files #\u6307\u5b9a\u54ea\u4e9b\u6587\u4ef6\u9700\u8981\u88ab\u6253\u5305\uff0c\u5982\/usr\/local\/php\r\n%defattr(-,root,root,-)\r\n%{_prefix}\r\n%attr(0755,root,root) \/etc\/init.d\/php-fpm\r\n%changelog #\u65e5\u5fd7\u6539\u53d8\u6bb5\uff0c \u8fd9\u4e00\u6bb5\u4e3b\u8981\u63cf\u8ff0\u8f6f\u4ef6\u7684\u5f00\u53d1\u8bb0\u5f55\r\n* Sat Oct 24 2015 yeho 5.4.45-1\r\n- Initial version\r\n<\/pre>\n
[root@linuxprobe SOURCES]# pwd\r\n\/root\/rpmbuild\/SOURCES\r\n[root@linuxprobe SOURCES]# ls\r\nredis-2.2.7.tgz\r\n[root@linuxprobe SOURCES]# cd ..\/SPEC\r\n[root@linuxprobe SPEC]# vim php-redis.spec\r\n%global php_extdir %(\/usr\/local\/php\/bin\/php-config --extension-dir 2>\/dev\/null || echo \"undefined\")\r\nName: php-redis\r\nVersion: 2.2.7\r\nRelease: 1%{?dist}\r\nSummary: The phpredis extension provides an API for communicating with the Redis key-value store.\r\nGroup: Development\/Languages\r\nLicense: PHP\r\nURL: http:\/\/pecl.php.net\/package\/redis\r\nSource0: redis-%{version}.tgz\r\nBuildRoot: %_topdir\/BUILDROOT\r\nRequires: php\r\nBuildRequires: php >= 5.4.40\r\n%description\r\nThe phpredis extension provides an API for communicating with the Redis key-value store.\r\n%prep\r\n%setup -q -n redis-%{version}\r\n%build\r\n\/usr\/local\/php\/bin\/phpize\r\n%configure\r\nmake %{?_smp_mflags}\r\n%install\r\nrm -rf %{buildroot}\r\nmkdir -p %{buildroot}%{php_extdir}\r\nmake install INSTALL_ROOT=%{buildroot}\r\nfind %{buildroot} -name redis.so -exec \/bin\/mv {} %{buildroot}%{php_extdir} \\;\r\n#rpm\u5b89\u88c5\u540e\u6267\u884c\u7684\u811a\u672c\r\n%post\r\nif [ $1 == 1 ];then\r\n [ -z \"`grep '^extension_dir' \/usr\/local\/php\/etc\/php.ini`\" ] && echo \"extension_dir = \\\"%{php_extdir}\\\"\" >> \/usr\/local\/php\/etc\/php.ini\r\n sed -i 's@^extension_dir\\(.*\\)@extension_dir\\1\\nextension = \"redis.so\"@' \/usr\/local\/php\/etc\/php.ini\r\nfi\r\n#rpm\u5378\u8f7d\u524d\u6267\u884c\u7684\u811a\u672c\r\n%preun\r\nif [ $1 == 0 ];then\r\n \/etc\/init.d\/php-fpm stop > \/dev\/null 2>&1\r\n sed -i '\/redis.so\/d' \/usr\/local\/php\/etc\/php.ini\r\nfi\r\n#%postun rpm\u5378\u8f7d\u540e\u6267\u884c\u7684\u811a\u672c\r\nif [ $1 == 0 ];then\r\n \/etc\/init.d\/php-fpm start > \/dev\/null 2>&1\r\nfi\r\n%clean\r\nrm -rf %{buildroot}\r\n%files\r\n%defattr(-,root,root,-)\r\n%{php_extdir}\/redis.so\r\n%changelog\r\n* Sat Oct 24 2015 yeho 2.2.7-1\r\n- Initial version\r\n<\/pre>\n
[root@linuxprobe SPEC]# rpmbuild -bb php.spec \u5236\u4f5cphp\u7684rpm\u4e8c\u8fdb\u5236\u5305\r\n[root@linuxprobe SPEC]# rpmbuild -bb php-redis.spec \u5236\u4f5cphp-redis\u7684rpm\u4e8c\u8fdb\u5236\u5305<\/pre>\n
\n