Centos7 源码安装 PHP7.2
2021-01-26 17:15
标签:each hang libxml2 dba efault 复制 writing HERE text Centos7 源码安装 PHP7.2 标签:each hang libxml2 dba efault 复制 writing HERE text 原文地址:https://www.cnblogs.com/gromm/p/13229408.html源码安装 php
#
yum install epel-release
#
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# 先安装下依赖
yum install -y wget gcc gcc-c++ autoconf libxml2-devel make systemtap-sdt-devel pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libxslt libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed gperftools dnf sqlite-devel bzip2-devel enchant-devel gmp-devel libc-client-devel firebird-devel libicu-devel unixODBC-devel openldap-devel postgresql-devel freetds-devel aspell-devel readline-devel libedit-devel recode-devel net-snmp-devel libsodium-devel libargon2-devel libtidy-devel libcurl-devel
mkdir -p /root/download
cd /root/download
wget https://www.php.net/distributions/php-7.2.31.tar.gz
tar -xvf php-7.2.31.tar.gz
cd php-7.2.31
# 配置,这个配置参考了 yum 安装 php72w 的一些参数,尽量按之前使用习惯来
./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --cache-file=../config.cache --with-libdir=lib64 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-debug --enable-cli --enable-fpm --with-pic --disable-rpath --without-pear --with-freetype-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr --without-gdbm --with-jpeg-dir=/usr --with-openssl --with-password-argon2 --with-pcre-regex --with-zlib --with-layout=GNU --with-kerberos --with-libxml-dir=/usr --with-mhash --enable-dtrace --disable-phpdbg --libdir=/usr/lib64/php --enable-pcntl --without-readline --with-libedit --enable-mbstring=shared --enable-mbregex --with-gd=shared --with-gmp=shared --enable-calendar=shared --enable-bcmath=shared --with-bz2=shared --enable-ctype=shared --enable-dba=shared --with-db4=/usr --enable-exif=shared --enable-ftp=shared --with-gettext=shared --with-iconv=shared --enable-sockets=shared --enable-tokenizer=shared --with-xmlrpc=shared --with-ldap=shared --with-ldap-sasl --enable-mysqlnd=shared --with-mysqli=shared,mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --with-interbase=shared,/usr/lib64/firebird --with-pdo-firebird=shared,/usr/lib64/firebird --enable-dom=shared --with-pgsql=shared --enable-simplexml=shared --enable-xml=shared --enable-wddx=shared --with-snmp=shared,/usr --enable-soap=shared --with-xsl=shared,/usr --enable-xmlreader=shared --enable-xmlwriter=shared --with-curl=shared,/usr --enable-pdo=shared --with-pdo-odbc=shared,unixODBC,/usr --with-pdo-mysql=shared,mysqlnd --with-pdo-pgsql=shared,/usr --with-pdo-sqlite=shared,/usr --with-pdo-dblib=shared,/usr --with-sqlite3=shared,/usr --enable-json=shared --enable-zip=shared --with-pspell=shared --enable-phar=shared --with-sodium=shared --with-tidy=shared,/usr --enable-sysvmsg=shared --enable-sysvshm=shared --enable-sysvsem=shared --enable-shmop=shared --enable-posix=shared --with-unixODBC=shared,/usr --enable-fileinfo=shared --enable-intl=shared --with-icu-dir=/usr --with-enchant=shared,/usr --with-recode=shared,/usr --enable-opcache build_alias=x86_64-redhat-linux-gnu host_alias=x86_64-redhat-linux-gnu
# 编译
make -j4 && make install
# 编译成功后,下面这些信息记录下,可能后面有用到
Installing shared extensions: /usr/lib64/php/20170718-debug/
Installing PHP CLI binary: /usr/bin/
Installing PHP CLI man page: /usr/share/man/man1/
Installing PHP FPM binary: /usr/sbin/
Installing PHP FPM defconfig: /etc/
Installing PHP FPM man page: /usr/share/man/man8/
Installing PHP FPM status page: /usr/share/fpm/
Installing PHP CGI binary: /usr/bin/
Installing PHP CGI man page: /usr/share/man/man1/
Installing build environment: /usr/lib64/php/build/
Installing header files: /usr/include/php/
Installing helper programs: /usr/bin/
program: phpize
program: php-config
Installing man pages: /usr/share/man/man1/
page: phpize.1
page: php-config.1
/root/download/php-7.2.31/build/shtool install -c ext/phar/phar.phar /usr/bin
ln -s -f phar.phar /usr/bin/phar
Installing PDO headers: /usr/include/php/ext/pdo/
后续处理
php -v
php-fpm -v
php -m
php -r "phpinfo();" | grep php.ini
# 编译后默认是没有 php.ini,根据环境把安装包里的复制一份过去
cp php.ini-development /etc/php.ini
# 检查 php-fpm 配置
ll /etc/php-fpm*
mv /etc/php-fpm.conf.default /etc/php-fpm.conf
mv /etc/php-fpm.d/www.conf.default /etc/php-fpm.d/www.conf
# 看下动态库配置的保存目录
php -r "phpinfo();" | grep additional
mkdir -p /etc/php.d
# 查看安装的动态库
ll /usr/lib64/php/20170718-debug/*.so
# 将所有的 so 在 /etc/php.d 里面对应生成一个 .ini 文件。 比如 zip.so
echo "extension=zip.so" > /etc/php.d/zip.ini
# 检查下
php -m | grep zip
# 其中 mysqli.so 比较特殊,必须在 mysqlnd.so 之后加载,所以 ini 文件名要改一下
# 报错类似 PHP Warning: PHP Startup: Unable to load dynamic library ‘mysqli.so‘
echo "extension=mysqli.so" > /etc/php.d/mysqlnd_mysqli.ini
# opcache 也比较特殊,需要 opcache.ini 和 opcache-default.blacklist 两个文件
cat /etc/php.d/opcache.ini
; Enable Zend OPcache extension module
zend_extension=opcache.so
; Determines if Zend OPCache is enabled
opcache.enable=1
; Determines if Zend OPCache is enabled for the CLI version of PHP
;opcache.enable_cli=0
; The OPcache shared memory storage size.
opcache.memory_consumption=128
; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8
; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 100000 are allowed.
opcache.max_accelerated_files=4000
; The maximum percentage of "wasted" memory until a restart is scheduled.
;opcache.max_wasted_percentage=5
; When this directive is enabled, the OPcache appends the current working
; directory to the script key, thus eliminating possible collisions between
; files with the same name (basename). Disabling the directive improves
; performance, but may break existing applications.
;opcache.use_cwd=1
; When disabled, you must reset the OPcache manually or restart the
; webserver for changes to the filesystem to take effect.
opcache.validate_timestamps=0
; How often (in seconds) to check file timestamps for changes to the shared
; memory storage allocation. ("1" means validate once per second, but only
; once per request. "0" means always validate)
;opcache.revalidate_freq=2
; Enables or disables file search in include_path optimization
;opcache.revalidate_path=0
; If disabled, all PHPDoc comments are dropped from the code to reduce the
; size of the optimized code.
;opcache.save_comments=1
; If disabled, PHPDoc comments are not loaded from SHM, so "Doc Comments"
; may be always stored (save_comments=1), but not loaded by applications
; that don‘t need them anyway.
;opcache.load_comments=1
; If enabled, a fast shutdown sequence is used for the accelerated code
opcache.fast_shutdown=1
; Allow file existence override (file_exists, etc.) performance feature.
;opcache.enable_file_override=0
; A bitmask, where each bit enables or disables the appropriate OPcache
; passes
;opcache.optimization_level=0xffffffff
;opcache.inherited_hack=1
;opcache.dups_fix=0
; The location of the OPcache blacklist file (wildcards allowed).
; Each OPcache blacklist file is a text file that holds the names of files
; that should not be accelerated. The file format is to add each filename
; to a new line. The filename may be a full path or just a file prefix
; (i.e., /var/www/x blacklists all the files and directories in /var/www
; that start with ‘x‘). Line starting with a ; are ignored (comments).
opcache.blacklist_filename=/etc/php.d/opcache*.blacklist
; Allows exclusion of large files from being cached. By default all files
; are cached.
;opcache.max_file_size=0
; Check the cache checksum each N requests.
; The default value of "0" means that the checks are disabled.
;opcache.consistency_checks=0
; How long to wait (in seconds) for a scheduled restart to begin if the cache
; is not being accessed.
;opcache.force_restart_timeout=180
; OPcache error_log file name. Empty string assumes "stderr".
;opcache.error_log=
; All OPcache errors go to the Web server log.
; By default, only fatal errors (level 0) or errors (level 1) are logged.
; You can also enable warnings (level 2), info messages (level 3) or
; debug messages (level 4).
;opcache.log_verbosity_level=1
; Preferred Shared Memory back-end. Leave empty and let the system decide.
;opcache.preferred_memory_model=
; Protect the shared memory from unexpected writing during script execution.
; Useful for internal debugging only.
;opcache.protect_memory=0
; Allows calling OPcache API functions only from PHP scripts which path is
; started from specified string. The default "" means no restriction
;opcache.restrict_api=
; Mapping base of shared memory segments (for Windows only). All the PHP
; processes have to map shared memory into the same address space. This
; directive allows to manually fix the "Unable to reattach to base address"
; errors.
;opcache.mmap_base=
EOF
cat /etc/php.d/opcache-default.blacklist
; The blacklist file is a text file that holds the names of files
; that should not be accelerated. The file format is to add each filename
; to a new line. The filename may be a full path or just a file prefix
; (i.e., /var/www/x blacklists all the files and directories in /var/www
; that start with ‘x‘). Line starting with a ; are ignored (comments).
; Files are usually triggered by one of the following three reasons:
; 1) Directories that contain auto generated code, like Smarty or ZFW cache.
; 2) Code that does not work well when accelerated, due to some delayed
; compile time evaluation.
; 3) Code that triggers an OPcache bug.
EOF
imagick 扩展安装
# 先安装下依赖
yum install -y ImageMagick-devel
cd /root/download
wget https://pecl.php.net/get/imagick-3.4.4.tgz
tar xvf imagick-3.4.4.tgz
cd imagick-3.4.4
phpize
./configure --with-imagick=shared
make && make install
echo "extension=imagick.so" > /etc/php.d/imagick.ini
php -m | grep imagick
文章标题:Centos7 源码安装 PHP7.2
文章链接:http://soscw.com/index.php/essay/47372.html