I have a .sh file that I execute from PHP with the shell_exec command. The .sh files are like below.
It creates the directories and "npm init -yes" line is executed successfully and I get the return lines but "npm install --save-dev hardhat" and "npx hardhat" lines have no return and don't do what expected to. Any idea how can I execute it and it works? When I execute the .sh file with root on the terminal it works also. But not with user apache.
cd /var/nftprojects
mkdir nft57
cd nft57
chmod -R 777 /var/nftprojects/nft57
mkdir ethereum
chmod -R 777 /var/nftprojects/nft57/ethereum
cd ethereum
npm init -yes
npm install --save-dev hardhat
npx hardhat --verbose
cd /var/nftprojects/nft57
mkdir /var/nftprojects/nft57/web
cd /var/nftprojects/nft57/web
npx create-next-app#latest
cd /var/nftprojects/nft57/ethereum
touch .env
npm install dotenv --save
Related
I get the following error message when I try to spin up my service via docker-compose:
service_frontend | npm ERR! code 128
service_frontend | npm ERR! An unknown git error occurred
service_frontend | npm ERR! command git --no-replace-objects clone -b feature/WHITELABEL-212-skeletons-während-der-lad https://bjoernme:***#bitbucket.org/faaren/faaren-ui.git /root/.npm/_cacache/tmp/git-cloneBmjHnf --recurse-submodules --depth=1
service_frontend | npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-cloneBmjHnf': Permission denied
service_frontend |
service_frontend | npm ERR! A complete log of this run can be found in:
service_frontend | npm ERR! /root/.npm/_logs/2022-06-24T13_42_41_376Z-debug.log
service_frontend exited with code 128
I have tried multiple constellations with in my docker-compose.yml for the user property, starting from root, root:root, node:node, 1000:1000, UID:GID (variables are set to inject my local user id and group id.
The relevant part from my docker-compose.yml:
service_frontend:
build:
context: /workspace/faaren-services/frontend
dockerfile: Dockerfile
args:
dev: "true"
command: bash -c "npm install --save-dev chokidar#3.5.2 && composer install && php artisan octane:start --server=swoole --host=0.0.0.0 --port=8080 --watch"
user: root
volumes:
- /workspace/faaren-services/frontend:/var/www/html
- ./docker-conf/supervisor/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf
- ./docker-conf/php/debugger.ini:/usr/local/etc/php/conf.d/debugger.ini
This is my local docker image:
FROM eu.gcr.io/faaren-prod/frontend-base-image:latest
COPY . /var/www/html
ARG dev=false
RUN if [ ${dev} = "true" ] ; then \
set -ex \
&& apk add --no-cache npm \
&& mkdir -p /.npm \
&& mkdir -p /root/.npm/_cacache/tmp/ \
&& chmod 777 -R "/root/.npm/_cacache/tmp/" \
&& chmod 777 -R "/.npm" \
fi ;
And this is our internal base image (which is based on the php:8.1.1-fpm-alpine3.15 image:
FROM php:8.1.1-fpm-alpine3.15
WORKDIR /var/www/html/
RUN apk add --no-cache --update git \
npm
RUN mkdir /.npm
RUN mkdir /.cache
RUN chown -R 1000:1001 "/.npm"
RUN chown -R 1000:1001 "/.cache"
After digging deeper into this issue I found out, that in Node 16.15.1 all commands within a npm task are run as the user who owns the current working dir. So even when running npm i as root subcommands as git clone are run as the user the current working dir belongs to.
In my case, /var/www/html/ belongs to user:group 33333:33333. npm i was run as root. Coming to some git clone commands, those were run as user 33333. Therefor the user 33333 was not allowed to access the default cache npm folder under /root/.npm as this folder belongs to user root.
I fixed the problem the following way:
create a cache dir outside of root mkdir /var/www/.npm/cache
change ownership to 333333: chown -R 33333:33333 /var/www/.npm/cache
set new directory as npm cache dir: npm config set cache /var/www/.npm/cache --global
I have created an AWS Launch Configuration with following user data
#!/bin/bash
ssh-keyscan github.com >> ~/.ssh/known_hosts
git clone git#github.com:[MyUserName]/[project-name].git /var/www/[project-name]
cd /var/www/[project-name]
composer install --no-dev
php artisan migrate
chown -R www-data:www-data /var/www
chmod g+w -R /var/www
Now every line gets executed, except composer install --no-dev. But if I run the above script manually everything works fine. So can anyone please help me understand what is the problem. Thanks
I have this multi-stage build in a Dockerfile:
## Stage 1
FROM node:9 as builder
RUN apt-get update && apt-get -y install sudo
RUN echo "newuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
RUN useradd -ms /bin/bash newuser
USER newuser
RUN mkdir -p /home/newuser/app
WORKDIR /home/newuser/app
RUN sudo chown -R $(whoami) $(npm config get prefix)/lib
RUN npm set progress=false
RUN npm config set depth 0
RUN npm cache clean --force
COPY dist .
## Stage 2
FROM php:5.6.30
RUN apt-get update && apt-get -y install sudo
RUN echo "newuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
RUN useradd -ms /bin/bash newuser
USER newuser
RUN mkdir -p /home/newuser/app
WORKDIR /home/newuser/app
COPY --from=builder /home/newuser/app /home/newuser/app
RUN ls -a /home/newuser/app
CMD ["php", "-S", "localhost:3000"]
the image build successfully, using:
docker build -t x .
Then I run it with:
docker run -p 3000:3000 x
but when I go to localhost:3000 on the host machine, I don't get a response. The webpage is blank.
Does anyone know why that might happen?
I also tried:
CMD ["sudo", "php", "-S", "localhost:80"]
and
docker run -p 3000:80 x
and a few other variations, still nothing.
Not sure why the PHP static server wasn't working, but I got it working with Node.js static server package:
FROM node:9 as builder
RUN apt-get update && \
apt-get -y install sudo
RUN echo "newuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
RUN useradd -ms /bin/bash newuser
USER newuser
RUN mkdir -p /home/newuser/app
WORKDIR /home/newuser/app
RUN sudo chown -R $(whoami) $(npm config get prefix)/lib
RUN sudo chown -R $(whoami) $(npm config get prefix)/lib/node_modules
RUN sudo chown -R $(whoami) $(npm config get prefix)/bin
RUN sudo chown -R $(whoami) $(npm config get prefix)/share
RUN sudo chown -R $(whoami) /usr/local/lib
RUN npm set progress=false
RUN npm config set depth 0
RUN npm cache clean --force
COPY dist .
RUN npm install -g http-server
ENTRYPOINT ["http-server", "."]
you build it like so:
docker build -t x .
and then run it like so:
docker run -p 3000:8080 x
I did this on terminal:
$ curl -sS https://getcomposer.org/installer | php
the output was:
All settings correct for using Composer
Downloading...
Composer successfully installed to: /Applications/XAMPP/xamppfiles/htdocs/composer.phar
Use it: php composer.phar
then I entered:
$ sudo mv composer.phar /usr/local/bin
No issues with this (it should work because usr/local/bin is in my $PATH). But how do I run it now? When I enter composer or composer.phar on the command line, I get:
-bash: composer: command not found
-bash: composer.phar: command not found
.phar is short for PHP Archive - it's a format that the php executable can read, not an executable on it's own right. To run it you should use:
$ php /usr/local/bin/composer.phar
To make your life a tad easier you could, of course, define an alias:
$ alias composer="php /usr/local/bin/composer.phar"
And then just call composer from your shell.
Did u check what do u have now in your path
ls -al /usr/local/bin
Check the right to execute.
To be sure u can do:
sudo chmod a+x /usr/local/bin/composer.phar
First look like should be composer.phar as you did not precise a new name in ur mv command like:
sudo mv composer.phar /usr/local/bin/composer
Did you made composer.phar executable ?
if not, just do sudo chmod a+x /usr/local/bin/composer.phar
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
mv: rename composer.phar to /usr/local/bin/composer.phar: No such file or directory
Solution:
make sure composer.phar and directory local ,bin composer exist (/usr/local/bin/composer) in $PATH
else
$ cd usr
usr$m kdir local
usr/local$m kdir bin
usr/local/bin$ mkdir composer
now we're sur local/bin/composer exist than
$sudo mv /path to composer.phar /usr/local/bin/composer
Password:
toto:~ macbookpro$ your composer.phar now is move to directory usr/local/bin/composer
Okay so i have finally build a test.js file that works on my ubuntu machine.
I just want to know how to i add phantomjs and casperjs on my cpanel and is there any way i can tet that they both work once on cpanel?
You can SSH / Shell Access from your cPanel account if you have permissions. Contact your host provider to be certain.
Here are the following commands that you can copy and paste into SSH to install dependencies, PhantomJS, and CasperJs. Dependents tested using docker.io:
apt-get install -y libfreetype6 libfontconfig libreadline-dev wget tar bzip2 vim git
mkdir -p /srv/var
cd /srv/var
PhantomJS:
wget http://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2
tar -xjf phantomjs-1.9.2-linux-x86_64.tar.bz2
ln -s `pwd`/phantomjs-1.9.2-linux-x86_64/bin/phantomjs /usr/bin/
phantomjs -v
CasperJS:
git clone https://github.com/n1k0/casperjs.git
ln -s `pwd`/casperjs/bin/casperjs /usr/bin/
casperjs --version
If they worked, You can type phantomjs -v or caspjer --version to verify installation.