Multiple Composer + Drupal 10 + Multiple PHP + MariaDB 10

Discussion in 'Tips/Tricks/Mods' started by Alex Mamatuik, Mar 21, 2023.

  1. Alex Mamatuik

    Alex Mamatuik Member

    Plot: Install drupal 10 website, using composer, to a server, which has incompatible php & mariadb versions.

    Start value:
    • Centos 7;
    • MariaDB (mysql) v5.#.#;
    • PHP 5.6.
    We need to enable php 8.2, to begin with.
    (Automatic method – REMI repository)
    yum-config-manager –disable ‘remi-php*’
     yum-config-manager –enable remi-safe
      yum -y install php82
    yum install php82-php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json,soap,intl,opcache,pcntl,sockets,sysvsem,sysvshm,mbregex,gd,openssl,Kerberos,zlib,calendar,bz2,webp,jpeg,enchant,freetype,exif,ftp,gettext,mhash,imap,imap-ssl,pcntl,mysqli}
    php82 -version
    PHP 8.2.4 (cli) (built: Mar 14 2023 16:11:05) (NTS gcc x86_64)
    Copyright (c) The PHP Group
    Zend Engine v4.2.4, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.4, Copyright (c), by Zend Technologies

    php82 -modules - to list all enabled modules.

    systemctl enable php82-php-fpm
    systemctl start php82-php-fpm

    Enabling some useful extensions.
    1) compiling it
    yum install ImageMagick-devel

    cd /usr/local/src/
    mkdir php82-build
    cd php82-build

    tar xzvf imagick-3.7.0.tgz
    cd imagick-3.7.0
    ./configure --with-php-config=/opt/remi/php82/root/usr/bin/php-config
    make test
    make install
    /opt/remi/php82/root/usr/bin/php -i | grep "magick"

    2) automatically
    yum install php82-php-pear
    /opt/remi/php82/root/usr/bin/pecl -C /etc/opt/remi/php82/pear.conf update-channels
    /opt/remi/php82/root/usr/bin/pecl -C /etc/opt/remi/php82/pear.conf install igbinary
    yum install php82-php-pecl-libmemcached
    yum install php82-php-pecl-msgpack
    /opt/remi/php82/root/usr/bin/pecl -C /etc/opt/remi/php82/pear.conf install memcached
    yum install php82-php-{apcu,uploadprogress}
    Hope, you read ISP Config 3 handbook and know, how to assign a multiple php record from the dashboard.

    Update MariaDB to the version 10.3 -

    Install Composer for php 8.2
    cd /tmp
    php82 -r "copy('', 'composer-setup.php');"
    php82 -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    php82 composer-setup.php --2.5 --install-dir=/usr/local/bin --filename=composer82
    composer82 - Composer (version 2.5.4) successfully installed to: /usr/local/bin/composer82 with php 8.2

    There is also possible to add alias through .bashrc:
    But be careful to not break a configuration!

    Next step - to run composer properly!

    Generally, i am writing these tips, because the Composer is a real headache.

    When we created a namespace for future website (domain#1 for client#0), new linux user was also added:
    But we are unable to switch for the user web1.
    To achieve this, from the control panel of ISP Config new shell-user should be created.

    A new record will be looking like:
    For developers (@Th0m ) - i wish it would be named not as default###, but some more decent way [CLIENTNAME] -> better equivalent.

    Then we are ready to install drupal 10 website via composer.
    cd /var/www/websites/client0/domain1/{subdomain_folder}
    ls -a
    rm -rf standard_index.html robots.txt favicon.ico
    su defaultdrupal
    php82 /usr/local/bin/composer82 create-project drupal/recommended-project:10.0.5 ./
    Unfortunately, composer doesn't handle non-empty directories.:oops:

    And if we remove error & stats, things are not smoothed down.

    Choose any folder, create project and look inside
    php82 /usr/local/bin/composer82 create-project drupal/recommended-project:10.0.5 ./d10
    Inside of d10 directory we have the web folder.
    It means, the drupal system will be run from index.php, placed in d10/web.

    Let's remove interstitial d10-folder:
    mv d10/* ./
    composer.json composer.lock d10 error stats vendor web
    ls -la d10
    -rw-r--r--. 1 web1 client0 357 Mar 21 23:46 .editorconfig
    -rw-r--r--. 1 web1 client0 4034 Mar 21 23:46 .gitattributes

    cp d10/{.editorconfig,.gitattributes} ./
    rm -rf d10

    But still drupal-system is managed from web.

    For such an occasion, we must create redirect-ruleю
    Thanks to unbelievable free ISP Config 3 system and its' Makers:D, this is very easy to do:
    ISPConfig — redirect.png

    after setting up database...
    we can see on the page /admin/reports/status#error some issues:
    • Trusted Host Settings - Not enabled;
    • Database Isolation Level - REPEATABLE-READ.
    Status report _ Drupal 10.png

    Trusted Host Settings

    Database Isolation Level
    !!! very important to set READ-COMMITTED or mysql server will say bye-bye!!!

    Enabling Drush for Drupal 10
    cd /var/www/websites/client0/domain1/{your_folder}
    php82 /usr/local/bin/composer82 require drush/drush
    Drupal version : 10.0.5
    Site URI : http://default
    DB driver : mysql
    DB hostname : localhost
    DB port : 3306
    DB username : {db_user}
    DB name : {db_name}
    Database : Connected
    Drupal bootstrap : Successful
    Default theme : olivero
    Admin theme : claro
    PHP binary : /opt/remi/php82/root/usr/bin/php
    PHP config : /etc/opt/remi/php82/php.ini
    PHP OS : Linux
    PHP version : 8.2.4
    Drush script : /var/www/websites/client0/domain1/{your_folder}/vendor/bin/drush
    Drush version : 11.5.1
    Drush temp : /tmp
    Drush configs : /var/www/websites/client0/domain1/{your_folder}/vendor/drush/drush/drush.yml
    Install profile : standard
    Drupal root : /var/www/websites/client0/domain1/{your_folder}/web
    Site path : sites/default
    Files, Public : sites/default/files
    Files, Temp : /tmp

    Modules' setup
    In case, we want to install Mobile Detect module,
    then we visit page

    Look at the installation path: composer require 'drupal/mobile_detect:^3.0'

    Follow to drupal 10 folder: cd /var/www/websites/client0/domain1/{your_folder}
    php82 /usr/local/bin/composer82 require 'drupal/mobile_detect:^3.0'
    But where was it installed?
    find ./ -type d -name mobile_detect

    Why did it happen, that directory was placed namely on there?
    It did happen due to several circumstances:

    cd ./web/modules/contrib/mobile_detect && cat composer.json  | grep type
    Type of the module is drupal-module.

    Definitely, it is a drupal module, what else?
    - let's make some steps backward and take a look what is written to $app_root . '/.composer.json'
        "type": "project",
                "type": "composer",
                "web/modules/contrib/{$name}": [                "type:drupal-module"            ],
                "web/modules/custom/{$name}": [                "type:drupal-custom-module"            ],
    Upon enabling modules - /admin/modules - it responds with error:
    I have very poor programming skill. Can't fix it with code.

    To avoid, instead of [L] redirecting rule we need use [R,L]
    But /web/ intermediate path becomes visible.

    Okay, we are done..!
    P.S.: i believe, this tutorial page will be often visited.
    ahrasis and till like this.

Share This Page