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
Apache2 From Source
Previously i tried to use the apache2 from Ubuntu repo.
--with--apxs2
flag configure successfully detect the libs. Unfortunately, when doingmake install
, it tried to put mod_php into the apache2 dir which requires root access, which failed.I'd like to make it installed on non-root directory. to avoid messing up with system files.
Dependencies for apache2:
Then simply follow the http://httpd.apache.org/docs/current/install.html, using this configure script, with only minimal mods required, and using
mpm_prefork
(becausemod_php
is not thread safe).And then, rebuild php using configuration above, with new flag:
--with-apxs2=$HOME/package/httpd-2.4.46/bin/apxs
Apache2 Configuration
Make backup of the default configuration
Then, use the following
$PREFIX/conf/httpd.conf
.In
$PREFIX/conf/httpd.conf
, make sure the following is applied. This will make apache2 listen to127.0.1.1:8000
, enablingmpm_event
andrewrite
(most php frameworks / cms have extensive use of.htaccess
), and specify directory for vhost conf and files.Then
mkdir -p $PREFIX/conf/domains && nano $PREFIX/conf/domains/demo.local.conf
, and add the minimal virtualhost needed to proxy all.php
files into php-fpm:Then add files virtualhost sites directory
mkdir -p $PREFIX/domains/demo.local && nano $PREFIX/domains/demo.local/index.php
Or you could symlink
public
directory that contains front controllerindex.php
of your project. For example symfony project has this front controllerpublic
that storeindex.php
front controller and many static assets. The static assets will be served by apache with mpm_event, and theindex.php
is forwarded to php_fpmCreate log directory
mkdir -p $PREFIX/logs/demo.local
Finally, register
demo.local
as the valid domain in your computer, bysudo nano /etc/hosts
, and add / appendfinally start
bin/apachectl -k start
. Alternatively you could dostart | stop | restart | graceful | graceful-stop