Carson Reinke's Headshot

Carson Reinke's (πŸš—β˜€β˜”πŸ”‘) Blog

Getting PHP Environment Setup Locally On Fedora Linux

Recently, I had some issues getting PHP setup installed correctly and wanted to share how I properly accomplished it. Please note, I have prefered ~/bin over /usr/local/bin.

Install PHPBrew first:

curl -L -O https://github.com/phpbrew/phpbrew/releases/latest/download/phpbrew.phar
chmod +x phpbrew.phar
sudo mv phpbrew.phar ~/bin/phpbrew
phpbrew init

To finish, PHPBrew must add a snippet to .bashrc simply with:

[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc

Install a specific PHP version, but some additional options need to be specified:

phpbrew --debug install 7.4.5 +default +openssl=/usr -- --with-libdir=lib64
+default
This will install the default PHP packages along with the core PHP
--with-libdir=lib64
Most libraries are actually installed under /usr/lib64 instead of under /usr/lib
+openssl=/usr
OpenSSL must resolve to the correct path and the default lib64 is incorrect

After install, make sure to start using that PHP version with phpbrew use 7.4.5.

Install Composer by running the PHP installer with the following:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '[Long Hash, Get The Real Script From The Site]') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

To make things easy, add an alias to Composer under .bashrc

alias composer="php ${HOME}/bin/composer.phar"

Install PHIVE to easily install PHP Archives (Phar)

wget -O phive.phar "https://phar.io/releases/phive.phar"
wget -O phive.phar.asc "https://phar.io/releases/phive.phar.asc"
gpg --keyserver hkps.pool.sks-keyservers.net --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
rm phive.phar.asc
chmod +x phive.phar
mv phive.phar ~/bin/phive

Install PHPUnit using PHIVE, as this a commonly used dependency that requires to be accessed directly from the shell.

phive install phpunit