Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 cases for php : php-symfony-apache2 php-symfony-apache2-dev php-symfony-nginx #23

Merged
merged 9 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ Each image can be built using the following command.

### Postgres

# to run the migrations when starting the database
--volume $(pwd)/migrations:/docker-entrypoint-initdb:ro \
# today, the 30th of april 2022, this is the latest release
postgres:14.2-bullseye

```bash
docker run -d \
--name eco-benchmark-database \
# to run the migrations when starting the database
--volume $(pwd)/migrations:/docker-entrypoint-initdb.d:ro \
--port 5432:5432 \
-e POSTGRES_PASSWORD=mysecretpassword \
# today, the 30th of april 2022, this is the latest release
postgres:14.2-bullseye

export DATABASE_URL=postgresql://postgres:[email protected]:5432/postgres
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ APP_SECRET=ae7393b8f9f349aa633c2d57a74b23b8
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7&charset=utf8mb4"
DATABASE_URL="postgresql://postgres:[email protected]:5432/postgres"
###< doctrine/doctrine-bundle ###
###< doctrine/doctrine-bundle ###
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.0.19-apache-buster
FROM php:8.1-apache-buster

RUN apt-get update && \
apt-get install -y libpq-dev unzip && \
Expand All @@ -11,7 +11,8 @@ RUN apt-get update && \
curl https://getcomposer.org/installer -o composer-setup.php && \
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
COPY apache.conf /etc/apache2/sites-enabled/symfony.conf
ENV APP_ENV prod
COPY . /var/www/project
WORKDIR /var/www/project
RUN composer install --no-dev --optimize-autoloader
RUN chown -R www-data /var/www/project
USER www-data
RUN composer install
13 changes: 13 additions & 0 deletions service/php-symfony-apache2-dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# How to run

## Build the image

```bash
docker build -t benchmark-php-symfony-apache2-dev .
```

## Run the container

```bash
docker run --name=benchmark-php-symfony-apache2-dev -d -p 8080:8080 -e DATABASE_URL='postgresql://postgres:[email protected]:5432/postgres' benchmark-php-symfony-apache2-dev
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
persistent: true

# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
Expand Down
28 changes: 28 additions & 0 deletions service/php-symfony-apache2/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=ae7393b8f9f349aa633c2d57a74b23b8
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7&charset=utf8mb4"
DATABASE_URL="postgresql://postgres:[email protected]:5432/postgres"
###< doctrine/doctrine-bundle ###
12 changes: 12 additions & 0 deletions service/php-symfony-apache2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###

.idea
24 changes: 24 additions & 0 deletions service/php-symfony-apache2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM php:8.1-apache-buster

RUN apt-get update && \
apt-get install -y libpq-dev unzip && \
rm -rf /var/cache/apt/archives /var/lib/apt/lists/* && \
docker-php-ext-install pdo_pgsql opcache && \
a2enmod rewrite && \
rm /etc/apache2/sites-available/000-default.conf && \
rm /etc/apache2/sites-available/default-ssl.conf && \
echo 'Listen 8080' > /etc/apache2/ports.conf && \
curl https://getcomposer.org/installer -o composer-setup.php && \
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
COPY apache.conf /etc/apache2/sites-enabled/symfony.conf
COPY docker/php.ini /usr/local/etc/php/conf.d/symfony.ini
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/conf.d/php.ini
ENV APP_ENV prod
COPY . /var/www/project
WORKDIR /var/www/project
RUN chown -R www-data /var/www/project
USER www-data
RUN composer install --prefer-dist --no-dev --no-interaction && \
composer dump-autoload --no-dev --classmap-authoritative && \
composer dump-env prod && \
php bin/console cache:clear --env prod
13 changes: 13 additions & 0 deletions service/php-symfony-apache2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# How to run

## Build the image

```bash
docker build -t benchmark-php-symfony-apache2 .
```

## Run the container

```bash
docker run --name=benchmark-php-symfony-apache2 -d -p 8080:8080 -e DATABASE_URL='postgresql://postgres:[email protected]:5432/postgres' benchmark-php-symfony-apache2
```
85 changes: 85 additions & 0 deletions service/php-symfony-apache2/apache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<VirtualHost *:8080>
DocumentRoot /var/www/project/public
<Directory /var/www/project/public>
Require all granted
AllowOverride All
Order Allow,Deny
Allow from All

# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex index.php

# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options +FollowSymlinks

# Disabling MultiViews prevents unwanted negotiation, e.g. "/index" should not resolve
# to the front controller "/index.php" but be rewritten to "/index.php/index".
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On

# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]

# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]

# Redirect to URI without front controller to prevent duplicate content
# (with and without `/index.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
# Rewrite all other queries to the front controller.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 307 ^/$ /index.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
</Directory>

# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>

ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
17 changes: 17 additions & 0 deletions service/php-symfony-apache2/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
};
83 changes: 83 additions & 0 deletions service/php-symfony-apache2/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.0",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.6",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.12",
"phpdocumentor/reflection-docblock": "^5.3",
"phpstan/phpdoc-parser": "^1.5",
"sensio/framework-extra-bundle": "^6.2",
"symfony/console": "5.4.*",
"symfony/dotenv": "5.4.*",
"symfony/flex": "^1.17|^2",
"symfony/framework-bundle": "5.4.*",
"symfony/property-access": "5.4.*",
"symfony/property-info": "5.4.*",
"symfony/proxy-manager-bridge": "5.4.*",
"symfony/runtime": "5.4.*",
"symfony/serializer": "5.4.*",
"symfony/uid": "5.4.*",
"symfony/yaml": "5.4.*"
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true,
"symfony/runtime": true
},
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.4.*"
}
},
"require-dev": {
"symfony/maker-bundle": "^1.40",
"symfony/stopwatch": "5.4.*",
"symfony/twig-bundle": "5.4.*",
"symfony/web-profiler-bundle": "5.4.*"
}
}
Loading
Loading