Creazione ambiente LEMP su Debian Buster (Testing)
In questo articolo spiegherò come creare un ambiente LEMP su Debian Buster (Testing)
Nginx
apt-get install nginx php7.1-fpm php7.1 php7.1-cli php7.1-xmlphp7.1-zip
A questo punto, chiamando localhost da browser nging dovrebbe già rispondere con la pagina di default. Ora modifichiamo la conf di base. La seguente modifica sarà da riportare sia su /etc/php/7.1/cli/php.ini che /etc/php/7.1/fpm/php.ini:
cgi.fix_pathinfo=0
Ora modifichiamo il virtualhost di default modificando il file /etc/nginx/sites-available/default così da abilitare php:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
Poi dentro /var/www/html create il file index.php con il seguente contenuto:
<?php phpinfo();
Riavviare nginx e php-fpm:
service nginx restart service php7.1-fpm restart
Ora, chiamando l’indirizzo localhost da browser vedrete la pagina con le informazioni su php 7.1.
MySql / MariaDb
TODO
Xdebug
Adesso abilitiamo xdebug che purtroppo almeno a oggi, su debian Buster (Testing) non funziona da repository se non portandosi dietro dipendenze di php 7.0:
apt-get install php7.1-dev build-essential pkg-config make git g++ gcc git clone https://github.com/xdebug/xdebug.git cd xdebug phpize ./configure --enable-xdebug make mv modules/ /usr/local/xdebug touch /etc/php/7.1/mods-available/xdebug.ini
Inserire all’interno del file xdebug.ini:
zend_extension = /usr/local/xdebug/xdebug.so xdebug.remote_enable = On xdebug.remote_host = "localhost" xdebug.remote_port=9000 xdebug.remote_handler=dbgp xdebug.max_nesting_level=5000
Poi abilitare il modulo
ln -s /etc/php/7.1/mods-available/xdebug.ini /etc/php/7.1/cli/conf.d/20-xdebug.ini ln -s /etc/php/7.1/mods-available/xdebug.ini /etc/php/7.1/fpm/conf.d/20-xdebug.ini service nginx restart service php7.1-fpm restart
Memcached
Come per xdebug, installiamo memcached:
apt-get install libmemcached-dev libmsgpack-dev libmsgpackc2 git clone --depth 1 https://github.com/php-memcached-dev/php-memcached.git cd php-memcached phpize ./configure make mv modules/ /usr/local/memcached/ touch/etc/php/7.1/mods-available/memcached.ini
Inseriamo all’interno del file memcached.ini:
extension=/usr/local/memcached/memcached.so
Abilitiamo il modulo:
ln -s /etc/php/7.1/mods-available/memcached.ini /etc/php/7.1/cli/conf.d/20-memcached.ini ln -s /etc/php/7.1/mods-available/memcached.ini /etc/php/7.1/fpm/conf.d/20-memcached.ini service nginx restart service php7.1-fpm restart
A questo punto tramite la pagina di phpinfo potrete vedere i moduli installati, mentre da shell con il comando php –version vedrete:
PHP 7.1.8-1 (cli) (built: Aug 3 2017 18:35:23) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.8-1, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.6.0-dev, Copyright (c) 2002-2017, by Derick Rethans
PhpMyAdmin
Installare phpMyAdmin
cd /usr/share git clone https://github.com/phpmyadmin/phpmyadmin.git cd phpmyadmin composer install --no-dev mkdir tmp chmod -R 777 tmp ln -s /usr/share/phpmyadmin /var/www/html cp config.sample.inc.php config.inc.php
Usare la seguente config:
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* phpMyAdmin sample configuration, you can use it as base for
* manual configuration. For easier setup you can use setup/
*
* All directives are explained in documentation in the doc/ folder
* or at <https://docs.phpmyadmin.net/>.
*
* @package PhpMyAdmin
*/
/**
* This is needed for cookie based authentication to encrypt password in
* cookie. Needs to be 32 chars long.
*/
//$cfg['blowfish_secret'] = '3278y(&&///((dsnksdiusnd'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
$cfg['blowfish_secret'] = '';
/**
* Servers configuration
*/
$i = 0;
/**
* First server
*/
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
/**
* phpMyAdmin configuration storage settings.
*/
/* User used to manipulate with storage */
// $cfg['Servers'][$i]['controlhost'] = '';
// $cfg['Servers'][$i]['controlport'] = '';
// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';
/* Storage database and tables */
// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
// $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
// $cfg['Servers'][$i]['relation'] = 'pma__relation';
// $cfg['Servers'][$i]['table_info'] = 'pma__table_info';
// $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
// $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
// $cfg['Servers'][$i]['column_info'] = 'pma__column_info';
// $cfg['Servers'][$i]['history'] = 'pma__history';
// $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
// $cfg['Servers'][$i]['tracking'] = 'pma__tracking';
// $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
// $cfg['Servers'][$i]['recent'] = 'pma__recent';
// $cfg['Servers'][$i]['favorite'] = 'pma__favorite';
// $cfg['Servers'][$i]['users'] = 'pma__users';
// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
// $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
// $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
// $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
// $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
// $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
/**
* End of servers configuration
*/
/**
* Directories for saving/loading files from server
*/
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
/**
* Whether to display icons or text or both icons and text in table row
* action segment. Value can be either of 'icons', 'text' or 'both'.
* default = 'both'
*/
//$cfg['RowActionType'] = 'icons';
/**
* Defines whether a user should be displayed a "show all (records)"
* button in browse mode or not.
* default = false
*/
//$cfg['ShowAll'] = true;
/**
* Number of rows displayed when browsing a result set. If the result
* set contains more rows, "Previous" and "Next".
* Possible values: 25, 50, 100, 250, 500
* default = 25
*/
//$cfg['MaxRows'] = 50;
/**
* Disallow editing of binary fields
* valid values are:
* false allow editing
* 'blob' allow editing except for BLOB fields
* 'noblob' disallow editing except for BLOB fields
* 'all' disallow editing
* default = 'blob'
*/
//$cfg['ProtectBinary'] = false;
/**
* Default language to use, if not browser-defined or user-defined
* (you find all languages in the locale folder)
* uncomment the desired line:
* default = 'en'
*/
//$cfg['DefaultLang'] = 'en';
//$cfg['DefaultLang'] = 'de';
/**
* How many columns should be used for table display of a database?
* (a value larger than 1 results in some information being hidden)
* default = 1
*/
//$cfg['PropertiesNumColumns'] = 2;
/**
* Set to true if you want DB-based query history.If false, this utilizes
* JS-routines to display query history (lost by window close)
*
* This requires configuration storage enabled, see above.
* default = false
*/
//$cfg['QueryHistoryDB'] = true;
/**
* When using DB-based query history, how many entries should be kept?
* default = 25
*/
//$cfg['QueryHistoryMax'] = 100;
/**
* Whether or not to query the user before sending the error report to
* the phpMyAdmin team when a JavaScript error occurs
*
* Available options
* ('ask' | 'always' | 'never')
* default = 'ask'
*/
//$cfg['SendErrorReports'] = 'always';
/**
* You can find more configuration options in the documentation
* in the doc/ folder or at <https://docs.phpmyadmin.net/>.
*/
$cfg['TempDir'] = 'tmp';
Creare il virtualhost per nginx in /etc/nginx/sites-available/phpmyadmin
server {
listen 80;
listen [::]:80;
# Server name being used (exact name, wildcards or regular expression)
# server_name phpmyadmin.my;
root /usr/share/phpmyadmin;
# Logging
error_log /var/log/phpmyadmin.error_log;
access_log /var/log/phpmyadmin.access_log;
location / {
index index.php;
}
## Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 360d;
}
location ~ /\.ht {
deny all;
}
location ~ /(libraries|setup/frames|setup/libs) {
deny all;
return 404;
}
# Pass the PHP scripts to FastCGI server
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
Abilitare il vhost
ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/ service nginx restart service php7.1-fpm restart
Mailparse
Vediamo come installare l’estensione mailparse per php cercando come sopra di non portarci dietro dipendenze di php 7.0
pecl download mailparse tar -xvf mailparse-3.0.2.tgz cd mailparse-3.0.2/ phpize ./configure sed -i 's/#if\s!HAVE_MBSTRING/#ifndef MBFL_MBFILTER_H/' ./mailparse.c make mv modules/ /usr/local/mailparse/ touch /etc/php/7.1/mods-available/mailparse.ini
Il replace fatto con sed ci serve in quando c’è un bug noto che impedisce a mailparse di rilevare l’estensione mbstring (dalla quale dipende) anche se effettivamente installata.
Inseriamo all’interno del file mailparse.ini:
extension=/usr/local/mailparse/mailparse.so
Abilitiamo il modulo:
ln -s /etc/php/7.1/mods-available/mailparse.ini /etc/php/7.1/cli/conf.d/20-mailparse.ini ln -s /etc/php/7.1/mods-available/mailparse.ini /etc/php/7.1/fpm/conf.d/20-mailparse.ini service nginx restart service php7.1-fpm restart
olidev - 20 Febbraio 2018 at 20:17 -
Non penso sia necessario installare e configurare apc e mariadb per stack LEMP su Debian. Può essere fatto senza di esso, come qui: https://www.cloudways.com/blog/how-to-create-a-lemp-stack-on-debian-server/ I pacchetti principali da installare sono nginx, php, mysql e phpfpm.
admin - 26 Febbraio 2018 at 10:13 -
Mariadb lo metto al posto di MySql. Quindi non capisco perchè non dovrei metterlo 🙂