03月31, 2018

Linux编译安装PHP

通过源码进行编译安装很简单,不过选择编译设置是一个很头疼的问题。由于我对XAMPP非常熟悉,因此这里我对XAMPP编译出的PHP,使用phpinfo得到它的编译设置,这样不容易踩坑。

我得到的编译设置如下:

./configure --prefix=安装路径 --with-config-file-path=configure文件的存放路径 --with-apxs2 --with-mysql=mysqlnd --enable-inline-optimization --disable-debug --enable-bcmath --enable-calendar --enable-ctype --enable-ftp --enable-gd-native-ttf --enable-magic-quotes --enable-shmop --disable-sigchild --enable-sysvsem --enable-sysvshm --enable-wddx --with-gdbm --with-jpeg-dir --with-png-dir --with-freetype-dir --with-zlib=yes --with-zlib-dir --with-openssl --with-xsl --with-ldap --with-gd --with-imap --with-imap-ssl --with-gettext --with-mssql=shared --with-pdo-dblib=shared --with-sybase-ct --with-mysql-sock --with-mcrypt --with-mhash --enable-sockets --enable-mbstring=all --with-curl --enable-mbregex --enable-zend-multibyte --enable-exif --with-bz2 --with-sqlite=shared --with-sqlite3 --with-libxml-dir --enable-soap --with-xmlrpc --enable-pcntl --with-mysqli=mysqlnd --with-pgsql=shared --with-iconv --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pdo_sqlite --with-icu-dir --enable-fileinfo --enable-phar --enable-zip --enable-intl --disable-huge-code-pages

不过它其实也有点问题,估计有些选项是给编译PHP5用的,所以有些会被废弃了或者直接就不被识别。我编译php-7.2.4会提示configure: WARNING: unrecognized options: --with-mysql, --enable-gd-native-ttf, --enable-magic-quotes, --with-mssql, --with-sybase-ct, --with-mcrypt, --enable-zend-multibyte, --with-sqlite

然后在configure过程中可能会遇到报错,很可能是库没安装或者版本/设置有问题,有root权限的话装起来就比较容易,可以直接在源里装。不过,如果不用那个库的话,最简单的方法就是去掉那个库的支持。例如我编译的时候就遇到了configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.,是因为IMAP库有问题造成的。其实我也用不上,所以就直接去掉了--with-imap --with-imap-ssl。除了这个,我还去掉了--with-icu-dir--enable-intl--with-ldap--with-pdo-dblib=shared--with-apxs2。(我是单独用PHP作为脚本语言使用,没有用MySQL、Apache等)

其中,默认的php.ini路径是在PREFIX/lib下。

我最后使用的编译设置如下:

./configure --prefix=安装路径 --with-config-file-path=configure文件的存放路径 --with-mysql=mysqlnd --enable-inline-optimization --disable-debug --enable-bcmath --enable-calendar --enable-ctype --enable-ftp --enable-gd-native-ttf --enable-magic-quotes --enable-shmop --disable-sigchild --enable-sysvsem --enable-sysvshm --enable-wddx --with-gdbm --with-jpeg-dir --with-png-dir --with-freetype-dir --with-zlib=yes --with-zlib-dir --with-openssl --with-xsl --with-gd --with-gettext --with-mssql=shared --with-sybase-ct --with-mysql-sock --with-mcrypt --with-mhash --enable-sockets --enable-mbstring=all --with-curl --enable-mbregex --enable-zend-multibyte --enable-exif --with-bz2 --with-sqlite=shared --with-sqlite3 --with-libxml-dir --enable-soap --with-xmlrpc --enable-pcntl --with-mysqli=mysqlnd --with-pgsql=shared --with-iconv --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pdo_sqlite  --enable-fileinfo --enable-phar --enable-zip --disable-huge-code-pages

注意:需要在其中修改一下路径。

然后make -jmake install编译安装一下。

最后复制源码中给的php.ini到指定的目录中。

本文链接:https://debug.fanzheng.org/post/compile-and-install-PHP-on-linux.html

-- EOF --

Comments

评论加载中...

注:如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理。