Olá pessoal.
Possuo um portal técnico da empresa em PHP e um sistema de CRM (do próprio ScriptCase modificado) sendo executado em nosso servidor, um dedicado com 8GB RAM com Windows Server 2012R2, porém estou tendo vários problemas que não estava tendo quando estava em um VPS Linux CentOS. Tanto o portal, que não foi feito em ScriptCase, quanto o CRM travam do nada, e só voltam a funcionar quando reinicio o serviço do Apache no servidor.
Eu realmente precisava do servidor dedicado em Windows, pois tenho o CobreBemX e preciso que seja executado em um servidor Windows.
Eu imaginei que iria perder somente performance nesses sistemas em PHP, não imaginei que iriam parar de funcionar de tempos em tempos.
Existe alguma configuração na instalação do Apache e do PHP que eu possa estar melhorando para corrigir esse problema?
Estou compartilhando com vocês um script do PowerShell que criei para facilitar minhas publicações de serviço, instala o Apache, PHP (como módulo do Apache ou com FastCGI), Zend e modifica as configurações. Pois imaginei que publicando em servidores Apache separados eu descobriria o problema, mas os dois param, tanto o que roda o sistema CRM quanto o meu portal técnico que é somente PHP.
clear
$tipoinst = ""
$svr = ""
$porta = ""
if ($args[0] -eq $null) {
$svr = read-host "Informe o nome do servidor"
} else {
$svr = $args[0]
}
if ($svr.Length -gt 0) {
if ($args[1] -eq $null) {
$porta = read-host "Informe a porta do servidor"
} else {
$porta = $args[1]
}
$tipoinst = read-host "Tipo de instalacao (M=Modulo do Apache, F=FastCGI)"
if (($tipoinst -eq "M") -or ($tipoinst -eq "m")) {
$tipoinst = "M"
" Instalacao como Modulo do Apache"
} else {
$tipoinst = "F"
" Instalacao como FastCGI"
}
if ($tipoinst -eq "M") {
"Configurando o servidor $svr . . ."
" "
$cmd = $env:ProgramFiles + "\7-Zip\7z.exe"
$par = "x ""D:\ApacheInst\httpd-2.4.10-win32-VC11.zip"" -o""D:\Servidores\" + $svr + """ -y"
"Descompactando o Apache 2.4.10 . . ."
start $cmd $par -wait -WindowStyle hidden
new-item ("D:\Servidores\" + $svr + "\www") -itemtype directory > nil
#$par = "x ""D:\ApacheInst\php-5.5.15-Win32-VC11-x86.zip"" -o""D:\Servidores\" + $svr + "\php5"" -y"
$par = "x ""D:\ApacheInst\php-5.4.32-Win32-VC9-x86.zip"" -o""D:\Servidores\" + $svr + "\php5"" -y"
"Descompactando o PHP 5.5.15 . . ."
start $cmd $par -wait -WindowStyle hidden
"Modificando a configuracao do Apache . . ."
$arqconf = "D:\Servidores\" + $svr + "\Apache24\conf\httpd.conf"
$conf = (get-content $arqconf)
$newconf = @()
$ignorar = 0
foreach ($l in $conf) {
switch -wildcard ($l) {
"ServerRoot *" { $newconf += "ServerRoot ""D:\Servidores\" + $svr + "\Apache24""" }
"Listen *" { $newconf += "Listen " + $porta }
"DocumentRoot ""c:/Apache24*" { $newconf += "DocumentRoot ""D:\Servidores\" + $svr + "\www""" }
"<Directory ""c:/Apache24/htdocs"">" { $newconf += "<Directory ""D:\Servidores\" + $svr + "\www"">" }
" ScriptAlias /cgi-bin/ ""c:/Apache24*" { $newconf += " ScriptAlias /cgi-bin/ ""D:\Servidores\" + $svr + "\Apache24\cgi-bin""" }
"<Directory ""c:/Apache24/cgi-bin"">" { $newconf += "<Directory ""D:\Servidores\" + $svr + "\Apache24\cgi-bin"">" }
"<IfModule unixd_module>" {
$newconf += "LoadModule php5_module ""D:/Servidores/" + $svr + "/php5/php5apache2_4.dll"""
$newconf += ""
$newconf += "PHPIniDir ""D:/Servidores/" + $svr + "/php5"""
$newconf += "AddType application/x-httpd-php .php"
$newconf += $l
}
"ServerAdmin admin@example.com" { $newconf += "ServerAdmin webadmin@fantastsoft.com.br" }
"<Directory />" {
$newconf += "<Directory />"
$newconf += " Options Indexes FollowSymLinks Includes ExecCGI"
$newconf += " AllowOverride All"
$newconf += " Order deny,allow"
$newconf += " Allow from all"
$ignorar = 1
}
"</Directory>" {
$newconf += $l
$ignorar = 0
}
" DirectoryIndex index.html" { $newconf += " DirectoryIndex index.php index.html" }
Default {
if ($ignorar -eq 0) {
$newconf += $l
}
}
}
}
Set-Content $arqconf $newconf
$arqhtml = "D:\Servidores\" + $svr + "\www\index.php"
$html = "<html><body>"
$html += "<h1>Servidor web Funcional</h1><h2>$svr</h2><br>"
$html += "<?php"
$html += " phpinfo();"
$html += "?>"
$html += "</body></html>"
Set-Content $arqhtml $html
copy-item "D:\ApacheInst\favicon.ico" ("D:\Servidores\" + $svr + "\www") -force > nil
"Modificando a configuracao do PHP . . ."
copy-item "D:\ApacheInst\ZendLoader.dll" ("D:\Servidores\" + $svr + "\php5\ext\ZendLoader.dll") -force > nil
copy-item "D:\ApacheInst\pgsql\*.dll" ("D:\Servidores\" + $svr + "\php5") -force > nil
$arqconf = "D:\Servidores\" + $svr + "\php5\php.ini"
copy-item ($arqconf + "-production") $arqconf -force > nil
$conf = (get-content $arqconf)
$newconf = @()
foreach ($l in $conf) {
switch -wildcard ($l) {
"; extension_dir = ""ext""" {
$newconf += "extension_dir = ""D:\Servidores\" + $svr + "\php5\ext"""
}
";extension=php_curl.dll" { $newconf += "extension=php_curl.dll" }
";extension=php_fileinfo.dll" { $newconf += "extension=php_fileinfo.dll" }
";extension=php_gd2.dll" { $newconf += "extension=php_gd2.dll" }
";extension=php_gettext.dll" { $newconf += "extension=php_gettext.dll" }
";extension=php_intl.dll" { $newconf += "extension=php_intl.dll" }
";extension=php_interbase.dll" { $newconf += "extension=php_interbase.dll" }
";extension=php_ldap.dll" { $newconf += "extension=php_ldap.dll" }
";extension=php_mbstring.dll" { $newconf += "extension=php_mbstring.dll" }
";extension=php_mysql.dll" { $newconf += "extension=php_mysql.dll" }
";extension=php_mysqli.dll" { $newconf += "extension=php_mysqli.dll" }
";extension=php_openssl.dll" { $newconf += "extension=php_openssl.dll" }
";extension=php_pdo_firebird.dll" { $newconf += "extension=php_pdo_firebird.dll" }
";extension=php_pdo_mysql.dll" { $newconf += "extension=php_pdo_mysql.dll" }
";extension=php_pdo_pgsql.dll" { $newconf += "extension=php_pdo_pgsql.dll" }
";extension=php_pdo_sqlite.dll" { $newconf += "extension=php_pdo_sqlite.dll" }
";extension=php_pgsql.dll" { $newconf += "extension=php_pgsql.dll" }
";extension=php_soap.dll" { $newconf += "extension=php_soap.dll" }
";extension=php_sockets.dll" { $newconf += "extension=php_sockets.dll" }
";extension=php_sqlite3.dll" { $newconf += "extension=php_sqlite3.dll" }
";extension=php_xsl.dll" { $newconf += "extension=php_xsl.dll" }
";date.timezone =" { $newconf += "date.timezone = America/Sao_Paulo" }
";error_log = syslog" { $newconf += "error_log = php_errors.log" }
"upload_max_filesize = *" { $newconf += "upload_max_filesize = 100M" }
"post_max_size = *" { $newconf += "post_max_size = 100M" }
Default { $newconf += $l }
}
}
$newconf += ""
$newconf += "[Zend]"
$newconf += "zend_extension=ZendLoader.dll"
$newconf += "zend_loader.enable=1"
$newconf += "zend_loader.disable_licensing=0"
$newconf += "zend_loader.license_path="
$newconf += ""
Set-Content $arqconf $newconf
"Instalando o servico do Apache . . ."
$cmd = "D:\Servidores\" + $svr + "\Apache24\bin\httpd.exe"
$par = "-k install -n Apache_$svr"
start $cmd $par -wait -WindowStyle hidden
"Iniciando o servico do Apache . . ."
$par = "-k start -n Apache_$svr"
start $cmd $par -wait -WindowStyle hidden
" "
" "
"Concluido!"
" "
start ("http://localhost:$porta")
} else {
"Configurando o servidor $svr . . ."
" "
$cmd = $env:ProgramFiles + "\7-Zip\7z.exe"
"Descompactando o Apache 2.4.10 . . ."
$par = "x ""D:\ApacheInst\httpd-2.4.10-win32-VC11.zip"" -o""D:\Servidores\" + $svr + """ -y"
start $cmd $par -wait -WindowStyle hidden
new-item ("D:\Servidores\" + $svr + "\www") -itemtype directory > nil
new-item ("D:\Servidores\" + $svr + "\tmp") -itemtype directory > nil
copy-item "D:\ApacheInst\modules-2.4-win32-VC11\mod_fcgid-2.3.9\mod_fcgid\mod_fcgid.so" ("D:\Servidores\" + $svr + "\apache24\modules") -force > nil
#"Descompactando o PHP 5.5.15 . . ."
#$par = "x ""D:\ApacheInst\php-5.5.15-Win32-VC11-x86.zip"" -o""D:\Servidores\" + $svr + "\php5"" -y"
"Descompactando o PHP 5.4.32 . . ."
$par = "x ""D:\ApacheInst\php-5.4.32-nts-Win32-VC9-x86.zip"" -o""D:\Servidores\" + $svr + "\php5"" -y"
start $cmd $par -wait -WindowStyle hidden
"Modificando a configuracao do Apache . . ."
$arqconf = "D:\Servidores\" + $svr + "\Apache24\conf\httpd.conf"
$conf = (get-content $arqconf)
$newconf = @()
$ignorar = 0
foreach ($l in $conf) {
switch -wildcard ($l) {
"ServerRoot *" { $newconf += "ServerRoot ""D:\Servidores\" + $svr + "\Apache24""" }
"Listen *" { $newconf += "Listen " + $porta }
"DocumentRoot ""c:/Apache24*" { $newconf += "DocumentRoot ""D:\Servidores\" + $svr + "\www""" }
"<Directory ""c:/Apache24/htdocs"">" {
$newconf += "<Directory ""D:\Servidores\" + $svr + "\www"">"
$newconf += " Options Indexes FollowSymLinks ExecCGI"
$newconf += " AllowOverride None"
$newconf += " Require all granted"
$ignorar = 1
}
" ScriptAlias /cgi-bin/ ""c:/Apache24*" { $newconf += " ScriptAlias /cgi-bin/ ""D:\Servidores\" + $svr + "\Apache24\cgi-bin""" }
"<Directory ""c:/Apache24/cgi-bin"">" { $newconf += "<Directory ""D:\Servidores\" + $svr + "\Apache24\cgi-bin"">" }
"<IfModule unixd_module>" {
$newconf += "LoadModule fcgid_module modules/mod_fcgid.so"
$newconf += ""
$newconf += "FcgidInitialEnv PATH ""D:/Servidores/" + $svr + "/php5;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"""
$newconf += "FcgidInitialEnv SystemRoot ""C:/Windows"""
$newconf += "FcgidInitialEnv TEMP ""D:/Servidores/" + $svr + "/tmp"""
$newconf += "FcgidInitialEnv TMP ""D:/Servidores/" + $svr + "/tmp"""
$newconf += "FcgidInitialEnv windir ""C:/WINDOWS"""
$newconf += "FcgidIOTimeout 64"
$newconf += "FcgidConnectTimeout 16"
$newconf += "FcgidMaxRequestsPerProcess 1000"
$newconf += "FcgidMaxProcesses 50 "
$newconf += "FcgidMaxRequestLen 8131072"
$newconf += "FcgidInitialEnv PHPRC ""D:/Servidores/" + $svr + "/php5"""
$newconf += "FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000"
$newconf += ""
$newconf += ""
$newconf += "<Files ~ ""\.php$"">"
$newconf += " AddHandler fcgid-script .php"
$newconf += " FcgidWrapper ""D:/Servidores/" + $svr + "/php5/php-cgi.exe"" .php"
$newconf += "</Files>"
$newconf += $l
}
"ServerAdmin admin@example.com" { $newconf += "ServerAdmin webadmin@fantastsoft.com.br" }
"<Directory />" {
$newconf += "<Directory />"
$newconf += " Options Indexes FollowSymLinks Includes ExecCGI"
$newconf += " AllowOverride All"
$newconf += " Order deny,allow"
$newconf += " Allow from all"
$ignorar = 1
}
"</Directory>" {
$newconf += $l
$ignorar = 0
}
" DirectoryIndex index.html" { $newconf += " DirectoryIndex index.php index.html" }
Default {
if ($ignorar -eq 0) {
$newconf += $l
}
}
}
}
Set-Content $arqconf $newconf
$arqhtml = "D:\Servidores\" + $svr + "\www\index.php"
$html = "<html><body>"
$html += "<h1>Servidor web Funcional</h1><h2>$svr</h2><br>"
$html += "<?php"
$html += " phpinfo();"
$html += "?>"
$html += "</body></html>"
Set-Content $arqhtml $html
copy-item "D:\ApacheInst\favicon.ico" ("D:\Servidores\" + $svr + "\www") -force > nil
"Modificando a configuracao do PHP . . ."
copy-item "D:\ApacheInst\ZendLoader.dll" ("D:\Servidores\" + $svr + "\php5\ext\ZendLoader.dll") -force > nil
copy-item "D:\ApacheInst\pgsql\*.dll" ("D:\Servidores\" + $svr + "\php5") -force > nil
$arqconf = "D:\Servidores\" + $svr + "\php5\php.ini"
copy-item ($arqconf + "-production") $arqconf -force > nil
$conf = (get-content $arqconf)
$newconf = @()
foreach ($l in $conf) {
switch -wildcard ($l) {
"doc_root =*" { $newconf += ";doc_root =" }
"; extension_dir = ""ext""" {
$newconf += "extension_dir = ""D:\Servidores\" + $svr + "\php5\ext"""
}
";extension=php_curl.dll" { $newconf += "extension=php_curl.dll" }
";extension=php_fileinfo.dll" { $newconf += "extension=php_fileinfo.dll" }
";extension=php_gd2.dll" { $newconf += "extension=php_gd2.dll" }
";extension=php_gettext.dll" { $newconf += "extension=php_gettext.dll" }
";extension=php_intl.dll" { $newconf += "extension=php_intl.dll" }
";extension=php_interbase.dll" { $newconf += "extension=php_interbase.dll" }
";extension=php_ldap.dll" { $newconf += "extension=php_ldap.dll" }
";extension=php_mbstring.dll" { $newconf += "extension=php_mbstring.dll" }
";extension=php_mysql.dll" { $newconf += "extension=php_mysql.dll" }
";extension=php_mysqli.dll" { $newconf += "extension=php_mysqli.dll" }
";extension=php_openssl.dll" { $newconf += "extension=php_openssl.dll" }
";extension=php_pdo_firebird.dll" { $newconf += "extension=php_pdo_firebird.dll" }
";extension=php_pdo_mysql.dll" { $newconf += "extension=php_pdo_mysql.dll" }
";extension=php_pdo_pgsql.dll" { $newconf += "extension=php_pdo_pgsql.dll" }
";extension=php_pdo_sqlite.dll" { $newconf += "extension=php_pdo_sqlite.dll" }
";extension=php_pgsql.dll" { $newconf += "extension=php_pgsql.dll" }
";extension=php_soap.dll" { $newconf += "extension=php_soap.dll" }
";extension=php_sockets.dll" { $newconf += "extension=php_sockets.dll" }
";extension=php_sqlite3.dll" { $newconf += "extension=php_sqlite3.dll" }
";extension=php_xsl.dll" { $newconf += "extension=php_xsl.dll" }
";date.timezone =" { $newconf += "date.timezone = America/Sao_Paulo" }
";error_log = syslog" { $newconf += "error_log = php_errors.log" }
"upload_max_filesize = *" { $newconf += "upload_max_filesize = 100M" }
"post_max_size = *" { $newconf += "post_max_size = 100M" }
Default { $newconf += $l }
}
}
$newconf += ""
$newconf += "[Zend]"
$newconf += "zend_extension=ZendLoader.dll"
$newconf += "zend_loader.enable=1"
$newconf += "zend_loader.disable_licensing=0"
$newconf += "zend_loader.license_path="
$newconf += ""
Set-Content $arqconf $newconf
"Instalando o servico do Apache . . ."
$cmd = "D:\Servidores\" + $svr + "\Apache24\bin\httpd.exe"
$par = "-k install -n Apache_$svr"
start $cmd $par -wait -WindowStyle hidden
"Iniciando o servico do Apache . . ."
$par = "-k start -n Apache_$svr"
start $cmd $par -wait -WindowStyle hidden
" "
" "
"Concluido!"
" "
start ("http://localhost:$porta")
}
}