To deploy a Laravel application for production on Apple Silicon using Docker, you can follow these steps:
- Build a Docker image for your Laravel application using a Dockerfile. Here's an example Dockerfile:
FROM php:8.0-apache
RUN apt-get update && \
apt-get install -y libpq-dev && \
docker-php-ext-install pdo pdo_pgsql && \
a2enmod rewrite
COPY . /var/www/html
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
CMD ["apache2-foreground"]
This Dockerfile uses the official PHP 8.0 Apache image, installs the PostgreSQL driver for PHP, enables the Apache rewrite module, copies the Laravel application code to the container, and sets the ownership of the storage and cache directories to the Apache user.
- Build the Docker image using the following command:
docker build -t my-laravel-app .
This command will build the Docker image and tag it with the name "my-laravel-app".
- Run the Docker container using the following command:
docker run -d -p 80:80 -p 443:443 --name my-laravel-container my-laravel-app
This command will run the Docker container in detached mode, map ports 80 and 443 to the host machine, and name the container "my-laravel-container".
- Configure SSL for your Laravel application. You can use a real-world SSL certificate by copying the certificate and key files to the container and configuring Apache to use them. Here's an example Dockerfile that copies the certificate and key files and configures Apache:
FROM php:8.0-apache
RUN apt-get update && \
apt-get install -y libpq-dev && \
docker-php-ext-install pdo pdo_pgsql && \
a2enmod rewrite ssl
COPY . /var/www/html
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
COPY ssl.crt /etc/apache2/ssl.crt
COPY ssl.key /etc/apache2/ssl.key
RUN sed -i 's/\/etc\/ssl\/certs\/ssl-cert-snakeoil.pem/\/etc\/apache2\/ssl.crt/g' /etc/apache2/sites-available/default-ssl.conf && \
sed -i 's/\/etc\/ssl\/private\/ssl-cert-snakeoil.key/\/etc\/apache2\/ssl.key/g' /etc/apache2/sites-available/default-ssl.conf && \
a2ensite default-ssl.conf
CMD ["apache2-foreground"]
This Dockerfile is similar to the previous one, but it also installs the Apache SSL module, copies the SSL certificate and key files to the container, and configures Apache to use them.
- Build the Docker image and run the Docker container as described in steps 2 and 3, but use the new Dockerfile that includes SSL configuration.
With these steps, you should be able to deploy your Laravel application for production on Apple Silicon using Docker. Note that you may need to adjust the Dockerfile and Apache configuration to fit your specific needs.