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
- http://www.phpinternalsbook.com/php7/build_system/building_php.html
- https://github.com/gitKearney/php7-from-scratch
- https://mac-dev-env.patrickbougie.com/php/
- https://php.watch/articles/compile-php-ubuntu
sudo apt-get install build-essential \
pkg-config \
autoconf \
libtool \
bison \
re2c \
libxml2-dev \
libonig-dev \
libssl-dev \
libargon2-0-dev \
libsodium-dev \
libcurl4-openssl-dev \
libreadline-dev \
libyaml-dev \
libgmp-dev \
libzip-dev \
libpng-dev \
libjpeg-dev \
libwebp-dev \
libxpm-dev \
libicu-dev \
libfreetype6-dev \
libxslt-dev \
libldb-dev \
libtidy-dev \
libvips-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.41.1
make
make install
Download PHP https://www.php.net/distributions/php-8.2.4.tar.xz, then adjusting the sqlite pkg-config and ldflags as needed
PKG_CONFIG_PATH="$HOME/package/sqlite-3.41.1/lib/pkgconfig" \
LDFLAGS="-L/$HOME/package/sqlite-3.41.1/lib" \
./configure \
--prefix=$HOME/package/php-8.2.4 \
--enable-bcmath \
--enable-calendar \
--enable-opcache \
--enable-mbstring \
--enable-intl \
--enable-mysqlnd \
--enable-fpm \
--enable-gd \
--enable-exif \
--with-fpm-user=$USER \
--with-fpm-group=$USER \
--with-readline \
--with-zlib \
--with-curl \
--with-openssl \
--with-password-argon2 \
--with-sodium \
--with-pear \
--with-gmp \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zip \
--with-xsl \
--with-jpeg \
--with-png \
--with-webp \
--with-tidy
make -j $(nproc)
# run test (optional)
mysql -u root -e 'CREATE SCHEMA test;'
make TEST_PHP_ARGS=-j$(nproc) test
# for specific test only make TEST_PHP_ARGS=-j$(nproc) TESTS=ext/pdo_sqlite/ test
make install
./libtool --finish $HOME/source/php-8.2.4/libs
Optionally, you could test the binary using make TEST_PHP_ARGS=-j$(nproc) test
or make TEST_PHP_ARGS=-j$(nproc) TESTS=ext/pdo_sqlite/ test
to test only specific extension . To test mysql connection, don't forget to create schema mysql -u root -e 'CREATE SCHEMA test;'
copy default php-fpm config, otherwise php-fpm cannot be started
cp $HOME/package/php-8.2.4/etc/php-fpm.conf.default $HOME/package/php-8.2.4/etc/php-fpm.conf
cp $HOME/package/php-8.2.4/etc/php-fpm.d/www.conf.default $HOME/package/php-8.2.4/etc/php-fpm.d/www.conf
configure to running in the foreground, for easy debugging. Edit $HOME/package/php-8.2.4/etc/php-fpm.conf
daemonize = no
configure it to listen to unix socket, edit $HOME/package/php-8.2.4/etc/php-fpm.d/www.conf
listen = /tmp/php-fpm.sock
also, uncomment out the listen.owner
, listen.group
, & listen.mode
variables
php-fpm
can be started by executing $HOME/package/php-8.2.4/sbin/php-fpm
This macos guide kind of outdated, since I rarely use Mac, please check the following for more updated approach:
- https://getgrav.org/blog/macos-monterey-apache-multiple-php-versions
- https://getgrav.org/blog/macos-monterey-apache-ssl
- https://getgrav.org/blog/macos-monterey-apache-mysql-vhost-apc
brew install icu4c \
oniguruma \
[email protected] \
libsodium \
argon2 \
libiconv \
readline \
libyaml \
gmp \
pkg-config \
libpng \
libzip \
autoconf \
tidy
Finally, install php-8.2.4, adjusting the sqlite pkg-config and ldflags as needed
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/icu4c/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$HOME/package/sqlite-3.41.1/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/libxml2/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/libpng/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/libwebp/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/libzip/lib/pkgconfig"
./configure \
--prefix=$HOME/package/php-8.2.4 \
--enable-bcmath \
--enable-calendar \
--enable-opcache \
--enable-mbstring \
--enable-intl \
--enable-mysqlnd \
--enable-fpm \
--enable-gd \
--enable-exif \
--with-fpm-user=$USER \
--with-fpm-group=$USER \
--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 \
--with-zip \
--with-xsl \
--with-jpeg \
--with-png \
--with-webp \
--with-tidy
make -j$(sysctl -n hw.logicalcpu)
# run test (optional)
mysql -u root -e 'CREATE SCHEMA test;'
make TEST_PHP_ARGS=-j$(sysctl -n hw.logicalcpu) test
# for specific test only make TEST_PHP_ARGS=-j$(sysctl -n hw.logicalcpu) TESTS=ext/pdo_sqlite/ test
make install
./libtool --finish $HOME/source/php-8.2.4/libs
Then, add the $HOME/package/php-8.2.4/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-8.2.4/lib/php.ini
> Checking Symfony requirements:
.............................
[OK]
Your system is ready to run Symfony projects
php.ini
In
$HOME/package/php-7.4.16/lib
add new filephp.ini
. The default path are found from./php --ini