my blog my blog

Category: Linux
Ubuntu18.04编译安装PHP7.3.8

奶牛在踩坑过程中,请不要阻止。身为一个站长,一路以来一直使用LNMP来安装LNMP环境,深感羞耻,打算把该踩的坑都踩一踩,也学习一下该学习的东西。

今天是把OpenResty+PHP+Mysql的坑都踩了一遍,学到了不少东西,与君共勉。

需求环境安装

build-essential libcurl14 libcurl4-gnutls-dev openssl curl libbz2-dev libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev libzip-dev libxslt1-dev

下载PHP7.3.8

wget https://www.php.net/distributions/php-7.3.8.tar.gz

解压

tar xzvf php-7.3.8.tar.gz

进入目录

cd php-7.3.8

编译安装

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext  --enable-opcache --with-xsl
make
make test
make install
mkdir -p /usr/local/php/{etc,conf.d}
cp php.ini-production /usr/local/php/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
update-rc.d php-fpm default

防止Failed to start php.service: Unit php-fpm.service not found.类错误发生。

配置文件php.ini

贴上现有的配置,改自LNMP。

engine = On
short_open_tag = On
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = -1
disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
disable_classes =
zend.enable_gc = On
expose_php = On
max_execution_time = 300
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 50M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
cgi.fix_pathinfo=0
file_uploads = On
upload_max_filesize = 50M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
extension=fileinfo
[CLI Server]
cli_server.color = On

[Date]
date.timezone = PRC
[filter]
[iconv]
[intl]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[OCI8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
[Assertion]
zend.assertions = -1
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[dba]
[opcache]
[zend opcache]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/opcache.so"
opcache.force_restart_timeout=3600
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable=1
opcache.enable_cli=1
[curl]
[openssl]

关于fileinfo

这个默认是安装的,但是有说内存小于1G是不推荐安装的,编译会出错,但是fileinfo很有用,有些程序需要使用fileinfo,未安装会导致500错误。可以在configiure的时候使用–disable-fileinfo参数来禁止安装,但是没有–enable-fileinfo参数哦。

关于fileinfo手动安装

cd ./ext/fileinfo/
apt install autoconf
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make
make install

最后修改php.ini添加extension=fileinfo即可。

PHP configure参数详细列表

如下,以便速查

~/php/php-7.3.8# ./configure --help
`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]

Optional Features and Packages:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-libdir=NAME      Look for libraries in .../NAME rather than .../lib
  --disable-rpath         Disable passing additional runtime library
                          search paths
  --enable-re2c-cgoto     Enable -g flag to re2c to use computed goto gcc extension
  --disable-gcc-global-regs
                          whether to enable GCC global register variables

SAPI modules:

  --with-apxs2=FILE       Build shared Apache 2.0 Handler module. FILE is the optional
                          pathname to the Apache apxs tool apxs
  --disable-cli           Disable building CLI version of PHP
                          (this forces --without-pear)
  --enable-embed=TYPE     EXPERIMENTAL: Enable building of embedded SAPI library
                          TYPE is either 'shared' or 'static'. TYPE=shared
  --enable-fpm            Enable building of the fpm SAPI executable
  --with-fpm-user=USER    Set the user for php-fpm to run as. (default: nobody)
  --with-fpm-group=GRP    Set the group for php-fpm to run as. For a system user, this
                          should usually be set to match the fpm username (default: nobody)
  --with-fpm-systemd      Activate systemd integration
  --with-fpm-acl          Use POSIX Access Control Lists
  --with-litespeed        Build PHP as litespeed module
  --enable-phpdbg         Build phpdbg
  --enable-phpdbg-webhelper
                          Build phpdbg web SAPI support
  --enable-phpdbg-debug   Build phpdbg in debug mode
  --enable-phpdbg-readline   Enable readline support in phpdbg (depends on static ext/readline)
  --disable-cgi           Disable building CGI version of PHP
  --with-valgrind=DIR     Enable valgrind support

General settings:

  --enable-gcov           Enable GCOV code coverage (requires LTP) - FOR DEVELOPERS ONLY!!
  --enable-debug          Compile with debugging symbols
  --with-layout=TYPE      Set how installed files will be laid out.  Type can
                          be either PHP or GNU [PHP]
  --with-config-file-path=PATH
                          Set the path in which to look for php.ini [PREFIX/lib]
  --with-config-file-scan-dir=PATH
                          Set the path where to scan for configuration files
  --enable-sigchild       Enable PHP's own SIGCHLD handler
  --enable-libgcc         Enable explicitly linking against libgcc
  --disable-short-tags    Disable the short-form <? start tag by default
  --enable-dmalloc        Enable dmalloc
  --disable-ipv6          Disable IPv6 support
  --enable-dtrace         Enable DTrace support
  --enable-fd-setsize     Set size of descriptor sets

Extensions:

  --with-EXTENSION=shared[,PATH]

    NOTE: Not all extensions can be build as 'shared'.

    Example: --with-foobar=shared,/usr/local/foobar/

      o Builds the foobar extension as shared extension.
      o foobar package install prefix is /usr/local/foobar/


  --disable-all           Disable all extensions which are enabled by default

  --disable-libxml        Disable LIBXML support
  --with-libxml-dir=DIR   LIBXML: libxml2 install prefix
  --with-openssl=DIR      Include OpenSSL support (requires OpenSSL >= 1.0.1)
  --with-kerberos=DIR     OPENSSL: Include Kerberos support
  --with-system-ciphers   OPENSSL: Use system default cipher list instead of hardcoded value
  --with-pcre-regex=DIR   Include Perl Compatible Regular Expressions support.
                          DIR is the PCRE install prefix BUNDLED
  --with-pcre-jit         Enable PCRE JIT functionality (BUNDLED only)
  --with-pcre-valgrind=DIR
                          Enable PCRE valgrind support. Developers only!
  --without-sqlite3=DIR   Do not include SQLite3 support. DIR is the prefix to
                          SQLite3 installation directory.
  --with-zlib=DIR         Include ZLIB support (requires zlib >= 1.2.0.4)
  --with-zlib-dir=<DIR>   Define the location of zlib install directory
  --enable-bcmath         Enable bc style precision math functions
  --with-bz2=DIR          Include BZip2 support
  --enable-calendar       Enable support for calendar conversion
  --disable-ctype         Disable ctype functions
  --with-curl=DIR         Include cURL support
  --enable-dba            Build DBA with bundled modules. To build shared DBA
                          extension use --enable-dba=shared
  --with-qdbm=DIR         DBA: QDBM support
  --with-gdbm=DIR         DBA: GDBM support
  --with-ndbm=DIR         DBA: NDBM support
  --with-db4=DIR          DBA: Oracle Berkeley DB 4.x or 5.x support
  --with-db3=DIR          DBA: Oracle Berkeley DB 3.x support
  --with-db2=DIR          DBA: Oracle Berkeley DB 2.x support
  --with-db1=DIR          DBA: Oracle Berkeley DB 1.x support/emulation
  --with-dbm=DIR          DBA: DBM support
  --with-tcadb=DIR        DBA: Tokyo Cabinet abstract DB support
  --with-lmdb=DIR         DBA: Lightning memory-mapped database support
  --without-cdb=DIR       DBA: CDB support (bundled)
  --disable-inifile       DBA: INI support (bundled)
  --disable-flatfile      DBA: FlatFile support (bundled)
  --disable-dom           Disable DOM support
  --with-libxml-dir=DIR   DOM: libxml2 install prefix
  --with-enchant=DIR      Include enchant support.
                          GNU Aspell version 1.1.3 or higher required.
  --enable-exif           Enable EXIF (metadata from images) support
  --disable-fileinfo      Disable fileinfo support
  --disable-filter        Disable input filter support
  --with-pcre-dir         FILTER: pcre install prefix
  --enable-ftp            Enable FTP support
  --with-openssl-dir=DIR  FTP: openssl install prefix
  --with-gd=DIR           Include GD support.  DIR is the GD library base
                          install directory BUNDLED
  --with-webp-dir=DIR     GD: Set the path to libwebp install prefix
  --with-jpeg-dir=DIR     GD: Set the path to libjpeg install prefix
  --with-png-dir=DIR      GD: Set the path to libpng install prefix
  --with-zlib-dir=DIR     GD: Set the path to libz install prefix
  --with-xpm-dir=DIR      GD: Set the path to libXpm install prefix
  --with-freetype-dir=DIR GD: Set the path to FreeType 2 install prefix
  --enable-gd-jis-conv    GD: Enable JIS-mapped Japanese font support
  --with-gettext=DIR      Include GNU gettext support
  --with-gmp=DIR          Include GNU MP support
  --with-mhash=DIR        Include mhash support
  --disable-hash          Disable hash support
  --without-iconv=DIR     Exclude iconv support
  --with-imap=DIR         Include IMAP support. DIR is the c-client install prefix
  --with-kerberos=DIR     IMAP: Include Kerberos support. DIR is the Kerberos install prefix
  --with-imap-ssl=DIR     IMAP: Include SSL support. DIR is the OpenSSL install prefix
  --with-interbase=DIR    Include Firebird support.  DIR is the Firebird base
                          install directory /opt/firebird
  --enable-intl           Enable internationalization support
  --with-icu-dir=DIR      Specify where ICU libraries and headers can be found
  --disable-json          Disable JavaScript Object Serialization support
  --with-ldap=DIR         Include LDAP support
  --with-ldap-sasl=DIR    LDAP: Include Cyrus SASL support
  --enable-mbstring       Enable multibyte string support
  --disable-mbregex       MBSTRING: Disable multibyte regex support
  --disable-mbregex-backtrack
                          MBSTRING: Disable multibyte regex backtrack check
  --with-onig=DIR         MBSTRING: Use external oniguruma. DIR is the oniguruma install prefix.
                          If DIR is not set, the bundled oniguruma will be used
  --with-mysqli=FILE      Include MySQLi support.  FILE is the path
                          to mysql_config.  If no value or mysqlnd is passed
                          as FILE, the MySQL native driver will be used
  --enable-embedded-mysqli
                          MYSQLi: Enable embedded support
                          Note: Does not work with MySQL native driver!
  --with-mysql-sock=SOCKPATH
                          MySQLi/PDO_MYSQL: Location of the MySQL unix socket pointer.
                          If unspecified, the default locations are searched
  --with-oci8=DIR         Include Oracle Database OCI8 support. DIR defaults to $ORACLE_HOME.
                          Use --with-oci8=instantclient,/path/to/instant/client/lib
                          to use an Oracle Instant Client installation
  --with-odbcver=HEX      Force support for the passed ODBC version. A hex number is expected, default 0x0350.
                          Use the special value of 0 to prevent an explicit ODBCVER to be defined.
  --with-adabas=DIR       Include Adabas D support /usr/local
  --with-sapdb=DIR        Include SAP DB support /usr/local
  --with-solid=DIR        Include Solid support /usr/local/solid
  --with-ibm-db2=DIR      Include IBM DB2 support /home/db2inst1/sqllib
  --with-empress=DIR      Include Empress support \$EMPRESSPATH
                          (Empress Version >= 8.60 required)
  --with-empress-bcs=DIR  Include Empress Local Access support \$EMPRESSPATH
                          (Empress Version >= 8.60 required)
  --with-custom-odbc=DIR  Include user defined ODBC support. DIR is ODBC install base
                          directory /usr/local. Make sure to define CUSTOM_ODBC_LIBS and
                          have some odbc.h in your include dirs. f.e. you should define
                          following for Sybase SQL Anywhere 5.5.00 on QNX, prior to
                          running this configure script:
                            CPPFLAGS=\"-DODBC_QNX -DSQLANY_BUG\"
                            LDFLAGS=-lunix
                            CUSTOM_ODBC_LIBS=\"-ldblib -lodbc\"
  --with-iodbc=DIR        Include iODBC support /usr/local
  --with-esoob=DIR        Include Easysoft OOB support /usr/local/easysoft/oob/client
  --with-unixODBC=DIR     Include unixODBC support /usr/local
  --with-dbmaker=DIR      Include DBMaker support
  --disable-opcache       Disable Zend OPcache support
  --disable-opcache-file  Disable file based caching
  --disable-huge-code-pages
                          Disable copying PHP CODE pages into HUGE PAGES
  --enable-pcntl          Enable pcntl support (CLI/CGI only)
  --disable-pdo           Disable PHP Data Objects support
  --with-pdo-dblib=DIR    PDO: DBLIB-DB support.  DIR is the FreeTDS home directory
  --with-pdo-firebird=DIR PDO: Firebird support.  DIR is the Firebird base
                          install directory /opt/firebird
  --with-pdo-mysql=DIR    PDO: MySQL support. DIR is the MySQL base directory
                          If no value or mysqlnd is passed as DIR, the
                          MySQL native driver will be used
  --with-zlib-dir=DIR     PDO_MySQL: Set the path to libz install prefix
  --with-pdo-oci=DIR      PDO: Oracle OCI support. DIR defaults to $ORACLE_HOME.
                          Use --with-pdo-oci=instantclient,/path/to/instant/client/lib
                          for an Oracle Instant Client installation.
  --with-pdo-odbc=flavour,dir
                          PDO: Support for 'flavour' ODBC driver.
			  include and lib dirs are looked for under 'dir'.

			  'flavour' can be one of:  ibm-db2, iODBC, unixODBC, generic
			  If ',dir' part is omitted, default for the flavour
			  you have selected will be used. e.g.:

			    --with-pdo-odbc=unixODBC

			  will check for unixODBC under /usr/local. You may attempt
			  to use an otherwise unsupported driver using the 'generic'
			  flavour.  The syntax for generic ODBC support is:

			    --with-pdo-odbc=generic,dir,libname,ldflags,cflags

			  When built as 'shared' the extension filename is always pdo_odbc.so
  --with-pdo-pgsql=DIR    PDO: PostgreSQL support.  DIR is the PostgreSQL base
                          install directory or the path to pg_config
  --without-pdo-sqlite=DIR
                          PDO: sqlite 3 support.  DIR is the sqlite base
                          install directory BUNDLED
  --with-pgsql=DIR        Include PostgreSQL support.  DIR is the PostgreSQL
                          base install directory or the path to pg_config
  --disable-phar          Disable phar support
  --disable-posix         Disable POSIX-like functions
  --with-pspell=DIR       Include PSPELL support.
                          GNU Aspell version 0.50.0 or higher required
  --with-libedit=DIR      Include libedit readline replacement (CLI/CGI only)
  --with-readline=DIR     Include readline support (CLI/CGI only)
  --with-recode=DIR       Include recode support
  --disable-session       Disable session support
  --with-mm=DIR           SESSION: Include mm support for session storage
  --enable-shmop          Enable shmop support
  --disable-simplexml     Disable SimpleXML support
  --with-libxml-dir=DIR   SimpleXML: libxml2 install prefix
  --with-snmp=DIR         Include SNMP support
  --with-openssl-dir=DIR  SNMP: openssl install prefix
  --enable-soap           Enable SOAP support
  --with-libxml-dir=DIR   SOAP: libxml2 install prefix
  --enable-sockets        Enable sockets support
  --with-sodium=DIR       Include sodium support
  --with-password-argon2=DIR
                          Include Argon2 support in password_*. DIR is the Argon2 shared library path
  --enable-sysvmsg        Enable sysvmsg support
  --enable-sysvsem        Enable System V semaphore support
  --enable-sysvshm        Enable the System V shared memory support
  --with-tidy=DIR         Include TIDY support
  --disable-tokenizer     Disable tokenizer support
  --enable-wddx           Enable WDDX support
  --with-libxml-dir=DIR   WDDX: libxml2 install prefix
  --with-libexpat-dir=DIR WDDX: libexpat dir for XMLRPC-EPI (deprecated)
  --disable-xml           Disable XML support
  --with-libxml-dir=DIR   XML: libxml2 install prefix
  --with-libexpat-dir=DIR XML: libexpat install prefix (deprecated)
  --disable-xmlreader     Disable XMLReader support
  --with-libxml-dir=DIR   XMLReader: libxml2 install prefix
  --with-xmlrpc=DIR       Include XMLRPC-EPI support
  --with-libxml-dir=DIR   XMLRPC-EPI: libxml2 install prefix
  --with-libexpat-dir=DIR XMLRPC-EPI: libexpat dir for XMLRPC-EPI (deprecated)
  --with-iconv-dir=DIR    XMLRPC-EPI: iconv dir for XMLRPC-EPI
  --disable-xmlwriter     Disable XMLWriter support
  --with-libxml-dir=DIR   XMLWriter: libxml2 install prefix
  --with-xsl=DIR          Include XSL support.  DIR is the libxslt base
                          install directory (libxslt >= 1.1.0 required)
  --enable-zend-test      Enable zend-test extension
  --enable-zip            Include Zip read/write support
  --with-zlib-dir=DIR     ZIP: Set the path to libz install prefix
  --with-pcre-dir         ZIP: pcre install prefix
  --with-libzip=DIR       ZIP: use libzip
  --enable-mysqlnd        Enable mysqlnd explicitly, will be done implicitly
                          when required by other extensions
  --disable-mysqlnd-compression-support
                          Disable support for the MySQL compressed protocol in mysqlnd
  --with-zlib-dir=DIR     mysqlnd: Set the path to libz install prefix

PEAR:

  --with-pear=DIR         Install PEAR in DIR [PREFIX/lib/php]
  --without-pear          Do not install PEAR

Zend:

  --enable-maintainer-zts Enable thread safety - for code maintainers only!!
  --disable-inline-optimization
                          If building zend_execute.lo fails, try this switch
  --disable-zend-signals  whether to enable zend signal handling

TSRM:

  --with-tsrm-pth=pth-config
                          Use GNU Pth
  --with-tsrm-st          Use SGI's State Threads
  --with-tsrm-pthreads    Use POSIX threads (default)

Libtool:

  --enable-shared=PKGS    Build shared libraries default=yes
  --enable-static=PKGS    Build static libraries default=yes
  --enable-fast-install=PKGS
                          Optimize for fast installation default=yes
  --with-gnu-ld           Assume the C compiler uses GNU ld default=no
  --disable-libtool-lock  Avoid locking (might break parallel builds)
  --with-pic              Try to use only PIC/non-PIC objects default=use both
  --with-tags=TAGS        Include additional configurations automatic


Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor
  YACC        The `Yet Another Compiler Compiler' implementation to use.
              Defaults to the first program found out of: `bison -y', `byacc',
              `yacc'.
  YFLAGS      The list of arguments that will be passed by default to $YACC.
              This script will default YFLAGS to the empty string to avoid a
              default value of `-d' given by some make applications.
  CXX         C++ compiler command
  CXXFLAGS    C++ compiler flags
  CXXCPP      C++ preprocessor

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to the package provider.

 

 

Rclone配置OneDrive和GoogleDrive

首先安装下载最新版本的Rclone,奶牛建议使用windows来操作,因为OneDrive和GoogleDrive都需要网页授权。

OneDrive 5T版本

rclone config

n) New remote

19 / Microsoft OneDrive
\ "onedrive"

版本教育版和商业版都选择Business即可

GoogleDrive 教育版无限空间

这个首先需要一个国外大学的edu邮箱帐号并且大学支持GoogleDrive的团队盘。使用大学edu的GoogleDrive团队盘创建新的管理员,然后在你需要的Google账户中激活这个团队盘,最后移除edu管理员即可。不知道以后会不会翻车。

rclone config

n) New remote

12 / Google Drive
\ "drive"

不需要设置高级设置,然后选择auth:http://127.0.0.1:53682/auth ,在浏览器打开通过验证就可以了。

Surface Pro 4 安装Kali Linux教程

关于Kali Linux

Kali Linux是基于Debian的Linux发行版, 设计用于数字取证操作系统。由Offensive Security Ltd维护和资助。最先由Offensive Security的Mati Aharoni和Devon Kearns通过重写BackTrack来完成,BackTrack是他们之前写的用于取证的Linux发行版 。
Kali Linux预装了许多渗透测试软件,包括nmap 、Wireshark 、John the Ripper,以及Aircrack-ng.[2] 用户可通过硬盘、live CD或live USB运行Kali Linux。Kali Linux既有32位和64位的镜像。可用于x86 指令集。同时还有基于ARM架构的镜像,可用于树莓派和三星的ARM Chromebook。

Surface Pro 4 设置关闭UEFI和TPM

按音量+键的同时按下开机键,Surface Pro 4 会进入Surface Pro 4的BIOS,在设置中可以关闭UEFI和TPM(貌似不关没法装Linux系统,有验证)

Surface Pro 4 设置U盘启动

同样的方法,按音量+键的同时按下开机键,Surface Pro 4 会进入Surface Pro 4的BIOS,在设置中可以设置从USB启动,这里操作就直接拖动就可以,支持触摸屏操作。

制作Kali Linux安装盘

推荐使用Rufus来进行Kali Linux的U盘制作,并使用DD模式,否则可能无法载入安装,只能进行Live。

Surface Pro 4安装Kali Linux

都是图形界面,就跟Ubuntu这些一样,没啥好说的,也没什么困难。只有一点,就是Windows要提前准备出一些空间,用Windows自带的计算机管理来压缩系统盘,然后就可以生成一些剩余空间来安装Kaili Linux了。

收尾

安装成功就结束了?不不不,不是这样子的,你会发现,你的触摸屏用不了,这个用不了,那个用不了,好吧,奶牛推荐个大神的Git:https://github.com/jakeday/linux-surface

奶牛为啥推荐大神的Git呢,因为看看人家都做了啥:

支持设备:

  • Surface Book
  • Surface Book 2
  • Surface Go
  • Surface Laptop
  • Surface Laptop 2
  • Surface Pro 3
  • Surface Pro 4
  • Surface Pro 2017
  • Surface Pro 6
  • Surface Studio

支持功能:

  • Keyboard (and backlight)
  • Touchpad
  • 2D/3D Acceleration
  • Touchscreen
  • Pen
  • WiFi
  • Bluetooth
  • Speakers
  • Power Button
  • Volume Buttons
  • SD Card Reader
  • Cameras (partial support, disabled for now)
  • Hibernate
  • Sensors (accelerometer, gyroscope, ambient light sensor)
  • Battery Readings
  • Docking/Undocking Tablet and Keyboard
  • Surface Docks
  • DisplayPort
  • USB-C (including for HDMI Out)
  • Dedicated Nvidia GPU (Surface Book 2)

不正常项目:

  • Dedicated Nvidia GPU (if you have a performance base on a Surface Book 1, otherwise onboard works fine)
  • Cameras (not fully supported yet)
  • Connected Standby is not supported yet

这个项目已经把Ubuntu或者Debian的内核更新到了5.1.15-1,可以从https://github.com/jakeday/linux-surface/releases进行下载。当然,人家也提供了一键脚本,https://github.com/jakeday/linux-surface/raw/master/setup.sh,脚本运行需要clone整个项目。具体看看人家的Git应该就能看明白了。

补充下grub分辨率问题,Surface Pro 4 的分辨率有些奇葩,经过配置发现修改/etc/default/grub文件,将

GRUB_GFXMODE=1024x768

然后重新生成grub.conf

grub-mkconfig -o /boot/grub/grub.cfg

重启之后就可以看到一个奶牛觉得比较习惯的Grub界面了。

手动开启BBR方式优化TCP拥堵控制

在Linux的内核中,默认有reno和cubic,还有一些tcp拥堵算法Hybla,比如这里奶牛推荐使用BBR(Bottleneck Bandwidth and RTT)。这里我们需要先将Linux的kenel内核版本升级到4.9+以及5.x,因为kenel 4.9之后才默认加入了bbr的支持。

echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
sysctl -p
reboot

升级内核后执行上面的命令就可以设置bbr为默认了。查看bbr是否设置成功?

sysctl net.ipv4.tcp_available_congestion_control
net.ipv4.tcp_available_congestion_control = bbr cubic reno
sysctl -n net.ipv4.tcp_congestion_control
bbr
lsmod | grep bbr
tcp_bbr                16384  0

 

CentOS 7更新内核至最新版本教程

CentOS跟Ubuntu的使用区别还是有的,比如这个内核,Ubuntu的话直接就可以更新一个比较新的内核了,可是CentOS还是3.1的好像,不知道为啥。好吧,进入教程环节吧。

添加ELRepo源

导入公key

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

添加源,根据系统版本

yum install https://www.elrepo.org/elrepo-release-8.0-1.el8.elrepo.noarch.rpm
yum install https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
yum install https://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm

安装CentOS最新版本kernel内核

yum --enablerepo=elrepo-kernel install kernel-ml -y

这里需要说明一下,ELRepo源有两条内核分支路线,一条是ml(mainline stable),是主线稳定版本,一条是lt(long term support),即长期支持版本,奶牛这里选择的是ml版本,直接更新到kernel5.x了。

最后,就是设置grub和重启了

egrep ^menuentry /etc/grub2.cfg | cut -f 2 -d \'
grub2-set-default 0
reboot
SSH与Linux主机交互文件传输工具lrzsz安装使用教程

以前传文件,奶牛一直是喜欢搭个web,然后直接把服务器文件扔上去然后从本地下载,或者用Bitvise SSH的SFTP工具来传输,直到忘了多久之前看到一个教学视频里面,有直接通过一条命令来传输本地文件到服务器上。最近无意中又看到了这个软件,名字叫lrzsz,推荐搭配Xshell这个SSH工具来使用。

lrzsz安装

CentOS下安装:

yum -y install lrzsz

Ubuntu下安装:

apt-get install lrzsz

lrzsz使用教程

lrzsz分开是两个命令,一个是rz,一个是sz。rz是用来从本地文件传输到服务器端,sz是用来从服务器端拉取文件到本地的。

使用方法也很简单:

sz filename
rz

其中sz后面直接加文件路径或者当前路径下的文件名即可,rz直接回车在Xshell下会直接弹出对话框来选择需要上传的文件的。

CloudFlare CDN下Nginx正确获取真实IP教程

说到获取真实IP,我们不难想到nginx的http realip module,就是当遇到IP是设定范围内的地址时,就逆向递归获取源目标的真实IP。对于Cloudflare CDN而言,也是遵从行业标准的,即使用X-Forwarded-For header 和 CF-Connecting-IP header 。Cloudflare的真实IP地址可以从这里获取Cloudflare IP addresses,当然我们也可以查看文本格式的Cloudflare的IP段:

https://www.cloudflare.com/ips-v4
https://www.cloudflare.com/ips-v6

官方建议还是要定期更新这个IP范围的,以免范围改动影响使用效果。

奶牛找到了一个别人写好的sh脚本,可以自动生成一个Cloudflare真实IP的conf。

#!/bin/bash
echo "#Cloudflare" > /usr/local/nginx/conf/cloudflare_ip.conf;
for i in `curl https://www.cloudflare.com/ips-v4`; do
        echo "set_real_ip_from $i;" >> /usr/local/nginx/conf/cloudflare_ip.conf;
done
for i in `curl https://www.cloudflare.com/ips-v6`; do
        echo "set_real_ip_from $i;" >> /usr/local/nginx/conf/cloudflare_ip.conf;
done
echo "" >> /usr/local/nginx/conf/cloudflare_ip.conf;
echo "# use any of the following two" >> /usr/local/nginx/conf/cloudflare_ip.conf;
echo "real_ip_header CF-Connecting-IP;" >> /usr/local/nginx/conf/cloudflare_ip.conf;
echo "#real_ip_header X-Forwarded-For;" >> /usr/local/nginx/conf/cloudflare_ip.conf;

运行脚本后,我们可以得到一个/usr/local/nginx/conf/cloudflare_ip.conf的conf文件,在网站所在的nginx conf中添加字段:

include /usr/local/nginx/conf/cloudflare_ip.conf;

即可,添加完成后使用nginx t来验证配置文件是否正确,正确无误后重启或者重新载入nginx即可。

也可以使用cron计划任务来定期更新cloudflare_ip.conf文件。

0 5 * * 1 /bin/bash /location/to/update_cf_ip.sh

这样子就可以在每周1的5点进行自动更新Cloudflare的IP conf文件了。如果使用配置文件中的X-Forwarded-For参数,理论上对所有的执行标准的CDN都是有效的。

PHP7环境下使用OPcache提高WordPress网站性能8倍

奶牛一直以为自己的服务器都开了OPcache,但是后来发现只是编译了,但是没有启用,今天启用了PHP7的OPcache,来发一份儿体验报告。

配置OPcache

配置文件为/usr/local/php/etc/php.ini,添加内容

[zend opcache]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/opcache.so"
opcache.force_restart_timeout=3600
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable=1
opcache.enable_cli=1

其中的zend_extension为你服务器编译后opcache.so文件的位置。

OPcache性能测试

载入时间数据比较:

OPcache载入时间比较

性能比较:

OPcache性能比较

测试结论

经过奶牛的测试,在服务器未启用WordPress cache插件的时候,CPU的飙升是非常厉害的,严重影响服务器性能,因此无WordPress插件的情况下,并未完全遵从1000次测试,但是图表已经完全可以说明性能的比较了。

WordPress的cache插件对网站性能提升至关重要,OPcache的存在也能最大性能的提升WordPress服务器的性能,对比而言,OPcache可以提升PHP7约3倍的性能,WordPress的cache插件可以提升约4~5倍的性能,WordPress启用cache插件并且在PHP7下启用OPcache,性能提升8倍。

所以,奶牛强烈建议WordPress的用户使用PHP7并开启OPcache,并且为WordPress安装一款cache插件,保证服务器的性能最优。

Linux下使用tar进行差异备份

说实话,奶牛这些年来一直都是手动完整备份文件,而且每次都是完整备份,其实很早之前就知道有增量备份这种东西了,可能是不太习惯吧,还是一直都是完整备份。今天就记录下tar进行差异备份和增量备份的一些心得。

首先说怎么做一个完整的备份

tar -czvf filename.tgz filename

这是普通的打包命令,没什么特别,下面我们使用一个-g参数

tar -g snapshot -czvf filename.tgz filename

执行完成后会生成一个snapshot文件,里面记录着备份信息。

这里插个分割线,说说增量备份和差异备份。

如果我们想进行增量备份,那么这个snapshot就需要一直更新,每次增量过后这个snapshot文件都会发生改变,如果我们需要还原,则需要把所有增量备份和完整备份一起还原。

如果我们想进行差异备份,那么我们需要把这个snapshot保护起来,然后每次都做针对完整备份的增量备份,那么恢复的时候我们只需要把最后一次增量备份和完整备份一起还原。

优缺点:增量备份占用的空间要小于差异备份,但是恢复起来非常麻烦,特别是比如一个月内只做一次完整备份,其它每天只做增量备份,那么恢复的时候要恢复很多个增量备份文件。

差异备份占用空间要比增量备份大一些,但是如果备份文件修改较少,则差异备份的文件也不会很大,恢复的时候只需要恢复完整备份和差异备份即可,工作量会小很多。

好了,回归正题,我们这里就讲差异备份,增量备份网上一堆参考,不多介绍了。

cp snapshot snapshot.backup
tar -g snapshot -czvf filename-1.tgz filename
mv snapshot snapshot-1.backup
cp snapshot.backup snapshot

这样一来,我们就在snapshot-1.backup中记录了这次差异备份的变化信息了,然后差异备份文件是filename-1.tgz

如果我们要备份的文件或目录里面存在软链接,而我们又需要备份其中软链接对应的文件或目录的源文件,我们则需要增加一个-h属性

tar -czvhf filename.tgz filename

查看tgz文件内容

tar -tvf filename.tgz

好了,奶牛今天的记录至此。

Comodo Positive SSL申请过程

黑五过去了,留下了一些折腾。不过还好,今天蛮有收获的。

说下Comodo Positive SSL到底怎么申请怎么用。对于Nginx用户来说,添加SSL就需要两个文件,一个是private.key,一个是domain.cer。其中private.key是我们自己生成的,cer是得花钱买的,当然也可以自己签,但是自己签的浏览器不认。

private.key的生成我们需要了解一个东西叫CSR。根据百科的内容是这样介绍的:

CSR是Certificate Signing Request的英文缩写,即证书请求文件,也就是证书申请者在申请数字证书时由CSP(加密服务提供者)在生成私钥的同时也生成证书请求文件,证书申请者只要把CSR文件提交给证书颁发机构后,证书颁发机构使用其根证书私钥签名就生成了证书公钥文件,也就是颁发给用户的证书。

生成private.key的方法很多,奶牛就不介绍了,使用linux或者windows下的签名软件生成,或者现在已经有很多网站支持在线生成CSR了,直接生成就可以。生成完成后我们得到csr.cer和private.key两个文件。

然后我们需要将csr.cer的内容提交给Comodo,然后需要一个验证过程,叫Domain Control Validation (DCV) 。这个验证过程有几种方式:

1.邮件,但是需要域名的[email protected]的邮箱可以接收邮件,这个比较麻烦,pass掉。

2.dns,这个可以,添加一个记录即可。

3.http文件,这个需要你下载他们的验证文件,然后使http://domain.com/.well-known/pki-validation/file.txt可以验证这个文件,这个方案也可以。

验证通过后就可以得到domain.cer了,然后修改nginx的conf文件增加ssl证书即可。