Debian GNU/Linux Apache Webserver Hilfe
Inhaltsverzeichnis
- Debian GNU/Linux Apache Webserver Hilfe
- Linux, Apache, MariaDB, PHP (LAMP)
- Multiple PHP Versionen in Apache einrichten
- Multiple PHP Versionen in der Konsole einrichten
- Composer
- elasticsearch
Linux, Apache, MariaDB, PHP (LAMP)
Linux
apt update && apt upgrade -y && apt full-upgrade -y && apt autoremove -y
Apache
apt install apache2
apache2 -v
- Testen
127.0.0.1 im Browser aufrufen.ifconfig
mod_rewrite aktivieren
a2enmod rewrite
systemctl restart apache2
nano /etc/apache2/apache2.conf
- Folgendes ändern in den folgenden Zeilen
‹Directory /var/www/›
Options Indexes FollowSymLinks
AllowOverride None
(None
ändern zuAll
)Require all granted
DirectoryIndex index.php index.html
(Zeile hinzufügen damitindex.php
als erstes geladen wird)‹/Directory›
- Apache neu starten
systemctl restart apache2
- Apache Benutzer und Gruppe ändern
nano /etc/apache2/envvars
www-data Benutzer und Gruppe ändernsystemctl restart apache2
Timeout erhöhen, damit Scripts nicht vorzeitig abgebrochen werden
nano /etc/apache2/apache2.conf
(in anderen Konfigurationenhttpd.conf
)- Folgendes ändern in den folgenden Zeilen
Timeout 3600
(Standard 600)ProxyTimeout 600
(in anderen Konfigurationen kann diese Erhöhung helfen) systemctl restart apache2
MariaDB
apt install mariadb-server
(Oder das Paketdefault-mysql-server
, dieses führt je nach System mittels Abhängigkeit zu MariaDB)- MariaDB absichern
mysql_secure_installation
5xYes
- Testen
mysql -u root -p
SHOW databases;
EXIT;
- Passwort ändern
USE mysql;
UPDATE user SET password=[PASSWORT] WHERE user='root';
FLUSH PRIVILEGES;
EXIT;
MariaDB Upgrade
systemctl stop mysql
- Backups erstellen
cp -R /etc/mysql/ /etc/mysql-[VERSION]_[DATUM]
cp -R /var/lib/mysql/ /var/lib/mysql-[VERSION]_[DATUM]
- Script wird heruntergeladen und ausgeführt.
Erstellt '/etc/apt/sources.list.d/mariadb.list
', '/etc/apt/preferences.d/mariadb-enterprise.pref
' und 'GPG Keys'.curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
- System Update
apt update && apt upgrade -y && apt full-upgrade -y && apt autoremove -y
- Alte Installation und Dazugehöriges deinstallieren
apt remove mariadb-*
- Neues MariaDB installieren
apt-get install mariadb-server
- Datenbanken upgraden
mysql_upgrade
Systemvariablen
MariaDB in Debian
character_set_server utf8mb4
collation_server utf8mb4_general_ci
Standard MariaDB
character_set_server latin1
collation_server latin1_swedish_ci
Systemvariablen ändern
Für diese Sitzung
mysql
SHOW VARIABLES LIKE 'character%';
SET character_set_server = 'utf8mb4';
SHOW VARIABLES LIKE 'collation%';
SET collation_server = 'utf8mb4_general_ci';
exit
systemctl restart mariadb.service
systemctl restart apache2
Über Konfigurationsdatei (Neustart erforderlich)
- '
my.cnf
' Symlink umbenennen in 'my.cnf.backup
' - Da der Link '
/etc/mysql/my.cnf
' bis zum Schluss auf 'my.cnf.fallback
' zeigt, kopieren wir diese Datei und speichern die Kopie unter '/etc/mysql/my.cnf
' ab. - Am Ende der Datei '
/etc/mysql/my.cnf
' fügen wir folgendes ein.[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
- Neu starten. Testen. Testen. Testen.
PHP
- PHP Standard Version abfragen
apt show php
- PHP Standard Version installieren
apt install php
- Wichtige PHP Module installieren
apt install php7.0-[MODUL]
(Aufbau)apt install php7.0-mysql
(für MariaDB)apt install php7.0-gd
(für Grafiken)apt install php7.0-opcache
(für die Optimierung der Script Geschwindigkeit; inphp.ini
opcache.save_comments=1
einstellen)apt install php7.0-mcrypt
apt install php7.0-intl
apt install php7.0-soap
apt install php7.0-bcmath
- Installierte Module anzeigen
php -m
- PHP Einstellungen
nano /etc/php/7.0/apache2/php.ini
systemctl restart apache2
PHP Erweiterung aktivieren/deaktivieren
Diese Befehle erstellen oder entfernen den Symlink '20-xdebug.ini
' in '/etc/php/7.1/cli/conf.d
' und '/etc/php/7.1/fpm/conf.d
'.
- Aktivieren
php5enmod xdebug
(für PHP 5)phpenmod xdebug
(für Standard PHP Version) - Deaktivieren
php5dismod xdebug
(für PHP 5)phpdismod xdebug
(für Standard PHP Version) - Neu starten
systemctl restart php5.6-fpm.service
systemctl restart apache2
phpMyAdmin
apt install phpmyadmin
- Testen
localhost/phpmyadmin im Browser aufrufen. - Bei nicht auswählen (=Leertaste) der automatischen Konfiguration für apache2
nano /etc/apache2/apache2.conf
Include /etc/phpmyadmin/apache.conf
(Zeile ganz unten einfügen) - Neuen Benutzer für MariaDB anlegen
Du kannst dich aus Sicherheitsgründen mithilfe der normalen Passwort-Authentifizierung beim MariaDB-Server nicht mehr direkt als Root-Nutzer anmelden (z.B. bei phpMyAdmin).USE mysql;
CREATE USER '[BENUTZER]'@'localhost' IDENTIFIED BY '[PASSWORT]';
GRANT ALL PRIVILEGES ON *.* TO '[BENUTZER]'@'localhost' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON [DATENBANK].* TO '[BENUTZER]'@'localhost';
(Benutzer für eine bestimmte Datenbank anlegen)FLUSH PRIVILEGES;
EXIT;
Xdebug
apt install php-xdebug
- Folgendes der Datei '
/etc/php/7.0/mods-available/xdebug.ini
' hinzufügenxdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
timeout 300 seconds
systemctl restart apache2
ImageMagick
apt install imagemagick
apt install php7.0-imagick
systemctl restart apache2
E-Mail Versand
sendmail
Das Modul sendmail ist in der php.ini als Standard eingestellt und bei Debian bereits installiert, man muss nur Thunderbird starten.
- Thunderbird Konto erstellen um Nachrichten lesen zu können
Konten-Bezeichnung: [BENUTZERNAME]@debian.com
Ihr Name: [NAME]
E-Mail-Adresse: [E-MAIL]
Postausgangs-Server (SMTP): [SMTP-SERVER]
Server-EinstellungenServertyp: Unix Movemail
Server: localhost
Benutzername:[BENUTZERNAME]
- E-Mail Speicherort
/var/spool/mail/
- Warteschlange für ausgehende E-Mails
ACHTUNG: Ordner ist auf meinem System nicht vorhanden gewesen./var/spool/mqueue/
- Hier sind alle Konfigurationsdateien
/etc/mail/
z.B./etc/mail/access/
- Informationen
Nur*.db
Dateien werden von sendmail verwendet.
Nach Änderungen in Konfigurationsdateien, werden die jeweiligen*.db
Dateien von dem Makefile neu erzeugt.
ACHTUNG: Falls kein Makefile vorhanden ist:cat ./Filename | makemap hash Filename
ACHTUNG: Auch hier bestätigen Ausnahmen die Regel. Diealiases.db
wird als einzige mit dem Befehlnewaliases
generiert. Durchmakemap
entsteht zwar auch einealiases.db
, die aber sendmail funktionsunfähig machen kann.
sSMTP
Mit sSMTP E-Mails über die Konsole senden.
apt install ssmtp
nano /etc/ssmtp/ssmtp.conf
Folgendes ändern in den folgenden Zeilenroot=[E-MAIL]
mailhub=[SMTP-SERVER]:[SMTP-PORT]
hostname=
(Wird nicht benötigt. Wenn die Variable eingegeben wurde, wird der E-Mail Versand beschleunigt.)rewriteDomain=
AuthUser=[E-MAIL]
AuthPass=[PASSWORT]
UseSTARTTLS=yes
UseTLS=yes
FromLineOverride=yes
nano /etc/ssmtp/revaliases
Folgendes hinzufügen[BENUTZER]:[E-MAIL]:[SMTP-SERVER]:[SMTP-PORT]
root:mail@dreadyhead.com:smtp.dreadyhead.com:465
- Testen
echo "This is a test message" | mailx -s 'Test Message' [E-MAIL]
MIME Types hinzufügen
nano /etc/mime.types
Host erstellen
nano /etc/hosts
Apache VirtualHost anlegen und SSL einrichten
- Ordner erstellen
mkdir /etc/apache2/ssl
cd /etc/apache2/ssl
- Private Key erstellen
openssl genrsa -out sslcert.key 2048
- CSR Datei generieren aus Private Key
CSR Datei enthält Zertifikatsinformationenopenssl req -new -key sslcert.key -out sslcert.csr
- Aus CSR Datei Zertifikat generieren
openssl x509 -req -days 365 -in sslcert.csr -signkey sslcert.key -out sslcert.crt
- Apache2 SSL Modul aktivieren
a2enmod ssl
- Prüfen ob auf Port 443 gelauscht wird
cat /etc/apache2/ports.conf
Folgende Zeilen sollten aufscheinenListen 80
‹IfModule ssl_module›
Listen 443
‹/IfModule›
‹IfModule mod_gnutls.c›
Listen 443
‹/IfModule›
- Neue VirtualHost Konfiguration für den SSL Port erstellen
nano /etc/apache2/sites-available/[DOMAIN].conf
Folgende Zeilen in die neue VirtualHost Konfiguration einfügen‹VirtualHost *:80›
ServerAdmin info@[DOMAIN]
ServerName [DOMAIN]
ServerAlias www.[DOMAIN]
DocumentRoot /var/www/[PFAD]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
‹/VirtualHost›
‹VirtualHost *:443›
ServerAdmin info@[DOMAIN]
ServerName [DOMAIN]
ServerAlias www.[DOMAIN]
DocumentRoot /var/www/[PFAD]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/sslcert.crt
SSLCertificateKeyFile /etc/apache2/ssl/sslcert.key
‹/VirtualHost›
- Seite aktivieren
a2ensite [DOMAIN].conf
systemctl restart apache2
- Seite deaktivieren
a2dissite [DOMAIN].conf
systemctl restart apache2
Wichtige Log Files
- Apache und PHP Fehler
nano /var/log/apache2/error.log
- MariaDB Fehler
nano /var/log/mysql/error.log
Multiple PHP Versionen in Apache einrichten
PHP 5.6 deaktivieren, PHP 7.1 aktivieren
a2dismod php5.6
a2enmod php7.1
systemctl restart apache2
PHP, FPM und FastCGI
- Quellenliste hinzufügen
apt install ca-certificates apt-transport-https
wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list
- PHP und FPM installieren
apt update && apt upgrade -y && apt full-upgrade -y && apt autoremove -y
apt install php5.6 php5.6-fpm
apt install php7.4 php7.4-fpm
- Testen
systemctl status php5.6-fpm
systemctl status php7.4-fpm
- Apache FastCGI installieren
apt update && apt upgrade -y && apt full-upgrade -y && apt autoremove -y
apt install apache2 libapache2-mod-fcgid
- Apache Konfiguration
a2enmod actions fcgid alias proxy_fcgi
systemctl restart apache2
- VirtualHost Konfiguration anpassen
nano /etc/apache2/sites-available/[DOMAIN].conf
Folgende Zeilen in die VirtualHost Konfiguration einfügen‹VirtualHost *:[PORT]›
...
‹FilesMatch \.php$›
# Apache 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost/"
‹/FilesMatch›
‹/VirtualHost›
Apache neu startensystemctl restart apache2
- PHP Einstellungen anpassen
ACHTUNG: Installierte Module werden automatisch hinzugefügt beim Installieren.nano /etc/php/7.0/fpm/php.ini
- Benutzer www-data ändern falls nötig
nano /etc/php/7.0/fpm/pool.d/www.conf
Alle Benutzerwww-data
in deinen Benutzernamen (z.B.dreadyhead
) ändernsystemctl restart php7.0-fpm.service
- Wichtige Dateien
/var/log/php7.0-fpm.log
/etc/php/7.0/fpm/php-fpm.conf
Falls der Ordner apache2 in '/etc/php/7.3/' fehlt
- Folgendes installieren
apt install libapache2-mod-php7.3
PHP Version deaktivieren
systemctl disable php5.6-fpm.service
Multiple PHP Versionen in der Konsole einrichten
- Momentane Konfiguration kontrollieren
which php
Die Datei '/usr/bin/php
' verweist auf die '/etc/alternatives/php
'.
Die Datei '/etc/alternatives/php
' verweist auf die '/usr/bin/php7.3
'. - Alternatives ändern
update-alternatives --set php /usr/bin/php7.1
update-alternatives --set phar /usr/bin/phar7.1
update-alternatives --set phar.phar /usr/bin/phar.phar7.1
ACHTUNG: Die Befehle phpize und php-config sind im Paket php[PHP VERSION]-dev verfügbar. Dies ist nützlicher für das Kompilieren von PHP Modulen mit pecl.update-alternatives --set phpize /usr/bin/phpize7.1
update-alternatives --set php-config /usr/bin/php-config7.1
Composer
System Composer installieren (kann veraltet sein)
apt install composer
- Testen
composer
Wenn alles geklappt hat, werden alle Befehle angezeigt.
Composer von getcomposer.org installieren
- Quellenliste hinzufügen
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '8a6138e2a05a8c28539c9f0fb361159823655d7ad2deecb371b04a83966c61223adc522b0189079e3e9e277cd72b8897') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
- Global verfügbar machen
mv composer.phar /usr/bin/composer
Composer Befehle
- Version Upgraden
composer require [HERSTELLER]/[PAKET]
composer require friendsofphp/php-cs-fixer
Multiple PHP Versionen im Composer einrichten
Zustand
- Über den Composer
composer -vvv about
which php
/usr/bin/php/usr/bin/php -v
PHP 7.1.33php -v
PHP 7.2.24type -a php
php is aliased to '/usr/bin/php7.2'
php is /usr/bin/phpwhich composer
/usr/bin/composer
Lösung
- Datei
.bash_aliases
ändernalias php="/usr/bin/php7.2"
alias composer="/usr/bin/php7.2 /usr/bin/composer"
- Konsole neu starten
- Einstellungen prüfen
type -a composer
composer is aliased to '/usr/bin/php7.2 /usr/bin/composer'
composer is /usr/bin/composer - Der Composer verwendet jetzt die richtige PHP Version.
elasticsearch
- Quellenliste hinzufügen
Öffentlichen Signaturschlüssel herunterladen und installierenwget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
apt install apt-transport-https
Quellenliste speichern unter '/etc/apt/sources.list.d/elastic-7.x.list
'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
apt update && apt upgrade -y && apt full-upgrade -y && apt autoremove -y
apt install elasticsearch
- Einstellungen
nano /etc/elasticsearch/elasticsearch.yml
- Fehlerbericht
/var/log/elasticsearch/
SysVInit Autostart konfigurieren
- elasticsearch hinzufügen
update-rc.d elasticsearch defaults 95 10
- Service starten
service elasticsearch start
- Test
curl -X GET http://127.0.0.1:9200
SystemD Autostart konfigurieren
- SystemD Prozess neu laden
systemctl daemon-reload
- Service starten
systemctl start elasticsearch
systemctl enable elasticsearch
- Test
curl -X GET http://127.0.0.1:9200