# Problem while creating a cron in php:7.2.2-apache

**URL:** <https://forums.docker.com/t/problem-while-creating-a-cron-in-php-7-2-2-apache/89298>\
**Category:** General\
**Tags:** docker\
**Created:** [February 19, 2020, 7:31pm UTC](https://forums.docker.com/t/problem-while-creating-a-cron-in-php-7-2-2-apache/89298 "2020-02-19T19:31:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexjub94](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@alexjub94](https://forums.docker.com/u/alexjub94)\
**Post date:** [February 19, 2020, 7:31pm UTC](https://forums.docker.com/t/problem-while-creating-a-cron-in-php-7-2-2-apache/89298/1 "2020-02-19T19:31:49Z")

</div>

Hello,

First, if i’m not in the good category, please tell me because I don’t know where to post.

My problem is : how to create a cron task in the php:7.2.2-apache container ?

Here is my Dockerfile :

```
FROM php:7.2.2-apache
RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN apt-get update && apt-get install -y cron
COPY data/ /var/www/html/
RUN chown -R :www-data /var/www && chmod -R 777 /var/www/
RUN chmod +x /var/www/html/crons/cronInit.sh
ENTRYPOINT ["/var/www/html/crons/cronInit.sh"]

```

cronInut.sh :

```
#!/bin/bash
chmod +x /var/www/html/crons/cron
crontab /var/www/html/crons/cron
service cron reload
service cron restart
chmod +x /var/www/html/crons/cron.php
cron -f &
docker-php-entrypoint apache2 -D FOREGROUND

```

It does’nt work but only running the container with copying my “data” folder in allow me to access to my app normally (but the cron is not working)

Thanks for help

---

<div class="post-metadata">

**Author:** ![tekki](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/tekki/32/21884_2.png) [@tekki](https://forums.docker.com/u/tekki)\
**Post date:** [February 20, 2020, 7:35am UTC](https://forums.docker.com/t/problem-while-creating-a-cron-in-php-7-2-2-apache/89298/2 "2020-02-20T07:35:16Z")

</div>

You can’t use the `crontab` command here, it is used to edit the file. Instead you could create a script that executes your commands in one of the `/etc/cron.*` folders.

---

<div class="post-metadata">

**Author:** ![alexjub94](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@alexjub94](https://forums.docker.com/u/alexjub94)\
**Post date:** [February 20, 2020, 10:15am UTC](https://forums.docker.com/t/problem-while-creating-a-cron-in-php-7-2-2-apache/89298/3 "2020-02-20T10:15:22Z")

</div>

I found a solution which works pretty good but thanks for the help

---

<div class="post-metadata">

**Author:** ![eurektrip](https://avatars.discourse-cdn.com/v4/letter/e/c57346/32.png) [@eurektrip](https://forums.docker.com/u/eurektrip)\
**Post date:** [November 9, 2021, 11:08pm UTC](https://forums.docker.com/t/problem-while-creating-a-cron-in-php-7-2-2-apache/89298/4 "2021-11-09T23:08:23Z")

</div>

Could you tell us what the solution was, I’m going through the same case.

Thanks.

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [November 10, 2021, 10:23pm UTC](https://forums.docker.com/t/problem-while-creating-a-cron-in-php-7-2-2-apache/89298/5 "2021-11-10T22:23:39Z")

</div>

Use [supervisor](http://supervisord.org/) to run multiple services and configure cron inside the PHP container but I don’t like to use supervisor just for cron.

You can run cron on your host or in an other container with a Docker client in it and use “docker exec” to execute commands in an any container.
