Servidor HTTP

Apache2

Instalación

root@server:~# apt-get install apache2 apache2-doc

Verificación

En un navegador web, debemos escribir la dirección del servidor (http://192.168.1.100):

SSL

Objetivo

La adición del soporte ssl al servidor web permite establecer conexiones seguras y encriptadas entre el servidor y el cliente. De este modo, es posible cambiar contraseñas, con la certeza de que éstas no podrán ser interceptadas por terceros.

De esta forma, es posible usar conexiones seguras como base para la implementación de otros servicios como, por ejemplo, un servidor webmail.

Configuración

Durante la instalación de apache2 se crea una configuración para acceso seguro (https). Por tanto, esta configuración debe ser modificada para incluir los certificados auto-firmados generados previamente.

Esta configuración se almacena en el archivo /etc/apache2/sites-available/default-ssl:

/etc/apache2/sites-available/default-ssl
# [...]

        #   SSL Engine Switch:
        #   Enable/Disable SSL for this virtual host.
        SSLEngine on

        #   A self-signed (snakeoil) certificate can be created by installing
        #   the ssl-cert package. See
        #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
        #   If both key and certificate are stored in the same file, only the
        #   SSLCertificateFile directive is needed.
        SSLCertificateFile     /etc/ssl/certs/server.crt
        SSLCertificateKeyFile  /etc/ssl/private/server.key

# [...]

Después, debe activarse el módulo ssl:

root@server:~# a2enmod ssl
Enabling module ssl.
See /usr/share/doc/apache2.2-common/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
  service apache2 restart

Y el nuevo site también debe activarse:

root@server:~# a2ensite default-ssl
Enabling site default-ssl.
To activate the new configuration, you need to run:
  service apache2 reload

Finalmente, debe reiniciar el servicio:

root@server:~# service apache2 restart

Verificación

En un navegador de internet, inserte la dirección del servidor (https://192.168.1.100). Después aparecerá el aviso del certificado auto-firmado:

PHP

Objetivo

Expandir la funcionalidad del servidor de internet, activando el soporte php.

Instalación

root@server:~# apt-get install php libapache2-mod-php

Reiniciar el servidor apache2:

root@server:~# service apache2 restart

Verificación

Para verificar la instalación del soporte php, basta con crear una página de Internet que muestre las características de la instalación php. En este caso, se creará una página en /var/www/html/phpinfo.php:

/var/www/html/phpinfo.php
<?php
    phpinfo();
?>

Con el navegador de Internet y escribiendo la dirección http://192.168.1.100/phpinfo.php, se podrá acceder a la página:

De la misma manera, también puede ser verificado el acceso seguro a través del protocolo https utilizando la dirección https://192.168.1.100/phpinfo.php.

Una vez verificado el funcionamiento, deberá apagarse la página de pruebas, dado que las informaciones que ésta contiene pueden comprometer la seguridad del servidor:

root@server:~# rm /var/www/html/phpinfo.php

MySQL

Objetivo

Expandir la funcionalidad del servidor de Internet, activando el soportemySQL del php.

Instalación

root@server:~# apt-get install php-mysql

Reiniciar el servidor apache:

root@server:~# service apache2 restart

Verificación

Para verificar la instalación del soportemySQL del php, basta con crear una página de Internet que muestre las características de la instalación php. En este caso, se creará una página en /var/www/phpinfo.php:

/var/www/phpinfo.php

En seguida puede buscarse la página en un navegador de internet, escribiendo la dirección http://192.168.1.100/phpinfo.php. La información sobre el controlador mysql debe aparecer:

El controlador mysqli también debe aparecer disponible:

Una vez realizada la prueba de funcionamiento, se debe apagar esta página de prueba, porque la información que contiene puede comprometer la seguridad del servidor:

root@server:~# rm /var/www/phpinfo.php

Userdir

Objetivo

Ofrecerle a cada usuario la posibilidad de crear páginas de Internet personales.

Configuración

Una vez que la instalación del servidor http concluye, la configuración del soporte para crear páginas personales se consigue con la activación del módulo userdir del servidor apache2:

root@server:~# a2enmod userdir
Enabling module userdir.
Run '/etc/init.d/apache2 restart' to activate new configuration!

Activar soporte PHP

La ejecución de scripts php está desactivada en las páginas personales. Para activarla, se necesita comentar la línea php_admin_value engine Off en el archivo /etc/apache2/mods-available/php.conf:

/etc/apache2/mods-available/php.conf
# [...]

# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        # php_admin_value engine Off
    </Directory>
</IfModule>

# [...]
/etc/apache2/mods-enabled/userdir.conf

En la línea 7 agregar AllowOverride All

<IfModule mod_userdir.c>
        UserDir public_html
        UserDir disabled root

        <Directory /home/*/public_html>
                AllowOverride FileInfo AuthConfig Limit Indexes
                AllowOverride All
                Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
                Require method GET POST OPTIONS
        </Directory>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Luego, reiniciar el servidor apache2:

root@server:~# service apache2 restart

De esta manera, queda activado el soporte para páginas personales en el servidor http.

Utilización

Las páginas personales son accesibles a través de una dirección del género “http://servidor/~usuario”. Cuando el servidor recibe un pedido de este género, intenta encontrar el contenido en un directorio específico llamado public_html en la carpeta home del usuario. Por tanto, para que cada usuario pueda crear sus propias páginas, debe primero, crear un directorio llamado “public_html” en su carpeta home, donde ubicará sus contenidos.

root@server:~$ mkdir ~/public_html

Una vez creado el directorio, el usuario puede comenzar a crear contenidos.

Verificación

Utilizando un navegador, escriba una url que apunte hacia las páginas personales de un usuario:

MySQL: MariaDB

Objetivo

Instalar el servidor de base de datos MySQL MariaDB, con una configuración mínima.

Instalación

root@server:~# apt install mariadb-server mariadb-client

Configuración

Terminada la instalación, se debe ejecutar el comando mysql_secure_installation, que hace una serie de verificaciones e cambios en la configuración para garantizar la seguridad del servidor mysql.

root@server:~# mysql_secure_installation
root@server:~# mysql_secure_installation
 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
 
In order to log into MariaDB to secure it, we`ll need the current
password for the root user.  If you`ve just installed MariaDB, and
you haven`t set the root password yet, the password will be blank,
so you should just press enter here.
 
Enter current password for root (enter for none):
OK, successfully used password, moving on...
 
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
 
Set root password? [Y/n] n
 ... skipping.
 
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
 
Remove anonymous users? [Y/n]
 ... Success!
 
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
 
Disallow root login remotely? [Y/n]
 ... Success!
 
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
 
Remove test database and access to it? [Y/n]
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
 
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
 
Reload privilege tables now? [Y/n]
 ... Success!
 
Cleaning up...
 
All done!  If you`ve completed all of the above steps, your MariaDB
installation should now be secure.
 
Thanks for using MariaDB!
root@server:~#

Verificación

A partir de este momento, es posible acceder al monitor de MySQL:

root@server:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 664224
Server version: 10.1.23-MariaDB-9+deb9u1 Debian 9.0
 
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
 
MariaDB [(none)]> quit;
Bye
 
root@server:~#

ProFTPd

de ProFTPd (Puerto 21)

apt-get install proftpd

Archivo de configuración de ProFTPd

/etc/proftpd/proftpd.conf

Solo cambiar lo siguiente

UseIPv6                         off
DefaultRoot                     ~

Reiniciae el ProFTPd

/etc/init.d/proftpd restart

Probar la conexión con el FileZilla

MySQL – Debian 10 (mejoras)

Manejador de Base de Datos

Puerto 3306

actualizar sources.list  

/etc/apt/sources.list
deb http://deb.debian.org/debian buster main
deb-src http://deb.debian.org/debian buster main

deb http://deb.debian.org/debian-security/ buster/updates main
deb-src http://deb.debian.org/debian-security/ buster/updates main

deb http://deb.debian.org/debian buster-updates main
deb-src http://deb.debian.org/debian buster-updates main

Verificar lista de actualizaciones

apt-get update

Instalar actualizaciones

apt-get upgrade

Reiniciar el sistema

init 6

Instalar gnupg

apt-get install gnupg  

Ir al directorio /tmp

cd /tmp

Descargar el archivo Debian

wget https://dev.mysql.com/get/mysql-apt-config_0.8.13-1_all.deb

Instalar el paquete

dpkg -i mysql-apt-config*

Instalar el servidor de default de MySQL

apt-get install default-mysql-server

Configurar los accesos de los usuarios

mysql -u root
CREATE DATABASE phpmyadmin DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL ON phpmyadmin.* TO 'phpmyadmin'@'localhost' IDENTIFIED BY 'debian';
FLUSH PRIVILEGES;
EXIT;

Otorgar todos los permisos al usuario root
mysql -u root -p
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'debian' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

PHPMyAdmin

Interfaz Web para MySQL

Puerto 80, 443 y 3306

apt-get install php-imagick php-phpseclib php-php-gettext php7.3-common php7.3-mysql php7.3-gd php7.3-imap php7.3-json php7.3-curl php7.3-zip php7.3-xml php7.3-mbstring php7.3-bz2 php7.3-intl php7.3-gmp

Crear un directorio temporal /tmp y acceder a el.

mkdir tmp
cd /tmp

descargar el paquete de PHPMyAdmin

wget https://files.phpmyadmin.net/phpMyAdmin/4.9.0.1/phpMyAdmin-4.9.0.1-all-languages.zip

Instalar unzip

apt-get install unzip

Descomprimir el archivo descargado

unzip phpMyAdmin-4.9.0.1-all-languages.zip

Mover el archivo a /usr/share/phpmyadmin

mv phpMyAdmin-4.9.0.1-all-languages /usr/share/phpmyadmin

Cambiar los permisos

chown -R www-data:www-data /usr/share/phpmyadmin

Crear los accesos para PHPMyAdmin

cd /etc/apache2/conf-available/

Crear phpmyadmin.conf

nano /etc/apache2/conf-available/phpmyadmin.conf
# phpMyAdmin default Apache configuration

Alias /phpmyadmin /usr/share/phpmyadmin

<Directory /usr/share/phpmyadmin>
    Options SymLinksIfOwnerMatch
    DirectoryIndex index.php

    <IfModule mod_php5.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        </IfModule>
        <FilesMatch ".+\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>

        php_value include_path .
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
        php_admin_value mbstring.func_overload 0
    </IfModule>
    <IfModule mod_php.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        </IfModule>
        <FilesMatch ".+\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>

        php_value include_path .
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
        php_admin_value mbstring.func_overload 0
    </IfModule>

</Directory>

# Disallow web access to directories that don't need it
<Directory /usr/share/phpmyadmin/templates>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/setup/lib>
    Require all denied
</Directory>

activar el archivo creado

a2enconf phpmyadmin.conf

Crear un directorio

mkdir -p /var/lib/phpmyadmin/tmp

Cambiar los permisos del directorio

chown www-data:www-data /var/lib/phpmyadmin/tmp

Reiniciar el apache2

systemctl reload apache2