WARNING This script is not supported by i-MSCP team WARNING
Hi there,
I was very frustrated bringing php 8.0 and 8.1 up with the PhpSwitcher plugin. So I checked alternatives and found other tools like IspConfig which are using package reposirories with precompiled php versions. So I started to check if these version could be used for the PhpSwitcher as it makes the implementing it into I-MSCP more easier. And the good part is that I found a solution.
ATTENTION:
- This HowTo is for Ubuntu and tested only on Ubuntu.
- Use at your own risk!
- I made this after bringing the new version to work - so some steps could be not precised as I want them to be.
- In some cases you need root access - in these cases place a sudo in front of the commands.
If all precompiled versions are working (which they should), you can install the following packages:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
Changelog:
- 09.12.2021
- Add information about how to configure and use it with the built in phpSwitcher function to handle packages from the repository
- Fix wrong pool directory path
- 06.12.2021 (first public release)
- PHP package installation
- PEAR installation
- Additional pecl packages
- IONCUBE installation
- Add it to I-MSCP phpSwitcher
Requirements:
- phpSwitcher (paid module)
- shell access to your server (with root permissions)
- shell knowledge (never trust online shell commands!)
Installing the package repository:
To install the packages I use the Ondrej php versions: https://deb.sury.org/
Install php version with basic needs (example is for php 8.1):
In my case I install all the packages I need:
- apt-get install php8.1-cgi php8.1-fpm php8.1-xml php8.1-bz2 php8.1-sqlite3 php8.1-pdo-sqlite php8.1-mysql php8.1-mbstring php8.1-imap php8.1-imagick php8.1-gd php8.1-curl php8.1-apcu php8.1-dev php8.1-memcached php8.1-pdo-mysql php8.1-pdo-sqlite php8.1-pgsql php8.1-zip php8.1-redis php8.1-mcrypt libapache2-mod-php8.1
(In some cases an apt-get upgrade is needed after this step.)
Install PEARL (optional):
WARNING: This is only needed if you want to configure the versions on your own and only if you want a seperate folder for each php version!
Installation of PEARL is really easy but you need to make sure to change the directory:
The last command opens the following list, the paths below are a suggestion:
- Below is a suggested file layout for your new PEAR installation. To
- change individual locations, type the number in front of the
- directory. Type 'all' to change all of them or simply press Enter to
- accept these locations.
- 1. Installation base ($prefix) : /usr
- 2. Temporary directory for processing : /tmp/pear/install
- 3. Temporary directory for downloads : /tmp/pear/install
- 4. Binaries directory : /usr/bin
- 5. PHP code directory ($php_dir) : /usr/share/php
- 6. Documentation directory : /usr/docs
- 7. Data directory : /usr/data
- 8. User-modifiable configuration files directory : /usr/cfg
- 9. Public Web Files directory : /usr/www
- 10. System manual pages directory : /usr/man
- 11. Tests directory : /usr/tests
- 12. Name of configuration file : /etc/pear.conf
- 1-12, 'all' or Enter to continue:
Now press 1 and change the path to /opt/pear/8.1
After that press 12 and change it to /opt/pear/pear8.1.conf
Now it should look like:
- Below is a suggested file layout for your new PEAR installation. To
- change individual locations, type the number in front of the
- directory. Type 'all' to change all of them or simply press Enter to
- accept these locations.
- 1. Installation base ($prefix) : /opt/pear/8.1
- 2. Temporary directory for processing : /tmp/pear/install
- 3. Temporary directory for downloads : /tmp/pear/install
- 4. Binaries directory : /opt/pear/8.1/bin
- 5. PHP code directory ($php_dir) : /opt/pear/8.1/share/php
- 6. Documentation directory : /opt/pear/8.1/docs
- 7. Data directory : /opt/pear/8.1/data
- 8. User-modifiable configuration files directory : /opt/pear/8.1/cfg
- 9. Public Web Files directory : /opt/pear/8.1/www
- 10. System manual pages directory : /opt/pear/8.1/man
- 11. Tests directory : /opt/pear/8.1/tests
- 12. Name of configuration file : /opt/pear/pear8.1.conf
- 1-12, 'all' or Enter to continue:
Press enter to start the installation process.
Installing additional pecl packages (optional):
WARNING: First of all check if there is a precompiled packages which comes with the Ondrej packages using apt search php | grep mymodulename.
WARNING: I had troubles using this and avoided using it. So be careful with this and test it before trying to use it productive!
First of all you need to change the default php version:
- update-alternatives --set php /usr/bin/php8.1
- update-alternatives --set php-cgi /usr/bin/php-cgi8.1
- update-alternatives --set php-cgi-bin /usr/lib/cgi-bin/php8.1
- update-alternatives --set php-config /usr/bin/php-config8.1
- update-alternatives --set php-fpm.sock /run/php/php8.1-fpm.sock
- update-alternatives --set phpize /usr/bin/phpize8.1
Now install your pecl module - in this example the module is called <module>:
- printf '\n' | pecl install -f <module>
- PHP_EXT_DIR=$(/usr/bin/php-config8.1 --extension-dir) \
- && echo "extension = <module>" > /etc/php/8.1/mods-available/<module>.ini
- if [ -f /etc/php/8.1/mods-available/<module>.ini ]; then
- ln -s /etc/php/8.1/mods-available/<module>.ini /etc/php/8.1/cgi/conf.d/50_<module>.ini
- ln -s /etc/php/8.1/mods-available/<module>.ini /etc/php/8.1/apache2/conf.d/50_<module>.ini
- ln -s /etc/php/8.1/mods-available/<module>.ini /etc/php/8.1/cli/conf.d/50_<module>.ini
- ln -s /etc/php/8.1/mods-available/<module>.ini /etc/php/8.1/fpm/conf.d/50_<module>.ini
- echo "extension does not exist: /etc/php/8.1/mods-available/<module>.ini"
- fi
Switch PHP version back to your old one - in this case 7.0:
- # some of the commands below could fail due to not installed in your main php version
- update-alternatives --set php /usr/bin/php7.0
- update-alternatives --set php-cgi /usr/bin/php-cgi7.0
- update-alternatives --set php-cgi-bin /usr/lib/cgi-bin/php7.0
- update-alternatives --set php-config /usr/bin/php-config7.0
- update-alternatives --set php-fpm.sock /run/php/php7.0-fpm.sock
- update-alternatives --set phpize /usr/bin/phpize7.0
Install Ioncube (optional):
First of all we need to download the ioncube package:
Now install it for the version you wanna use. At this moment php8.1 is not in the list but shown above as an example:
- PHP_EXT_DIR=$(/usr/bin/php-config8.1 --extension-dir) \
- && cp /opt/ioncube/ioncube/ioncube_loader_lin_8.1.so $PHP_EXT_DIR/ioncube.so \
- && echo "zend_extension = ioncube.so" > /etc/php/8.1/mods-available/ioncube.ini
- if [ -f /etc/php/8.1/mods-available/ioncube.ini ]; then
- ln -s /etc/php/8.1/mods-available/ioncube.ini /etc/php/8.1/cgi/conf.d/01_ioncube.ini
- ln -s /etc/php/8.1/mods-available/ioncube.ini /etc/php/8.1/apache2/conf.d/01_ioncube.ini
- ln -s /etc/php/8.1/mods-available/ioncube.ini /etc/php/8.1/cli/conf.d/01_ioncube.ini
- ln -s /etc/php/8.1/mods-available/ioncube.ini /etc/php/8.1/fpm/conf.d/01_ioncube.ini
- else
- echo "extension does not exist: /etc/php/8.1/mods-available/ioncube.ini"
- fi
And remove the garbage :
Finally:
After this you need to restart all php services. I also added some more details about the output versions, but in general they are not really needed:
- service php8.1-fpm restart
- service php8.0-fpm restart
- service php7.4-fpm restart
- service php7.3-fpm restart
- service php7.2-fpm restart
- service php7.1-fpm restart
- service php7.0-fpm restart
- service php5.6-fpm restart
- service --status-all | grep php
- printf '\n' | update-alternatives --config php
- printf '\n' | update-alternatives --config php-cgi
- printf '\n' | update-alternatives --config php-cgi-bin
- printf '\n' | update-alternatives --config php-config
- printf '\n' | update-alternatives --config php-fpm.sock
- printf '\n' | update-alternatives --config phpize
Installing in I-MSCP:
There are two ways to install the packages:
Using built in phpSwitcher function:
Make sure the version is in the compiler file (not known versions are not searched and therefore cannot be added). Check the file /var/www/imscp/gui/plugins/PhpSwitcher/PhpCompiler/php_compiler.pl and add the versions you want and need (the most recent versions can be found at https://www.php.net).
After that you can add the php versions with the following command (only specify the versions you want or simply do not specify any version to add them all):
WARNING: If you already have a configured compiled version this is going to overwrite them!
Do it on your own:
All you need now is to switch to your new php version. So add it with the following parameters (example still with 8.1):
Name | Value |
General -> Pear folder | /opt/pear/8.1/share/php or if you do not have an own folder for pear /usr/share/php |
FastCGI -> path to binary file | /usr/bin/php-cgi8.1 |
PHP-FPM -> path to binary file | /usr/sbin/php-fpm8.1 |
PHP-FPM -> path to config file | /etc/php/8.1/fpm/php-fpm.conf |
PHP-FPM -> path to pool folder | /etc/php/8.1/fpm/pool.d |
Upgrade:
If there is a new version in the package repository all you need to do is a normal packages update. As this has not happened till this howto was made I recommend to check the admin panel if everything works fine.
Finally 2 (optional):
If you liked it please leave a thumbs up .
WARNING This script is not supported by i-MSCP team WARNING