How to install PHP Extensions (mcrypt) on Azure App Service with Debian 9 with PHP 7.3+

How to install PHP Extensions (mcrypt) on Azure App Service with Debian 9 with PHP 7.3+

Basically, when you install any extensions on the Azure App Service and restart the app all the installed extensions and settings will get deleted and rolled back to the base image. Except for the home folder.

So how can we install the extensions like PHP mcrypt? Will see in this article.

Objective

  • Configure Azure App Service to store the configurations and settings even after Azure App is restarted
  • Configure Startup Command
  • Connect to Azure App Service using KUDU Console
  • Check and restart the app to verify

Configure Azure App Service to store the configurations and settings even after Azure App is restarted

Go to the Azure App Service in which you want to install the extension and click on the Configuration under the Settings Section.

No alt text provided for this image

Under Application Settings Tab on the Configuration section, click on New Application Setting

No alt text provided for this image

Add the following Name and Variable and Click OK and Save

Name = WEBSITES_ENABLE_APP_SERVICE_STORAGE

Value = True

No alt text provided for this image

Configure Startup Command

Next is to give the path for the startup script, Under the Configuration Section. Navigate to the second tab called General Settings. In the Stack Settings, look for the field Startup Command in that enter the path for the startup script /home/startup.sh

No alt text provided for this image

Connect to Azure App Service using KUDU Console

Now let's ssh into the Azure App Service using KUDU Console.

Go to your KUDU console https://<sitename>.scm.azurewebsites.net and Select SSH

No alt text provided for this image

In your SSH session, run the commands below

Setup Startup Script

Create a file called startup.sh under the home directory

     /home# vi startup.sh

Copy-paste the commands given below.

     #!/bin/bash 
     [answer] | 
     apt-get install -y libmcrypt-dev && pecl install mcrypt-1.0.2 && docker-php-ext-enable mcrypt 
     /usr/sbin/apache2ctl -D FOREGROUND

Save and Exit from SSH.

Stop and Start the App from the console.

No alt text provided for this image

Check and restart the app to verify

SSH into the App and test the installation.

Congratulations. Now we successfully installed the mcrypt PHP module. You can restart the Azure App Serice and you can verify the installation using below command

     $ php -m | grep mcrypt
     mcrypt

要查看或添加评论,请登录

Vignesh Sivakumar的更多文章

社区洞察

其他会员也浏览了