lpic-305-306/ubuntu-lamp2/ubuntulamp.sh
2022-05-11 17:43:53 +02:00

113 lines
3.6 KiB
Bash

#!/bin/bash
#Aktualizacja systemu
sudo apt update && sudo apt upgrade -y
#Instalacja Apache i MC
sudo apt -y install apache2 mc
#Instalacja PHP
sudo apt -y install php php-{cli,mysql,json,opcache,xml,mbstring,gd,curl}
#Instalacja serwera baz danych
sudo apt -y install mariadb-server mariadb-client
#Konfiguracja serwera baz danych (wykonanie m.in. "mysql_secure_installation")
sudo mysql -e "UPDATE mysql.user SET Password = PASSWORD('Zaq12wsx') WHERE User = 'root'"
sudo mysql -e "DELETE FROM mysql.user WHERE User='';"
sudo mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
sudo mysql -e "DROP DATABASE IF EXISTS test;"
sudo mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';"
sudo mysql -e "use mysql; update user set plugin='' where User='root';"
sudo mysql -e "flush privileges;"
#Instalacja phpmyadmin
cd /tmp
wget -P Downloads https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
sudo mkdir -p /www/phpmyadmin
sudo tar xvf /tmp/Downloads/phpMyAdmin-latest-all-languages.tar.gz --strip-components=1 -C /www/phpmyadmin
sudo cp /www/phpmyadmin/config.sample.inc.php /www/phpmyadmin/config.inc.php
sudo chmod 660 /www/phpmyadmin/config.inc.php
sudo chown -R www-data:www-data /www/phpmyadmin
cat << 'EOF' > phpmyadmin.conf
# phpMyAdmin default Apache configuration
Alias /phpmyadmin /www/phpmyadmin
<Directory /www/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 /www/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/www/php/php-gettext/:/www/php/php-php-gettext/:/www/javascript/:/www/php/tcpdf/:/www/doc/phpmyadmin/:/www/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 /www/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/www/php/php-gettext/:/www/php/php-php-gettext/:/www/javascript/:/www/php/tcpdf/:/www/doc/phpmyadmin/:/www/php/phpseclib/
php_admin_value mbstring.func_overload 0
</IfModule>
</Directory>
# Authorize for setup
<Directory /www/phpmyadmin/setup>
<IfModule mod_authz_core.c>
<IfModule mod_authn_file.c>
AuthType Basic
AuthName "phpMyAdmin Setup"
AuthUserFile /etc/phpmyadmin/htpasswd.setup
</IfModule>
Require valid-user
</IfModule>
</Directory>
# Disallow web access to directories that don't need it
<Directory /www/phpmyadmin/templates>
Require all denied
</Directory>
<Directory /www/phpmyadmin/libraries>
Require all denied
</Directory>
<Directory /www/phpmyadmin/setup/lib>
Require all denied
</Directory>
EOF
sudo mv phpmyadmin.conf /etc/apache2/conf-available/phpmyadmin.conf
cp /etc/apache2/apache2.conf apache2.conf
cat << 'EOF' >> apache2.conf
<Directory /www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
EOF
sudo mv apache2.conf /etc/apache2/apache2.conf
sudo a2enconf phpmyadmin.conf
sudo systemctl restart apache2