Instalar Nginx, PHP-7.0 y MariaDB en Windows

Debido a que tenemos un proyecto entre manos, ayer me decidi a realizar una instalacion de NGINX, PHP-7.0 y MariaDB en Windows, de esta forma, puedo testear en Windows dicha instalacion, aunque no me gusta nada, hay a quien si le gusta y este interesado en estos tipos de instalaciones.

Pues bien vamos a empezar.

Nos drigimos a NGINX ahi descargamos NGINX para windows, esta en formato zip, lo descomprimimos en la C:\ ,la carpeta la podemos llamar nginx o yo la he llamado por su verison C:\nginx-1.10.2

Hasta aqui facil no, seguimos con PHP 7

Nos dirigimos a la pagina de descarga de php-7.0 para windows

https://windows.php.net/download#php-7.0

Yo he elejido la Non Thread Safe, ya que se ejecutara como binario CGI

VC14 x64 Non Thread Safe

Una vez descargado le descomprimimos en la C:\ o com en mi caso en C:\nginx-1.10.2\php

Vamos a configurar NGINX para ejecutar PHP

Dentro de la carpeta conf en el directorio de NGINX, tenemos el fichero nginx.conf, sobre la linea 65 tenemos que descomentar las siguientes lineas y modificar con nuestra eleccion de directorios etc

location ~ \.php$ {
root           html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include        fastcgi_params;
}

por la linea 45 anadimos index.php, quedandonos asi

index  index.html index.htm index.php;

Yo he seguido este hilo https://www.nginx.com/resources/wiki/start/topics/examples/phpfastcgionwindows/ y he creado estos scripts

start_nginx.bat

@echo off
echo Starting PHP FastCGI...
set PATH=c:\nginx-1.10.2\php;%PATH%
cd c:\nginx-1.10.2\
start nginx
c:\nginx-1.10.2\php\RunHiddenConsole.exe c:\nginx-1.10.2\php\php-cgi.exe -b 127.0.0.1:9000 -c c:\nginx-1.10.2\php\php.ini
exit

stop_nginx.bat

@echo off
taskkill /f /im nginx.exe
taskkill /f /im php-cgi.exe
exit

Con esto ya tenemos NGINX funionando con php-7.0, ahora vamos por MariaDB

Nos dirigimos  la web de descarga https://downloads.mariadb.org/mariadb/10.1.18/

Ahi seleccionamos mariadb-10.1.18-winx64.msi

Una vez descargado el ejecutable clic clic clic, atotclic.

Para configurar mysqli descomentamos o modificamos las siguientes lineas en C:\nginx-1.10.2\php\php.ini

extension_dir = C:/nginx-1.10.2/php/ext

extension=php_mysqli.dll

extension=php_pdo_mysql.dll

Si habiamos ejecutado el script start_nginx.bat ejecutamos estop o hacemos un reload a nginx

accedemos al directorio de NGINX y

nginx.exe -s reload

Para comprobar php info.php

<?php
phpinfo();
?>

Para comprobar MariaDB

mysql_test.php

<?php
// Conexión a la base de datos
$base = mysqli_connect("127.0.0.1", "root", "password", "mysql");
if ($base) {
echo 'Conexión realizada.<br />';
echo 'Información del servidor:'.mysqli_GET_host_info($base).
'<br />';
$sql = "select host, user FROM user";
// Preparación de la consulta
$resultado = mysqli_prepare($base, $sql);
// Ejecución de la consulta.
$ok = mysqli_stmt_execute($resultado);
if ($ok == FALSE) {
echo "Error en la ejecución de la consulta.<br />";
}
else {
// Asociación de variables de resultado.
$ok = mysqli_stmt_bind_result($resultado,$host,$user);
// Lectura de valores.
echo "Host y usuario tabla user<br />";
while (mysqli_stmt_fetch($resultado)) {
echo $host.", ".$user."<br />";
}
mysqli_stmt_close($resultado);
}
if (mysqli_close($base)) {
echo 'Desconexión realizada.<br />';
}
else {
echo 'Error en la desconexión.';
}
}
else {
printf('Error %d : %s.<br/ >',mysqli_connect_errno(),
mysqli_connect_error());
}
?>

Esto es todo, un servidor web funcionando en menos de una hora.

Habilitar archivelog

[oracle@vbgeneric backup]$ sqlplus /nolog

SQL*Plus: Release 12.1.0.2.0 Production on Mon Oct 17 17:11:37 2016

Copyright (c) 1982, 2014, Oracle. All rights reserved.

SQL> connect sys/oracle@localhost:1521/orcl12c as sysdba
Connected.

SQL> SHUTDOWN
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> STARTUP MOUNT
ORACLE instance started.

Total System Global Area  838860800 bytes
Fixed Size            2929936 bytes
Variable Size          608176880 bytes
Database Buffers      222298112 bytes
Redo Buffers            5455872 bytes
Database mounted.
SQL> ALTER DATABASE ARCHIVELOG;

Database altered.

SQL> ALTER DATABASE OPEN;

Database altered.

SQL> SELECT LOG_MODE FROM SYS.V$DATABASE;

LOG_MODE
————
ARCHIVELOG

SQL>

Backup RMAN Oracle 12c en modo noarchivelog

Nos connectamos a RMAN

[oracle@vbgeneric oracle]$ rman

Recovery Manager: Release 12.1.0.2.0 – Production on Sun Oct 16 13:17:01 2016

Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.

Nos connectamos con el usuario sys a la instancia orlc12c donde esta la CDB

RMAN> connect target «sys/oracle@localhost:1521/orcl12c as sysdba»

connected to target database: ORCL12C (DBID=743937264)

Ejecutamos el backup

RMAN> backup database;

Starting backup at 16-OCT-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=27 device type=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 10/16/2016 13:12:29
RMAN-06149: cannot BACKUP DATABASE in NOARCHIVELOG mode

Nos da error debido a que la base de datos esta en modo noarchivelog

RMAN> exit

Recovery Manager complete.

Revisamos las variables de entorno

[oracle@vbgeneric oracle]$ env|grep SID
ORACLE_SID=orcl12c

Miramos si esta la variable NLS_DATE_FORMAT

[oracle@vbgeneric oracle]$ env|grep NSL

No obtenemos ningun resultado

[oracle@vbgeneric oracle]$ echo «export NLS_DATE_FORMAT=’DD-MM-RRRR HH24:MI:SS'» >> .bash_profile

Agregamos la variable al profile

[oracle@vbgeneric oracle]$ export NLS_DATE_FORMAT=’DD-MM-RRRR HH24:MI:SS’

Exportamos la variable y volvemos a acceder a RMAN

[oracle@vbgeneric oracle]$ rman

Recovery Manager: Release 12.1.0.2.0 – Production on Sun Oct 16 13:17:01 2016

Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.

Nos volvemos a connectar al CDB

RMAN> connect target «sys/oracle@localhost:1521/orcl12c as sysdba»

connected to target database: ORCL12C (DBID=743937264)
using target database control file instead of recovery catalog

Paramos la instancia

RMAN> shutdown immediate;

database closed
database dismounted
Oracle instance shut down

Levantamos la instancia sin abrirla

RMAN> startup mount;

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area 838860800 bytes

Fixed Size 2929936 bytes
Variable Size 608176880 bytes
Database Buffers 222298112 bytes
Redo Buffers 5455872 bytes

Realizamos el backup

RMAN> backup database;

Starting backup at 16-10-2016 13:19:11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00011 name=/u01/app/oracle/oradata/orcl12c/orcl/example01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/orcl12c/orcl/sysaux01.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/orcl12c/orcl/system01.dbf
input datafile file number=00010 name=/u01/app/oracle/oradata/orcl12c/orcl/SAMPLE_SCHEMA_users01.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/orcl12c/orcl/APEX_1851336378250219.dbf
input datafile file number=00013 name=/u01/app/oracle/oradata/orcl12c/orcl/APEX_5457999048253711.dbf
channel ORA_DISK_1: starting piece 1 at 16-10-2016 13:19:13
channel ORA_DISK_1: finished piece 1 at 16-10-2016 13:20:08
piece handle=/u01/app/oracle/fast_recovery_area/ORCL12C/344AC7178F061E05E0530100007F0C70/backupset/2016_10_16/o1_mf_nnndf_TAG20161016T131912_d07fnl03_.bkp tag=TAG20161016T131912 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl12c/sysaux01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl12c/system01.dbf
input datafile file number=00017 name=/u01/app/oracle/oradata/orcl12c/undotbs2.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/orcl12c/users01.dbf
channel ORA_DISK_1: starting piece 1 at 16-10-2016 13:20:09
channel ORA_DISK_1: finished piece 1 at 16-10-2016 13:20:44
piece handle=/u01/app/oracle/fast_recovery_area/ORCL12C/backupset/2016_10_16/o1_mf_nnndf_TAG20161016T131912_d07fp9hs_.bkp tag=TAG20161016T131912 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00015 name=/u01/app/oracle/oradata/orcl12c/ORDS/sysaux01.dbf
input datafile file number=00014 name=/u01/app/oracle/oradata/orcl12c/ORDS/system01.dbf
input datafile file number=00016 name=/u01/app/oracle/oradata/orcl12c/ORDS/users01.dbf
channel ORA_DISK_1: starting piece 1 at 16-10-2016 13:20:45
channel ORA_DISK_1: finished piece 1 at 16-10-2016 13:21:10
piece handle=/u01/app/oracle/fast_recovery_area/ORCL12C/344C19EC2BA1043AE0530100007F8552/backupset/2016_10_16/o1_mf_nnndf_TAG20161016T131912_d07fqfjj_.bkp tag=TAG20161016T131912 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:26
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/u01/app/oracle/oradata/orcl12c/pdbseed/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl12c/pdbseed/system01.dbf
channel ORA_DISK_1: starting piece 1 at 16-10-2016 13:21:10
channel ORA_DISK_1: finished piece 1 at 16-10-2016 13:21:36
piece handle=/u01/app/oracle/fast_recovery_area/ORCL12C/344AA75FC7C01B5AE0530100007FDC99/backupset/2016_10_16/o1_mf_nnndf_TAG20161016T131912_d07fr78x_.bkp tag=TAG20161016T131912 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:26
Finished backup at 16-10-2016 13:21:36

Starting Control File and SPFILE Autobackup at 16-10-2016 13:21:36
piece handle=/u01/app/oracle/fast_recovery_area/ORCL12C/autobackup/2016_10_16/o1_mf_s_925391901_d07fs6gx_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 16-10-2016 13:21:51

El backup ha finalizado correctamente, hacemos un listado de los backups

RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— ——————-
1 Full 1.46G DISK 00:00:44 16-10-2016 13:19:57
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20161016T131912
Piece Name: /u01/app/oracle/fast_recovery_area/ORCL12C/344AC7178F061E05E0530100007F0C70/backupset/2016_10_16/o1_mf_nnndf_TAG20161016T131912_d07fnl03_.bkp
List of Datafiles in backup set 1
Container ID: 3, PDB Name: ORCL
File LV Type Ckp SCN Ckp Time Name
—- — —- ———- ——————- —-
8 Full 2817455 16-10-2016 13:18:07 /u01/app/oracle/oradata/orcl12c/orcl/system01.dbf
9 Full 2817455 16-10-2016 13:18:07 /u01/app/oracle/oradata/orcl12c/orcl/sysaux01.dbf
10 Full 2817455 16-10-2016 13:18:07 /u01/app/oracle/oradata/orcl12c/orcl/SAMPLE_SCHEMA_users01.dbf
11 Full 2817455 16-10-2016 13:18:07 /u01/app/oracle/oradata/orcl12c/orcl/example01.dbf
12 Full 2817455 16-10-2016 13:18:07 /u01/app/oracle/oradata/orcl12c/orcl/APEX_1851336378250219.dbf
13 Full 2817455 16-10-2016 13:18:07 /u01/app/oracle/oradata/orcl12c/orcl/APEX_5457999048253711.dbf

BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— ——————-
2 Full 1.18G DISK 00:00:29 16-10-2016 13:20:38
BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20161016T131912
Piece Name: /u01/app/oracle/fast_recovery_area/ORCL12C/backupset/2016_10_16/o1_mf_nnndf_TAG20161016T131912_d07fp9hs_.bkp
List of Datafiles in backup set 2
File LV Type Ckp SCN Ckp Time Name
—- — —- ———- ——————- —-
1 Full 2817670 16-10-2016 13:18:21 /u01/app/oracle/oradata/orcl12c/system01.dbf
3 Full 2817670 16-10-2016 13:18:21 /u01/app/oracle/oradata/orcl12c/sysaux01.dbf
6 Full 2817670 16-10-2016 13:18:21 /u01/app/oracle/oradata/orcl12c/users01.dbf
17 Full 2817670 16-10-2016 13:18:21 /u01/app/oracle/oradata/orcl12c/undotbs2.dbf

BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— ——————-
3 Full 614.79M DISK 00:00:19 16-10-2016 13:21:03
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20161016T131912
Piece Name: /u01/app/oracle/fast_recovery_area/ORCL12C/344C19EC2BA1043AE0530100007F8552/backupset/2016_10_16/o1_mf_nnndf_TAG20161016T131912_d07fqfjj_.bkp
List of Datafiles in backup set 3
Container ID: 4, PDB Name: ORDS
File LV Type Ckp SCN Ckp Time Name
—- — —- ———- ——————- —-
14 Full 2817454 16-10-2016 13:18:06 /u01/app/oracle/oradata/orcl12c/ORDS/system01.dbf
15 Full 2817454 16-10-2016 13:18:06 /u01/app/oracle/oradata/orcl12c/ORDS/sysaux01.dbf
16 Full 2817454 16-10-2016 13:18:06 /u01/app/oracle/oradata/orcl12c/ORDS/users01.dbf

BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— ——————-
4 Full 606.45M DISK 00:00:21 16-10-2016 13:21:31
BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TAG20161016T131912
Piece Name: /u01/app/oracle/fast_recovery_area/ORCL12C/344AA75FC7C01B5AE0530100007FDC99/backupset/2016_10_16/o1_mf_nnndf_TAG20161016T131912_d07fr78x_.bkp
List of Datafiles in backup set 4
Container ID: 2, PDB Name: PDB$SEED
File LV Type Ckp SCN Ckp Time Name
—- — —- ———- ——————- —-
5 Full 2013568 02-06-2016 07:48:44 /u01/app/oracle/oradata/orcl12c/pdbseed/system01.dbf
7 Full 2013568 02-06-2016 07:48:44 /u01/app/oracle/oradata/orcl12c/pdbseed/sysaux01.dbf

BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— ——————-
5 Full 17.20M DISK 00:00:05 16-10-2016 13:21:42
BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TAG20161016T132136
Piece Name: /u01/app/oracle/fast_recovery_area/ORCL12C/autobackup/2016_10_16/o1_mf_s_925391901_d07fs6gx_.bkp
SPFILE Included: Modification time: 16-10-2016 13:19:11
SPFILE db_unique_name: ORCL12C
Control File Included: Ckp SCN: 2817670 Ckp time: 16-10-2016 13:18:21

Volvemos a abrir la base de datos

RMAN> startup

database is already started
database opened

RMAN>exit

[oracle@vbgeneric oracle]$ sqlplus /nolog

SQL*Plus: Release 12.1.0.2.0 Production on Sun Oct 16 14:35:11 2016

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

SQL> conn hr
Enter password:
Connected.

SQL> SELECT con_name, instance_name, state FROM dba_pdb_saved_states;

CON_NAME
———-
INSTANCE_N
———-
STATE
———-
ORCL
orcl12c
OPEN