How can I create a bash script that detects version of php, disable it then shift to the another without telling it which one to . I work with ZF2 and some detailed errors fail to show while using php 7 but when I shift to php5.6 I m able to see them well in the browser.

I'm able to change php mod by doing sudo a2enmod php7 or php5.6 and also doing sudo a2dismod. someone please help automate this process using a single script so that I just run it once then it disables the current mod and enable the other. thanks in advance.

  • I have a server with a legacy PHP script that needs 5.x, I am using lighthttpd and configured it in such a way that I use '5.6` for the corresponding vhost and 7.x for the rest. – Rui F Ribeiro Jun 12 '17 at 9:44
  • maybe I can try this other method if I fail to do a script to automate this process with a shell script.I have tried working with vagrant with php5.6 in a given port but at times it takes much time to load.This is the reason why I need a faster way which am convinced shell script can do.thanks. – E. Oloo Jun 12 '17 at 10:34

Thanks friends I finally had my problem solved.

    if [ ! -f $MODES_ENABLED_DIR/php5.6.conf ] && [ -f 
    $MODES_ENABLED_DIR/php7.0.conf ]
     sudo a2enmod php5.6
     sudo a2dismod php7.0 
     sudo service apache2 restart
     echo "php 5.6 successfully enabled"
    elif [ -f $MODES_ENABLED_DIR/php5.6.conf ] && [ ! -f 
    $MODES_ENABLED_DIR/php7.0.conf ]
     sudo a2enmod php7.0
     sudo a2dismod php5.6 
     sudo service apache2 restart
      echo "php 7.0 successfully enabled"

That script navigates to the etc/apache2/mod-enabled and check if symlink for php5.6 is created, if it finds it then it knows php5.6 is enabled and so it disables it by doing a2dismod php5.6 then enables php7.0. The same applies when php7.0 is enabled, it checks, disables it then enables 5.6. I only lacked the knowledge that symlink is created in mods available whenever a2enmod Php-version is run and the reverse happens when a2dismod is done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.