Skip to content

Instantly share code, notes, and snippets.

@graphis
Forked from rizalp/phpbuild.md
Created July 23, 2020 15:20
Show Gist options
  • Save graphis/0ef3c3d0c0800dc628b5fef18be93a4d to your computer and use it in GitHub Desktop.
Save graphis/0ef3c3d0c0800dc628b5fef18be93a4d to your computer and use it in GitHub Desktop.
Minimal Build of PHP 7.4.5, linked with sqlite3 from source on Ubuntu 18.04 And Macos

Why?

  • Minimal PHP system needed to run CRUD symfony app
  • Better understanding of PHP configurations
  • Newer sqlite support, like window functions and JSON1 extension

Adapted from

Install build tools & PHP Core dependencies

Ubuntu

sudo apt-get install build-essential \
autoconf \
libtool \
bison \
re2c \
libxml2-dev \
libonig-dev \
libssl-dev \
libargon2-0-dev \
libsodium-dev \
libcurl4-openssl-dev \
libreadline-dev \
libyaml-dev \
libgmp-dev

Download sqlite3 from https://www.sqlite.org/download.html. Download the source code with -autoconf file which contains the configure scripts. Extract and cd into the extracted directory

./configure --prefix=$HOME/package/sqlite-3.32.2 

make

make install

Configure And Compile PHP

Download PHP https://www.php.net/distributions/php-7.4.6.tar.xz, then adjusting the sqlite pkg-config and ldflags as needed

PKG_CONFIG_PATH="$HOME/package/sqlite-3.32.1/lib/pkgconfig" \
LDFLAGS="-L/$HOME/package/sqlite-3.32.1/lib" \
./configure \
--prefix=$HOME/package/php-7.4.6 \
--enable-bcmath \
--enable-calendar \
--enable-opcache \
--enable-mbstring \
--enable-intl \
--enable-mysqlnd \
--disable-cgi \
--with-readline \
--with-zlib \
--with-curl \
--with-openssl \
--with-password-argon2 \
--with-sodium \
--with-pear \
--with-gmp \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd

make -j 4

make install

./libtool --finish $HOME/source/php-7.4.6/libs

Macos

brew install icu4c \
oniguruma \
openssl@1.1 \
libsodium \
argon2 \
libiconv \
readline \
libyaml \
gmp

For now, use macos built in sqlite

Configure And Compile PHP

Finally, install php-7.4.6, adjusting the sqlite pkg-config and ldflags as needed

PKG_CONFIG_PATH="$(brew --prefix openssl@1.1)/lib/pkgconfig:$(brew --prefix icu4c)/lib/pkgconfig:$HOME/package/sqlite-3.32.1/lib/pkgconfig" \
LDFLAGS="-L$(brew --prefix openssl@1.1)/lib:-L$(brew --prefix icu4c)/lib:-L/$HOME/package/sqlite-3.32.1/lib" \
./configure \
--prefix=$HOME/package/php-7.4.6 \
--enable-bcmath \
--enable-calendar \
--enable-opcache \
--enable-mbstring \
--enable-intl \
--enable-mysqlnd \
--disable-cgi \
--with-readline=$(brew --prefix readline) \
--with-iconv=$(brew --prefix libiconv) \
--with-zlib \
--with-curl \
--with-openssl \
--with-password-argon2 \
--with-sodium \
--with-pear \
--with-gmp \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd

make -j 4

make install

./libtool --finish $HOME/source/php-7.4.6/libs

Add To Path And Test

Then, add the $HOME/package/php-7.4.6/bin to your PATH

Finally:

rizalp@desktop:~$ symfony check:requirements

Symfony Requirements Checker
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> PHP is using the following php.ini file:
/home/rizalp/package/php-7.4.6/lib/php.ini

> Checking Symfony requirements:

.............................

                                              
 [OK]                                         
 Your system is ready to run Symfony projects 
                                              
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment