0

I'm trying to run php-fpm in gitpod.io.
But when I run following command...

service php7.1-fpm start

...Gitpod console return a permission error, I can't use sudo in gitpod console. What can i do to fix that issue.

Error:
> mkdir: cannot create directory ‘/run/php’: Permission denied . That error are show in my gitpod console

My dockerfile :

FROM gitpod/workspace-full:latest

# optional: use a custom Nginx config.
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./docker-run.sh /

# optional: change document root folder. It's relative to your git working copy.
ENV NGINX_DOCROOT_IN_REPO="www"
USER root
RUN apt-get update \
 && apt-get -y install mysql-server mysql-client \
 && apt-get -y install php-fpm php-cli php-bz2 php-bcmath php-gmp php-imap php-shmop php-soap php-xmlrpc php-xsl php-ldap \
 && apt-get -y install php-amqp php-apcu php-imagick php-memcached php-mongodb php-oauth php-redis\
 && apt-get clean && rm -rf /var/cache/apt/* /var/lib/apt/lists/* /tmp/*

RUN mkdir /var/run/mysqld \
 && chown -R gitpod:gitpod /var/run/mysqld /usr/share/mysql /var/lib/mysql /var/log/mysql /etc/mysql

COPY ./my.cnf /etc/mysql/my.cnf

RUN mysqld --daemonize --skip-grant-tables \
    && sleep 3 \
    && ( mysql -uroot -e "USE mysql; UPDATE user SET authentication_string=PASSWORD(\"root\") WHERE user='root'; UPDATE user SET plugin=\"mysql_native_password\" WHERE user='root'; FLUSH PRIVILEGES;" ) \
    && mysqladmin -uroot -proot shutdown;

EXPOSE 80 443

Sorry for my english is verry bad.

Giorgos Tsakonas
  • 5,845
  • 3
  • 17
  • 20
  • > mkdir: cannot create directory ‘/run/php’: Permission denied . That error are show in my gitpod console . – Ben Thunder Sep 23 '19 at 08:18

1 Answers1

0

I'm not familiar with php-fpm therefore I'm not able to test if my solution runs correctly. However, I'm able to start php-fpm in Gitpod when I change the paths in the php-fpm config files to locations the user gitpod is allowed to write to.

You'll find the configuration of php-fpm in /etc/php/7.2/fpm/ (you may have to change the version number if you use 7.1). I created a simple config file where the pid file, the socket file and the log file will be written to /tmp/, a location the user gitpod is allowed to write files to:

[global]
pid = /tmp/php7.2-fpm.pid
error_log = /tmp/php7.2-fpm.log

[www]
listen = /tmp/php7.2-fpm.sock
listen.owner = gitpod
listen.group = gitpod

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

Now, you can start the php-fpm daemon like this:

/usr/sbin/php-fpm7.2 --fpm-config php-fpm.conf

After that, you can check that the daemon is running by ps -aux. There you'll find something like this:

gitpod      3342  0.0  0.0 234512 11524 ?        Ss   14:34   0:00 php-fpm: master process (php-fpm.conf)
gitpod      3343  0.0  0.0 234644  5812 ?        S    14:34   0:00 php-fpm: pool www
gitpod      3344  0.0  0.0 234644  5812 ?        S    14:34   0:00 php-fpm: pool www

You can find a working example here.

I hope that works for you.

Cornelius


PS: If this answers your question please consider to write a comment to your reddit post with a link to this answer so that the reddit users know that the problem is solved already.

Cornelius
  • 400
  • 3
  • 12