PHP7.3を関連ライブラリと共にインストール（ソースからコンパイル）for Apache2.4+CentOS8

##はじめに
PHPは、様々なライブラリがあり大変便利ですが、コンパイル時にはそのライブラリを含めてビルドする必要があります。
PHP7とよく使うであろうGD周りを含めたコンパイルの一式の作業メモです。
処理部分をまとめていますので、必要に応じてコピペすればほぼ無操作で、PHP7が稼働する環境が作れます。

##あらかじめApacheのインストールが必要です
Apacheのインストールに関しては以下を参考にしてあらかじめインストールが必要です。
[Apache2.4をインストールする(ソースからコンパイル) for CentOS7.2](http://qiita.com/shadowhat/items/163ee5fdd56c51100e9e)

##以下のライブラリの事前インストールが必要です。
コンパイルオプションを適宜変更していただければ構いませんが、投稿で以下のライブラリが事前にインストールされている前提になっています。
インストール手順はリンクを参考にしてください。
[OpenSSL1.0](http://qiita.com/shadowhat/items/68fd55b532c04b13acf5)
[libssh2](http://qiita.com/shadowhat/items/7122eec16161956dc484)
[zlib](http://qiita.com/shadowhat/items/867d9e06bc42cf862b9a)


##今回採用するライブラリ群
| プログラム名 | バージョン |
|:--|:-:|
| JPEG | v9c |
| FreeType  | 2.10.1  |
|  libPNG |  1.6.37 |
| zlib  | 1.2.11  |
|  m4 | 1.4.18 |
| autoconf  |  2.69 |
|  libiconv |  1.15 |
|  xml |  2.9.9 |
|  libGD | 2.3.0  |
|  libmcrypt |  2.5.8(廃止) |
|  imap(c-client) |  2007f |
| curl | curl-7.69.1 |
| libpng | 1.6.34 |
| libtiff | 4.1.0 |


※必要に応じてMySQLやPostgreSQLも追加可能です

##実践環境
| 環境 | バージョン |
|:-:|:-:|
|  PHP | 7.3.17  |
| OS | CentOS 8.1(7.2/7.3/7.4も確認済み) |

##OS標準のバイナリをインストールする
xorg-x11-proto-devel-7.7-13.el7.noarch.rpm
libXpm-devel-3.5.11-3.el7.x86_64.rpm
libX11-devel-1.6.3-3.el7.x86_64.rpm
pam-devel-1.1.8-18.el8.x86_64.rpm


##関係ライブラリをダウンロードする
```bash:
#バイナリダウンロード
mkdir -p /usr/local/src/phpmodule
cd /usr/local/src/phpmodule
#JPEG
cd /usr/local/src/phpmodule
wget http://www.ijg.org/files/jpegsrc.v9d.tar.gz
tar xvzf jpegsrc.v9d.tar.gz

#FreeType
wget https://download.savannah.gnu.org/releases/freetype/freetype-2.10.1.tar.gz
tar xvzf freetype-2.10.1.tar.gz

#libPNG
wget --trust-server-names  https://downloads.sourceforge.net/project/libpng/libpng16/1.6.37/libpng-1.6.37.tar.gz?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Flibpng%2Ffiles%2Flibpng16%2F1.6.37%2Flibpng-1.6.37.tar.gz%2Fdownload&ts=1587360521
tar xvzf libpng-1.6.37.tar.gz

#zlib
dbf install zlib-devel
#wget http://zlib.net/zlib-1.2.11.tar.gz
#tar xvzf zlib-1.2.11.tar.gz

#m4
wget http://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.gz
tar xvzf m4-1.4.18.tar.gz

#autoconf
#wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
#tar xvzf autoconf-2.69.tar.gz

#libiconv
#wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
#tar xvzf libiconv-1.16.tar.gz

#xml
wget ftp://xmlsoft.org/libxml2/libxml2-2.9.9.tar.gz
tar xvzf libxml2-2.9.9.tar.gz

#libGD
wget -O libgd-2.3.0.tar.gz https://github.com/libgd/libgd/releases/download/gd-2.3.0/libgd-2.3.0.tar.gz
tar xvzf libgd-2.3.0.tar.gz

#libmcrypt
#wget --trust-server-names #https://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fmcrypt%2Ffiles%2FLibmcrypt%2F2.5.8%2Flibmcrypt-2.5.8.tar.gz%2Fdownload&ts=1587361084
#tar xvzf libmcrypt-2.5.8.tar.gz

#imap
#wget ftp://ftp.cac.washington.edu/imap/imap-2007f.tar.gz
#ミラーサイトを利用
wget http://ftp.ntua.gr/pub/net/mail/imap/imap-2007f.tar.gz
tar xvzf imap-2007f.tar.gz

#curl
wget https://curl.haxx.se/download/curl-7.69.1.tar.gz
tar xvzf curl-7.69.1.tar.gz

#libpng
wget ftp://ftp-osl.osuosl.org/pub/libpng/src/libpng16/libpng-1.6.34.tar.gz
tar xvzf libpng-1.6.34.tar.gz

#libtiff
wget http://download.osgeo.org/libtiff/tiff-4.1.0.tar.gz
tar xvzf tiff-4.1.0.tar.gz

#SQLite3
wget https://www.sqlite.org/2020/sqlite-autoconf-3310100.tar.gz
tar xvzf sqlite-autoconf-3310100.tar.gz

#Oniguruma
https://github.com/kkos/oniguruma　からダウンロード
unzip oniguruma-master.zip

#libzip
wget https://libzip.org/download/libzip-1.6.1.tar.gz
tar xvzf libzip-1.6.1.tar.gz

#libwebp
wget https://github.com/webmproject/libwebp/archive/master.zip
unzip libwebp-master.zip

```

###各モジュールをコンパイルする

```bash
#JPEG
cd /usr/local/src/phpmodule
cd jpeg-9d
./configure --enable-shared
make
make install

#libtiff
cd /usr/local/src/phpmodule
cd tiff-4.1.0
./configure
make
make install

#FreeType
cd /usr/local/src/phpmodule
cd freetype-2.10.1
./configure --enable-static
make
make install

#phpから参照できるようにシンボリックリンクを作成する
ln -s /usr/local/include/freetype2/freetype /usr/local/include/freetype
ln -s /usr/local/include/freetype2/ft2build.h /usr/local/include/ft2build.h


#libPNG
cd /usr/local/src/phpmodule
cd libpng-1.6.37
cp scripts/makefile.linux Makefile
./configure --prefix=/usr/local LDFLAGS="-L/usr/local/lib -lz"
make
make install


#zlib
cd /usr/local/src/phpmodule
cd zlib-1.2.11
./configure
make
make install


#m4
cd /usr/local/src/phpmodule
cd m4-1.4.18
```
m4が、CentOS8では、コンパイルできない場合、以下のパッチを適用する
(参考）http://git.openembedded.org/openembedded-core/plain/meta/recipes-devtools/m4/m4/m4-1.4.18-glibc-change-work-around.patch

``` m4-1.4.18-glibc-change-work-around.patch
cat > m4-1.4.18-glibc-change-work-around.patch << EOF
update for glibc libio.h removal in 2.28+

see
https://src.fedoraproject.org/rpms/m4/c/814d592134fad36df757f9a61422d164ea2c6c9b?branch=master

Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=4af4a4a718]
Signed-off-by: Khem Raj <raj.khem@gmail.com>

Index: m4-1.4.18/lib/fflush.c
===================================================================
--- m4-1.4.18.orig/lib/fflush.c
+++ m4-1.4.18/lib/fflush.c
@@ -33,7 +33,7 @@
 #undef fflush
 
 
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
 
 /* Clear the stream's ungetc buffer, preserving the value of ftello (fp).  */
 static void
@@ -72,7 +72,7 @@ clear_ungetc_buffer (FILE *fp)
 
 #endif
 
-#if ! (defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
+#if ! (defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
 
 # if (defined __sferror || defined __DragonFly__ || defined __ANDROID__) && defined __SNPT
 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Android */
@@ -148,7 +148,7 @@ rpl_fflush (FILE *stream)
   if (stream == NULL || ! freading (stream))
     return fflush (stream);
 
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
 
   clear_ungetc_buffer_preserving_position (stream);
 
Index: m4-1.4.18/lib/fpending.c
===================================================================
--- m4-1.4.18.orig/lib/fpending.c
+++ m4-1.4.18/lib/fpending.c
@@ -32,7 +32,7 @@ __fpending (FILE *fp)
   /* Most systems provide FILE as a struct and the necessary bitmask in
      <stdio.h>, because they need it for implementing getc() and putc() as
      fast macros.  */
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
   return fp->_IO_write_ptr - fp->_IO_write_base;
 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
   /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Android */
Index: m4-1.4.18/lib/fpurge.c
===================================================================
--- m4-1.4.18.orig/lib/fpurge.c
+++ m4-1.4.18/lib/fpurge.c
@@ -62,7 +62,7 @@ fpurge (FILE *fp)
   /* Most systems provide FILE as a struct and the necessary bitmask in
      <stdio.h>, because they need it for implementing getc() and putc() as
      fast macros.  */
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
   fp->_IO_read_end = fp->_IO_read_ptr;
   fp->_IO_write_ptr = fp->_IO_write_base;
   /* Avoid memory leak when there is an active ungetc buffer.  */
Index: m4-1.4.18/lib/freadahead.c
===================================================================
--- m4-1.4.18.orig/lib/freadahead.c
+++ m4-1.4.18/lib/freadahead.c
@@ -25,7 +25,7 @@
 size_t
 freadahead (FILE *fp)
 {
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
   if (fp->_IO_write_ptr > fp->_IO_write_base)
     return 0;
   return (fp->_IO_read_end - fp->_IO_read_ptr)
Index: m4-1.4.18/lib/freading.c
===================================================================
--- m4-1.4.18.orig/lib/freading.c
+++ m4-1.4.18/lib/freading.c
@@ -31,7 +31,7 @@ freading (FILE *fp)
   /* Most systems provide FILE as a struct and the necessary bitmask in
      <stdio.h>, because they need it for implementing getc() and putc() as
      fast macros.  */
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
   return ((fp->_flags & _IO_NO_WRITES) != 0
           || ((fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0
               && fp->_IO_read_base != NULL));
Index: m4-1.4.18/lib/fseeko.c
===================================================================
--- m4-1.4.18.orig/lib/fseeko.c
+++ m4-1.4.18/lib/fseeko.c
@@ -47,7 +47,7 @@ fseeko (FILE *fp, off_t offset, int when
 #endif
 
   /* These tests are based on fpurge.c.  */
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
   if (fp->_IO_read_end == fp->_IO_read_ptr
       && fp->_IO_write_ptr == fp->_IO_write_base
       && fp->_IO_save_base == NULL)
@@ -123,7 +123,7 @@ fseeko (FILE *fp, off_t offset, int when
           return -1;
         }
 
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
       fp->_flags &= ~_IO_EOF_SEEN;
       fp->_offset = pos;
 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
Index: m4-1.4.18/lib/stdio-impl.h
===================================================================
--- m4-1.4.18.orig/lib/stdio-impl.h
+++ m4-1.4.18/lib/stdio-impl.h
@@ -18,6 +18,12 @@
    the same implementation of stdio extension API, except that some fields
    have different naming conventions, or their access requires some casts.  */
 
+/* Glibc 2.28 made _IO_IN_BACKUP private.  For now, work around this
+   problem by defining it ourselves.  FIXME: Do not rely on glibc
+   internals.  */
+#if !defined _IO_IN_BACKUP && defined _IO_EOF_SEEN
+# define _IO_IN_BACKUP 0x100
+#endif
 
 /* BSD stdio derived implementations.  */

EOF
```


```
#m4
cd /usr/local/src/phpmodule
cd m4-1.4.18

#パッチを適用する
patch -p1 < m4-1.4.18-glibc-change-work-around.patch
./configure
make
make install


#autoconf
#cd /usr/local/src/phpmodule
#cd autoconf-2.69
#./configure
#make
#make install


#libiconv
#cd /usr/local/src/phpmodule
#cd libiconv-1.16
#./configure
#make
#make install

```

### libiconvで以下のエラーが出る場合

```
In file included from progname.c:26:0:
./stdio.h:1010:1: error: 'gets' undeclared here (not in a function)
 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
```

その場合は、以下のファイルを編集する

```bash:
vi srclib/stdio.h
```

「_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");」
の箇所を確認し、以下のように変更する

```c:
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif
```

続き

```bash:

#libxml
cd /usr/local/src/phpmodule
cd libxml2-2.9.9
./configure --with-python=no
make
make install
ln -s /usr/local/include/libxml2/libxml /usr/local/include/libxml


#libGD
cd /usr/local/src/phpmodule
cd libgd-2.3.0
#cp scripts/makefile.linux Makefile
./configure \
--with-png=/usr/local \
--with-freetype=/usr/local \
--with-jpeg=/usr/local \
--with-xpm=/usr \
--with-libiconv-prefix=/usr/local \
--disable-werror
make
make install

##もし、libgdのmakeで「gdft.c:154:22: 致命的エラー: ft2build.h:」こける場合は、
##yum install fontconfig-devel
##を実行後、再度、configureからやり直す

#mcrypt
cd /usr/local/src/phpmodule
cd libmcrypt-2.5.8
./configure
make
make install
cd libltdl
./configure --enable-ltdl-install
make
make install


#imap
#OPENSSLが1.1系の場合は以下のパッチを当てる
cd /usr/local/src/phpmodule
cd imap-2007f
wget https://raw.githubusercontent.com/openwrt/packages/master/libs/uw-imap/patches/010-imap-2007f-openssl-1.1.patch
```

パッチがない場合はこちらを利用する

```010-imap-2007f-openssl-1.1.patch
cat > 010-imap-2007f-openssl-1.1.patch << EOF
From c3f68d987c00284d91ad6599a013b7111662545b Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Date: Fri, 2 Sep 2016 21:33:33 +0000
Subject: [PATCH] uw-imap: compile against openssl 1.1.0

I *think* I replaced access to cert->name with certificate's subject name. I
assume that the re-aranged C-code is doing the same thing. A double check
wouldn't hurt :)

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
 src/osdep/unix/ssl_unix.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/osdep/unix/ssl_unix.c b/src/osdep/unix/ssl_unix.c
index 3bfdff3..836e9fa 100644
--- a/src/osdep/unix/ssl_unix.c
+++ b/src/osdep/unix/ssl_unix.c
@@ -59,7 +59,7 @@ typedef struct ssl_stream {
 static SSLSTREAM *ssl_start(TCPSTREAM *tstream,char *host,unsigned long flags);
 static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags);
 static int ssl_open_verify (int ok,X509_STORE_CTX *ctx);
-static char *ssl_validate_cert (X509 *cert,char *host);
+static char *ssl_validate_cert (X509 *cert,char *host, char *cert_subj);
 static long ssl_compare_hostnames (unsigned char *s,unsigned char *pat);
 static char *ssl_getline_work (SSLSTREAM *stream,unsigned long *size,
 			       long *contd);
@@ -210,6 +210,7 @@ static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags)
   BIO *bio;
   X509 *cert;
   unsigned long sl,tl;
+  char cert_subj[250];
   char *s,*t,*err,tmp[MAILTMPLEN];
   sslcertificatequery_t scq =
     (sslcertificatequery_t) mail_parameters (NIL,GET_SSLCERTIFICATEQUERY,NIL);
@@ -266,14 +267,19 @@ static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags)
   if (SSL_write (stream->con,"",0) < 0)
     return ssl_last_error ? ssl_last_error : "SSL negotiation failed";
 				/* need to validate host names? */
-  if (!(flags & NET_NOVALIDATECERT) &&
-      (err = ssl_validate_cert (cert = SSL_get_peer_certificate (stream->con),
-				host))) {
-				/* application callback */
-    if (scq) return (*scq) (err,host,cert ? cert->name : "???") ? NIL : "";
+  if (!(flags & NET_NOVALIDATECERT)) {
+
+	cert_subj[0] = '\0';
+	cert = SSL_get_peer_certificate(stream->con);
+	if (cert)
+		X509_NAME_oneline(X509_get_subject_name(cert), cert_subj, sizeof(cert_subj));
+	err = ssl_validate_cert (cert, host, cert_subj);
+	if (err)
+		/* application callback */
+		if (scq) return (*scq) (err,host,cert ? cert_subj : "???") ? NIL : "";
 				/* error message to return via mm_log() */
-    sprintf (tmp,"*%.128s: %.255s",err,cert ? cert->name : "???");
-    return ssl_last_error = cpystr (tmp);
+	sprintf (tmp,"*%.128s: %.255s",err,cert ? cert_subj : "???");
+	return ssl_last_error = cpystr (tmp);
   }
   return NIL;
 }
@@ -313,7 +319,7 @@ static int ssl_open_verify (int ok,X509_STORE_CTX *ctx)
  * Returns: NIL if validated, else string of error message
  */
 
-static char *ssl_validate_cert (X509 *cert,char *host)
+static char *ssl_validate_cert (X509 *cert,char *host, char *cert_subj)
 {
   int i,n;
   char *s,*t,*ret;
@@ -322,9 +328,9 @@ static char *ssl_validate_cert (X509 *cert,char *host)
 				/* make sure have a certificate */
   if (!cert) ret = "No certificate from server";
 				/* and that it has a name */
-  else if (!cert->name) ret = "No name in certificate";
+  else if (cert_subj[0] == '\0') ret = "No name in certificate";
 				/* locate CN */
-  else if (s = strstr (cert->name,"/CN=")) {
+  else if (s = strstr (cert_subj,"/CN=")) {
     if (t = strchr (s += 4,'/')) *t = '\0';
 				/* host name matches pattern? */
     ret = ssl_compare_hostnames (host,s) ? NIL :
-- 
2.9.3

EOF
```

```
## 「osdep.c:89:31: 致命的エラー: security/pam_appl.h: そのようなファイルやディレクトリはありません」が出る場合は、
## rpm -ivh pam-devel-1.1.8-18.el7.x86_64.rpm
cd /usr/local/src/phpmodule
cd imap-2007f

#OpenSSL1.1.xの場合のみ
patch -p1 < 010-imap-2007f-openssl-1.1.patch
make lnp SSLTYPE=unix EXTRACFLAGS=-fPIC
y

#ソースをコピー
cp -p c-client/*.h /usr/include
cp c-client/c-client.a  /usr/lib/libc-client.a


#curl
cd /usr/local/src/phpmodule
cd curl-7.69.1

#OpenSSLの場所を明示
CPPFLAGS="-I/usr/local/ssl/include" LDFLAGS="-L/usr/local/ssl/lib"

./configure \
--enable-http \
--enable-ftp \
--enable-file \
--enable-proxy \
--enable-cookies \
--with-zlib=/usr/local \
--with-ssl=/usr/local/ssl \
--with-libssh2=/usr/local

make
make install

#libwebp
cd /usr/local/src/phpmodule
cd libwebp-master
./autogen.sh
./configure
make 
make install


#SQLite3
cd /usr/local/src/phpmodule
cd sqlite-autoconf-3310100
./configure
make
make install

#Oniguruma
cd /usr/local/src/phpmodule
cd oniguruma-master
autoreconf -vfi
./configure
make
make install


#libzip
cd /usr/local/src/phpmodule
cd libzip-1.6.1
mkdir build
cd build
cmake ..
make
make test
make install
```


##PHPをインストールする


```
cd /usr/local/src
wget --trust-server-names https://www.php.net/distributions/php-7.3.17.tar.gz
tar xvzf php-7.3.17.tar.gz
cd php-7.3.17


./configure \
--enable-mbstring \
--enable-mbregex \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-gd=/usr/local \
--with-freetype-dir=/usr/local/src/phpmodule/freetype-2.10.1 \
--with-jpeg-dir=/usr/local/lib \
--with-png-dir=/usr/local \
--with-zlib-dir=/usr \
--with-iconv-dir=/usr/local \
--with-libxml-dir=/usr/local \
--enable-gd-jis-conv \
--enable-zip \
--with-curl=/usr/local \
--enable-bcmath \
--enable-sockets \
--enable-ftp \
--enable-opcache=no \
--with-openssl=/usr/local/ssl \
--with-xpm-dir=/usr \
--with-gettext \
--with-imap=/usr/local/src/phpmodule/imap-2007f \
--with-imap-ssl=/usr/local/ssl \
#
#PGSQLを入れる場合
#--with-pgsql=/usr/local/pgsql \
#--with-pdo-pgsql=/usr/local/pgsql
#
#MySQL(MariaDB)を入れる場合
#--with-mysqli=/usr/local/mysql/bin/mysql_config \
#--with-pdo-mysql=/usr/local/mysql \
##CentOS6以前=--with-mysql-sock=/tmp/mysql.sock
#--with-mysql-sock=/run/mariadb/mysql.sock

#以下は廃止
#--with-mcrypt=/usr/local 
#--enable-gd-native-ttf 
#--with-tiff-dir=/usr/local 


make
make install
```
####以下のようなエラーが出る場合

```bash:
In file included from /usr/local/src/php-7.1.0/ext/gd/gd_compat.c:13:0:
/usr/local/include/jpeglib.h:974:30: error: unknown type name 'FILE'
 EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
                              ^
/usr/local/include/jpeglib.h:975:29: error: unknown type name 'FILE'
 EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
```

この場合、jpeglib.hを編集し、「#include "jmorecfg.h" 」の下に、「#include \<stdio.h>」を追加する


```bash:
vi /usr/local/include/jpeglib.h
```

以下のを追加

```c:
#include "jmorecfg.h"           /* seldom changed options */
#include <stdio.h>
//↑これを追加する
```



###DBに対応する場合
PostgreSQLに対応する場合

```bash:
--with-pgsql=/usr/local/pgsql \
--with-pdo-pgsql=/usr/local/pgsql
```

MySQL対応する場合

```bash:
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock
```

##設定を行う

```bash:
cp php.ini-production /usr/local/lib/php.ini
```

httpd.confにphpファイルを実行されるように設定します

```
vi /usr/local/apache2/conf/httpd.conf
```

LoadModule php7_module        modules/libphp7.so
の下に「AddType application/x-httpd-php .php」を記入する

```bash:httpd.copf
LoadModule php7_module        modules/libphp7.so
#↓追加する
AddType application/x-httpd-php .php
```

を追記して保存終了します。


##phpinfoを出す

```
vi /usr/local/apache2/htdocs/phpinfo.php
```

以下の内容を張り付けて保存終了

```php:phpinfo
<?php
  date_default_timezone_set("Asia/Tokyo");
  phpinfo();
?>
```

Apacheを再起動後、phpinfo.phpを開き以下のような画面が出ればOK
![image](https://qiita-image-store.s3.amazonaws.com/0/85495/8cf788a9-e06b-101c-17cd-660683775d91.png)


###参考文献
http://www.itkb.ro/kb/linux/patch-libiconv-pentru-glibc-216
https://travis-ci.org/libgd/libgd/jobs/151123674/config
https://github.com/libgd/libgd/issues/292