Execute perl script in Yii2 Framework by http at localhost (Docker)
I am able to run my Yii2 Project using Docker at localhost. Now, I need to exec perl script by http request. Perl script is located at root folder. Here are piece of codes, how I try to exec perl script.
public function actionExecPerl()
{
$path = './script.pl';
$exec = exec("/usr/bin/perl $path", $output);
if(is_executable($path)) {
return 'ok';
}
else {
return 'Unable to call Perl Script';
}
}
Then, I am trying to execute this script by http, from local address:
http://127.0.0.1:22080/sync/exec-perl
In result, I always get: Unable to call Perl Script
I tried all of possible paths (full path), but didn’t get a result.
Just in case, I share my Docker Configuration file
DockerFile
FROM yiisoftware/yii2-php:7.2-apache
# Change document root for Apache
RUN sed -i -e 's|/app/web|/app/api/web|g' /etc/apache2/sites-available/000-default.conf
docker-compose.yml
version: '3.2'
services:
backend:
build: backend
ports:
- 21080:80
volumes:
# Re-use local composer cache via host-volume
- ~/.composer-docker/cache:/root/.composer/cache:delegated
- ./docker/php/php.ini:/usr/local/etc/php/conf.d/custom.ini
# Mount source-code for development
- ./:/app
api:
build: api
ports:
- 22080:80
volumes:
# Re-use local composer cache via host-volume
- ~/.composer-docker/cache:/root/.composer/cache:delegated
- ./docker/php/php.ini:/usr/local/etc/php/conf.d/custom.ini
# Mount source-code for development
- ./:/app
mysql:
image: mysql:latest
restart: always
container_name: mysql-sensei
ports:
- 3306:3306
command:
--default-authentication-plugin=mysql_native_password
--innodb_flush_method=O_DIRECT
volumes:
- ./docker/mysql/dump:/docker-entrypoint-initdb.d
- ./docker/mysql/my.cnf:/etc/mysql/my.cnf
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=secret
- MYSQL_USER=secret
- MYSQL_PASSWORD=secret
Source: StackOverflow