Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save safdar-tp/b7d282f25c86d029853451acf2a98904 to your computer and use it in GitHub Desktop.
Save safdar-tp/b7d282f25c86d029853451acf2a98904 to your computer and use it in GitHub Desktop.
CentOS 7 - Apache 2.4 + MOD_PROXY_FCGI + PHP-FPM 5.5 + InstantClient Oracle.

CentOS 7 - Apache 2.4 + PHP-FPM 5.5 + InstantClient Oracle.


Montando uma VM para o desenvolvimento de aplicações em PHP, utilizado o CentOS 7

(EM DESENVOLVIMENTO)

Downloads

Downloads de ferramentas e bibliotecas necessárias para a instalação da VM

Realize o download do arquivo oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm.

Realize a instalação do WinSCP, VMware Player e crie uma VM com a ISO do CentOS 7.

Como pretendo simular um ambiente de produção. Minha VM foi criada com as seguintes configurações:

  • Memory 2 GB
  • Processors 4
  • HD 20GB
  • Network NAT

Durante o processo de instalação a VM pegou o IP (192.168.183.134), guarde o seu IP gerado para acesso via WinSCP/SSH.

Instalação

Utilizando a ferramenta WinSCP, realize a cópia do arquivo oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm, para a sua VM e jogue na pasta "/tmp".

Acesse o terminal da VM, pelo WinSCP use "Ctrl+P" que será aberto o terminal. Vamos começar a brincadeira.

Por se tratar de uma VM de desenvolvimento local, vou desabilitar o Firewall e Selinux, que vem instalado e configurado por default. Caso for utilizar esse exemplo para outros ambientes recomendo que deixe os 2(dois) em funcionamento.

systemctl stop firewalld
systemctl disable firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
reboot

Instalação dos RPMs e Repositórios necessários

yum install net-tools nano wget libaio
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-1.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -ivh /tmp/oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
echo '/usr/lib/oracle/12.1/client64/lib/' > /etc/ld.so.conf.d/Oracle-InstantClient-12.1.conf
ldconfig
yum update
reboot

Para evitar surpresas, realizei mais um reboot para validar a atualização de kernel.

Instalação do Apache, PHP e libs.

yum --enablerepo=remi,remi-php55 install httpd php-fpm php-common php-pecl-apcu php-gd php-intl php-mbstring php-mssql php-mysql php-mysqlnd php-oci8 php-xmlrpc php-openssl php-pgsql php-soap php-opcache php-mcrypt

Iniciando o serviço do Apache, setando para que seja iniciado ao boot e verificando o status.

systemctl start httpd.service
systemctl enable httpd.service
systemctl status httpd.service -l

Removendo o Warning da falta de ServerName do Apache.

echo "ServerName localhost" >> /etc/httpd/conf.d/servername.conf

Iniciando o serviço do PHP-FPM, setando para que seja iniciado ao boot e verificando o status.

systemctl start php-fpm.service
systemctl enable php-fpm.service
systemctl status php-fpm.service -l

Criando o arquivo info.php para validar as configurações do PHP.

printf '<?php\n   phpinfo();' > /var/www/html/info.php

Criando um VirtualHost utilizando o mod_proxy_fcgi

nano /etc/httpd/conf.d/localhost.conf
<VirtualHost *:80>
    
    ServerName localhost
    
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1

    DocumentRoot /var/www/html
    <Directory /var/www/html>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog /var/log/httpd/localhost_error.log
    CustomLog /var/log/httpd/localhost_access.log combined
</VirtualHost>
systemctl restart httpd.service
systemctl status httpd.service -l

Para validar as configurações acesse via navegador os endereços:

Configuração Apache

Como meu apache vai servir apenas como um proxy para o php-fpm, vou utilizar o MPM Event (EM TESTE).

nano /etc/httpd/conf.modules.d/00-mpm.conf
# Select the MPM module which should be used by uncommenting exactly
# one of the following LoadModule lines:

# prefork MPM: Implements a non-threaded, pre-forking web server
# See: http://httpd.apache.org/docs/2.4/mod/prefork.html
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

# worker MPM: Multi-Processing Module implementing a hybrid
# multi-threaded multi-process web server
# See: http://httpd.apache.org/docs/2.4/mod/worker.html
#
#LoadModule mpm_worker_module modules/mod_mpm_worker.so

# event MPM: A variant of the worker MPM with the goal of consuming
# threads only for connections with active processing
# See: http://httpd.apache.org/docs/2.4/mod/event.html
#
LoadModule mpm_event_module modules/mod_mpm_event.so
systemctl restart httpd.service
Configuração PHP

nano /etc/php.ini

Altere as seguintes linhas:

date.timezone = "America/Sao_Paulo"
default_charset = "UTF-8"
systemctl restart php-fpm.service
Configuração InstantClient Oracle

Configurações das Variáveis de Ambiente.

nano /etc/sysconfig/php-fpm

Incluir no arquivo o NLS_LANG, conforme arquivo abaixo:

# Additional environment file for php-fpm

# This file is deprecated when systemd is used and
# will be removed in the future

# To alter the FPM environment, copy the unit file
# from /usr/lib/systemd/system/php-fpm.service
# to   /etc/systemd/system/php-fpm.service
# and add an Environment line

# With systemd >= 204 you can simply drop a file with the
# suffix .conf in /etc/systemd/system/php-fpm.service.d, with
#     [Service]
#     Environment=FOO=bar

# See systemd documentation.
#    man systemd.unit
#    man systemd.exec

NLS_LANG = 'BRAZILIAN PORTUGUESE_BRAZIL.AL32UTF8'

Próximo passo é incluir as variáveis no pool do php-fpm

nano /etc/php-fpm.d/www.conf

Segue conteúdo e local aonde deve ser incluido.

...

; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
env[HOSTNAME] = 'localhost'
env[NLS_LANG] = 'BRAZILIAN PORTUGUESE_BRAZIL.AL32UTF8'
env[NLS_TERRITORY] = 'BRAZIL'
env[NLS_DUAL_CURRENCY] = 'R$'
env[NLS_CURRENCY] = 'R$'
env[NLS_ISO_CURRENCY] = 'BRAZIL'
env[NLS_DATE_LANGUAGE] = 'BRAZILIAN PORTUGUESE'
env[NLS_DATE_FORMAT] = 'DD/MM/YYYY'
env[NLS_TIME_FORMAT] = 'HH24:MI:SS'
env[NLS_TIMESTAMP_FORMAT] = 'DD/MM/YYYY HH24:MI:SS'

...
systemctl restart php-fpm.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment