Instalar Linux, Nginx, MySQL, PHP en Debian y Ubuntu en sus últimas versiones estables y lts
Esta guía mostrará cómo montar un servidor Web usando las tecnologías de Software Libre mencionadas en el título, sin más preámbulos pongamos manos a la obra. Actualizar el sistema
user@server:~$ apt-get update && apt-get -y upgrade
Servidor Web NGINX
Instalación
sudo apt-get install nginx
Probar la instalación
w3m localhost
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
<=UpDn Viewing <Welcome to nginx!>
Para salir del navegador presionar la letra q
ps aux|grep nginx
root 8974 0.0 0.1 125008 1488 ? Ss 22:18 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 8975 0.0 0.2 125368 2368 ? S 22:18 0:00 nginx: worker process
www-data 8976 0.0 0.1 125368 2064 ? S 22:18 0:00 nginx: worker process
user 9765 0.0 0.0 11224 900 pts/0 S+ 22:39 0:00 grep --color=auto nginx
Manejador de Base de Datos Mysql
Instalar Mysql Server
user@server:~$ sudo apt-get install mysql-server
Se le pedirá una contraseña root, ingrese una aunque no se muestra, esta se usará para labores administrativas. Ejecutar script para dar seguridad a Mysql
sudo mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: Y solo si quiere activar el plugin, yo no lo recomiendo :-)
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : y
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? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL 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? (Press y|Y for Yes, any other key for No) : y
- 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? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
Procesador de Hypertexto PHP
Instalando PHP para trabajar con NGINX y Mysql
sudo apt-get install php-fpm php-mysql
Configurando PHP
sudo vim /etc/php/7.0/fpm/php.ini
Buscar y cambiar
;cgi.fix_pathinfo=1
Por
cgi.fix_pathinfo=0
Esto debido a que NGINX usa php-fpm (fastCGI process manager) y este cambio nos ayuda a hacer más seguro a PHP en este tipo de instalación.
Solo queda reiniciar PHP para que cargue la configuración.
sudo systemctl restart php7.0-fpm
Preparar NGINX para servir PHP
Editando el Virtualhost por defecto
sudo vim /etc/nginx/sites-available/default
Sustituir todo por esto
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name server_domain_or_IP;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Verificar si no hay errores en la sintaxis
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Recargar la configuración de NGINX
sudo systemctl reload nginx
Comprobar que está funcionando PHP
Crear el archivo info.php Este archivo es solo para pruebas, debe ser eliminado si estás configurando un ambiente de producción
sudo vim /var/www/html/info.php
Añade lo siguiente
<?php phpinfo(); ?>
Navega en http://localhost/info.php
w3m http://localhost/info.php
Aparecerá algo como esto
PHP logo
PHP Version 7.0.32-0ubuntu0.16.04.1
System Linux TragicVelvety-VM 2.6.32-042stab127.2 #1 SMP Thu Jan 4 16:41:44 MSK 2018 x86_64
Server API FPM/FastCGI
Virtual
Directory disabled
Support
Configuration
File /etc/php/7.0/fpm
(php.ini)
Path
Loaded
Configuration /etc/php/7.0/fpm/php.ini
File
Scan this dir
for /etc/php/7.0/fpm/conf.d
additional
.ini files
/etc/php/7.0/fpm/conf.d/10-mysqlnd.ini, /etc/php/7.0/fpm/conf.d/10-opcache.ini, /etc/php/7.0/fpm/conf.d/
10-pdo.ini, /etc/php/7.0/fpm/conf.d/20-calendar.ini, /etc/php/7.0/fpm/conf.d/20-ctype.ini, /etc/php/7.0/fpm
/conf.d/20-exif.ini, /etc/php/7.0/fpm/conf.d/20-fileinfo.ini, /etc/php/7.0/fpm/conf.d/20-ftp.ini, /etc/php/
Additional 7.0/fpm/conf.d/20-gettext.ini, /etc/php/7.0/fpm/conf.d/20-iconv.ini, /etc/php/7.0/fpm/conf.d/20-json.ini, /
.ini files etc/php/7.0/fpm/conf.d/20-mysqli.ini, /etc/php/7.0/fpm/conf.d/20-pdo_mysql.ini, /etc/php/7.0/fpm/conf.d/
parsed 20-phar.ini, /etc/php/7.0/fpm/conf.d/20-posix.ini, /etc/php/7.0/fpm/conf.d/20-readline.ini, /etc/php/7.0/
fpm/conf.d/20-shmop.ini, /etc/php/7.0/fpm/conf.d/20-sockets.ini, /etc/php/7.0/fpm/conf.d/20-sysvmsg.ini, /
etc/php/7.0/fpm/conf.d/20-sysvsem.ini, /etc/php/7.0/fpm/conf.d/20-sysvshm.ini, /etc/php/7.0/fpm/conf.d/
20-tokenizer.ini
<=UpDn Viewing <phpinfo()>
Sal presionando la tecla q.
O si prefieres pudes abrir un navegador tradicional y escribir la ip del servidor donde has alojado los servicios, http://127.0.0.1/info.php
Elimina el archivo info luego de la prueba.
sudo rm /var/www/html/info.php
Eso es todo.
Referencia https://www.digitalocean.com