This file can't be rendered. View the full file.
l / NextGenPHP
Last active 4 months ago
Turma 5 Desafios
This file can't be rendered. View the full file.
This file can't be rendered. View the full file.
This file can't be rendered. View the full file.
This file can't be rendered. View the full file.
This file can't be rendered. View the full file.
| 1 | ==================================================== |
| 2 | DETALHES - Desafio Aula01 | NextGenPHP5 |
| 3 | ==================================================== |
| 4 | |
| 5 | ---------------------------------------------------- |
| 6 | 1. Versão do PHP e Zend Engine |
| 7 | ---------------------------------------------------- |
| 8 | Comando para verificar: |
| 9 | docker compose exec php php -v |
| 10 | |
| 11 | Saída esperada (PHP 8.3 Alpine): |
| 12 | PHP 8.3.x (cli) (built: ...) |
| 13 | Copyright (c) The PHP Group |
| 14 | Zend Engine v4.3.x, Copyright (c) Zend Technologies |
| 15 | |
| 16 | ---------------------------------------------------- |
| 17 | 2. Extensões instaladas |
| 18 | ---------------------------------------------------- |
| 19 | Comando para verificar: |
| 20 | docker compose exec php php -m |
| 21 | |
| 22 | Extensões padrão da imagem php:8.3-alpine: |
| 23 | Core, ctype, curl, date, dom, fileinfo, filter, |
| 24 | ftp, hash, iconv, json, libxml, mbstring, mysqlnd, |
| 25 | openssl, pcre, PDO, pdo_sqlite, Phar, posix, |
| 26 | readline, Reflection, session, SimpleXML, sodium, |
| 27 | SPL, sqlite3, standard, tokenizer, xml, xmlreader, |
| 28 | xmlwriter, zlib |
| 29 | |
| 30 | ---------------------------------------------------- |
| 31 | 3. Localização do php.ini no contêiner |
| 32 | ---------------------------------------------------- |
| 33 | Comando para verificar: |
| 34 | docker compose exec php php --ini |
| 35 | |
| 36 | Caminho do php.ini na imagem php:8.3-alpine: |
| 37 | /usr/local/etc/php/php.ini |
| 38 | |
| 39 | ---------------------------------------------------- |
| 40 | 4. Substituição do php.ini interno por volume |
| 41 | ---------------------------------------------------- |
| 42 | Configurado no docker-compose.yml com o mapeamento: |
| 43 | ./php.ini:/usr/local/etc/php/php.ini |
| 44 | |
| 45 | O arquivo local ./php.ini substitui o php.ini |
| 46 | interno do contêiner via volume do Docker. |
| 47 | |
| 48 | ---------------------------------------------------- |
| 49 | 5. Horário padrão do PHP ajustado |
| 50 | ---------------------------------------------------- |
| 51 | Configuração aplicada em ./php.ini: |
| 52 | date.timezone = America/Sao_Paulo |
| 53 | |
| 54 | Verificar no contêiner: |
| 55 | docker compose exec php php -r "echo date('d/m/Y H:i:s');" |
| 56 | |
| 57 | ---------------------------------------------------- |
| 58 | 6. Limite de memória aumentado para 512MB |
| 59 | ---------------------------------------------------- |
| 60 | Configuração aplicada em ./php.ini: |
| 61 | memory_limit = 512M |
| 62 | |
| 63 | Verificar no contêiner: |
| 64 | docker compose exec php php -r "echo ini_get('memory_limit');" |
| 65 | |
| 66 | Saída esperada: 512M |
| 67 | |
| 68 | ---------------------------------------------------- |
| 69 | 8. Correção do erro de exibição do projeto |
| 70 | ---------------------------------------------------- |
| 71 | Bug encontrado em ./index.php na função formatServices(): |
| 72 | |
| 73 | ANTES (incorreto): |
| 74 | return $services; // retornava o array, não a string HTML |
| 75 | |
| 76 | DEPOIS (correto): |
| 77 | return $servicesHtml; // retorna a string HTML montada |
| 78 | |
| 79 | Acessar o projeto em: http://localhost:8011 |
| 80 | |
| 81 | ---------------------------------------------------- |
| 82 | DESAFIO EXTRA 1: Versão da extensão pdo_sqlite |
| 83 | ---------------------------------------------------- |
| 84 | Comando para verificar: |
| 85 | docker compose exec php php -r " |
| 86 | \$pdo = new PDO('sqlite::memory:'); |
| 87 | \$stmt = \$pdo->query('SELECT sqlite_version()'); |
| 88 | echo 'SQLite version: ' . \$stmt->fetchColumn() . PHP_EOL; |
| 89 | echo 'pdo_sqlite version acompanha SQLite: ' . phpversion('pdo_sqlite') . PHP_EOL; |
| 90 | " |
| 91 | |
| 92 | Alternativa via phpinfo: |
| 93 | docker compose exec php php -r "phpinfo();" | grep -i sqlite |
| 94 | |
| 95 | ---------------------------------------------------- |
| 96 | DESAFIO EXTRA 2: Compilar o PHP |
| 97 | ---------------------------------------------------- |
| 98 | Passos disponíveis em: ../README.md |
| 99 | |
| 100 | Resumo: |
| 101 | 1. git clone --depth=1 [email protected]:php/php-src.git |
| 102 | 2. cd php-src && git checkout php-8.4.3 |
| 103 | 3. docker compose up -d && docker compose exec ubuntu bash |
| 104 | 4. apt update && apt install -y pkg-config build-essential \ |
| 105 | autoconf bison re2c libxml2-dev libsqlite3-dev |
| 106 | 5. ./buildconf |
| 107 | 6. ./configure --enable-debug |
| 108 | 7. make -j$(nproc) |
| 109 | 8. make test |
| 110 | 9. make install |
| 111 | |
| 112 | ==================================================== |
| 113 | Para rodar o projeto |
| 114 | ==================================================== |
| 115 | docker compose up -d |
| 116 | Acesse: http://localhost:8011 |
| 117 | ==================================================== |
| 118 |
| 1 | FROM php:8.2-fpm |
| 2 | |
| 3 | RUN apt-get update && apt-get install -y \ |
| 4 | libpq-dev \ |
| 5 | && docker-php-ext-install pdo_pgsql opcache |
| 6 | |
| 7 | RUN pecl install xdebug \ |
| 8 | && docker-php-ext-enable xdebug |
| 9 | |
| 10 | WORKDIR /var/www/html |
| 11 |
| 1 | services: |
| 2 | nginx: |
| 3 | image: nginx:latest |
| 4 | ports: |
| 5 | - "8080:80" |
| 6 | volumes: |
| 7 | - ./src:/var/www/html |
| 8 | - ./nginx/default.conf:/etc/nginx/conf.d/default.conf |
| 9 | depends_on: |
| 10 | - php |
| 11 | networks: |
| 12 | - app-network |
| 13 | |
| 14 | php: |
| 15 | image: lira/php:8.2-fpm-aula02 |
| 16 | volumes: |
| 17 | - ./src:/var/www/html |
| 18 | - ./php.ini:/usr/local/etc/php/conf.d/custom.ini |
| 19 | depends_on: |
| 20 | - db |
| 21 | networks: |
| 22 | - app-network |
| 23 | |
| 24 | db: |
| 25 | image: postgres:15 |
| 26 | environment: |
| 27 | POSTGRES_DB: mydatabase |
| 28 | POSTGRES_USER: user |
| 29 | POSTGRES_PASSWORD: password |
| 30 | ports: |
| 31 | - "5432:5432" |
| 32 | networks: |
| 33 | - app-network |
| 34 | |
| 35 | networks: |
| 36 | app-network: |
| 37 | driver: bridge |
| 38 |


This file can't be rendered. View the full file.