VKCOM/kphp

CLI execution not working

mamchyts opened this issue · 4 comments

Installation code:

FROM ubuntu:22.04

RUN apt update && apt -y upgrade \
    && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt -y install tzdata
RUN apt -y install software-properties-common \
    && add-apt-repository -y ppa:ondrej/php \
    && apt install -y php8.2-cli
RUN wget -qO /etc/apt/trusted.gpg.d/vkpartner.asc https://artifactory-external.vkpartner.ru/artifactory/api/gpg/key/public \
    && echo "deb [arch=amd64] https://artifactory-external.vkpartner.ru/artifactory/kphp jammy main" | tee /etc/apt/sources.list.d/vkpartner.list \
    && apt update \
    && apt install -y kphp vk-tl-tools

Example of error:

root@502f820c3186:/# mkdir demo
root@502f820c3186:/# cd demo
root@502f820c3186:/demo# echo '<?php echo time();' > demo.php
root@502f820c3186:/demo# kphp -M cli demo.php 
Starting php to cpp transpiling...

Starting make...
objs cnt = 10
objs cnt = 10
Compiling stage started...
  0% [total jobs 14] [left jobs 14] [running jobs 0] [waiting jobs 4]
  7% [total jobs 14] [left jobs 13] [running jobs 9] [waiting jobs 4]
 14% [total jobs 14] [left jobs 12] [running jobs 8] [waiting jobs 3]
 21% [total jobs 14] [left jobs 11] [running jobs 8] [waiting jobs 2]
 28% [total jobs 14] [left jobs 10] [running jobs 8] [waiting jobs 1]
 35% [total jobs 14] [left jobs 9] [running jobs 8] [waiting jobs 1]
 42% [total jobs 14] [left jobs 8] [running jobs 7] [waiting jobs 0]
 50% [total jobs 14] [left jobs 7] [running jobs 7] [waiting jobs 0]
 57% [total jobs 14] [left jobs 6] [running jobs 6] [waiting jobs 0]
 64% [total jobs 14] [left jobs 5] [running jobs 5] [waiting jobs 0]
 71% [total jobs 14] [left jobs 4] [running jobs 4] [waiting jobs 0]
 78% [total jobs 14] [left jobs 3] [running jobs 3] [waiting jobs 0]
 85% [total jobs 14] [left jobs 2] [running jobs 2] [waiting jobs 0]
 92% [total jobs 14] [left jobs 1] [running jobs 1] [waiting jobs 0]
100% [total jobs 14] [left jobs 0] [running jobs 0] [waiting jobs 0]
Linking stage started...
root@502f820c3186:/demo# ./kphp_out/cli
[2115][2023-06-06 05:49:22.951314 relogin.cpp  112] You are trying to run the script as root, if you are sure of this, specify the user explicitly with the command --user

root@9937d9d03ee2:/demo# php demo.php 
1686031094root@9937d9d03ee2:/demo# 

Have you tried to run script like this ./kphp_out/cli --user root?

According with docs:

--user avalidable only for server mode https://vkcom.github.io/kphp/kphp-server/execution-options/server-cmd-options.html

cli mode does not have any options https://vkcom.github.io/kphp/kphp-server/execution-options/cli-mode.html

PS.

root@25696cb29afb:/demo# ./kphp_out/cli --user root
[106][2023-06-06 19:15:10.337338 relogin.cpp  112] You are trying to run the script as root, if you are sure of this, specify the user explicitly with the command --user

This error occurs due to the fact that you are not running the executable file from root. Actually, this is written in the error.
As you may know, the executable file accepts arguments after the call, so you cannot write ./kphp_out/cli --user root, this means that you pass the --user flag with the root parameter to the executable file, but you need to pass this to the console. Therefore, to say that you will pass arguments to the console, you need to write the --Xkphp-options flag.

Solving the problem:

$ ./kphp_out/cli --Xkphp-options -u root

@Tsygankov-Slava thank you.