# cd /var/www/html
# curl -s https://getcomposer.org/installer | php
# mv composer.phar /usr/local/bin/composer
# composer create-project --prefer-dist cakephp/app cms
#composer require twbs/bootstrap:4.3.0
Aruba debian początek instalacji
# apt-get update # apt-get upgrade Czytaj dalej Aruba debian początek instalacji
file-storage plugin
# composer require imagine/imagine
# composer require cakephp/migrations
# composer require burzum/file-storage:2.*
# cake migrations migrate -p Burzum/FileStorage
Update do php7.3
apt -y install lsb-release apt-transport-https ca-certificates ## zainstalowane
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php7.3.list
apt update
apt -y install php7.3
apt install php7.3-
php7.3-xml
php7.3-intl
php7.3-soap
php7.3-mysql
php7.3-mbstring
php7.3-gd
php7.3-openssl
php7.3-curl
php7.3-zip
php7.3-xmlrpc
php7.3-sqlite3
apt install libapache2-mod-php7.3
apt policy php7.3-cli
a2dismod php7.2
a2enmod php7.3
systemctl restart apache2
tinyMCE install
<!DOCTYPE html>
<html>
<head>
<script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
</head>
<body>
<textarea>Pole edytora</textarea>
</body>
</html>
cake pdf szablony
Templates/Layout/pdf/default.ctp
countdown plugin
<html>
<head>
<link rel="stylesheet" href="/css/flipclock.css">
</head>
<body>
<div class="your-clock"></div>
<script src="/js/libs/jquery.js"></script>
<script src="/js/flipclock/flipclock.min.js"></script>
</body>
</html>
var clock = $('.your-clock').FlipClock({
// ... your options here
});
updateAll – expression
Aktualizuje wiele rekordów
function publishAllUnpublished() { $this->updateAll( [ // fields 'published' => true, 'publish_date' => FrozenTime::now() ], [ // conditions 'published' => false ] ); }
.htaccess – mapowanie adresów
# Wymuszanie https:
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RichFilemanager
Instalacja cake
# php composer.phar create-project --prefer-dist cakephp/app media77
debug
echo "<pre>". print_r($query, 1) ."</pre>"; exit;
Zmiana bazy danych
class ArticlesTable extends Table { public static function defaultConnectionName() { return 'replica_db' ; } }
iptables.sh
#!/bin/sh IPTABLES=/sbin/iptables MODEPROBE=/sbin/modprobe INT_NET=10.1.0.0/16 INT_IN=eno2 INT_OUT=eno1
Virtual host + certyfikat + SSL
Utworzenie wirtualnego hosta /etc/apache2/sites-available/000-default.conf
<VirtualHost 81.137.4.24:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/example ServerName example.pl </VirtualHost>
LetsEncrypt – rozszerzenie domeny
Można dodać/usunąć domenę do certyfikatu już istniejącego np. o nazwie example.com:
# certbot certonly --cert-name example.com -d example.org,www.example.org
Nowy certyfikat będzie zawierał teraz dwie nazwy example.org oraz www.example.org
Instalacja php 7.2
# apt install ca-certificates apt-transport-https
LetsEncrypt – webroot
https://certbot.eff.org/docs/using.html
# certbot certonly --webroot -w /var/www/rewita/webroot -d tmp.rewita.pl -d crm.rewita.pl
Odnowienie certyfikatu
Odnowienie co 60 dni poprzez moduł wykorzystujący crona
Odnawia wszystkie certyfikaty, które zbliżają się do wygaśnięcia <= 30 dni do końca. Komendę można wydawać codziennie lub raz na tydzień, można dodać do crona.
# certbot renew
Tylko sprawdza działania –dry-run
# certbot renew --dry-run
Zmiana długości klucza z 2048 na 4096
# certbot renew --rsa-key-size 4096
Certyfikaty wildcard
DNS plugin musi być zainstalowany dla dostawcy dns
# certbot -a <dns-plugin> -i apache -d "*.example.com" -d example.com --server https://acme-v02.api.letsencrypt.org/directory
Ręczna konfiguracja certyfikatów
Ręczna konfiguracja certyfikatów:
# certbot certonly --authenticator standalone
Przed zainstalowaniem trzeba zatrzymać serwer ręcznie lub za pomocą skryptów:
# certbot certonly --authenticator standalone --pre-hook "apache2ctl -k stop" --post-hook "apache2ctl -k start"
Certbot
https://certbot.eff.org/lets-encrypt/debianstretch-apache
# apt-get install python-certbot-apache -t stretch-backports
# certbot --authenticator webroot --installer apache
cakePHP – logowanie autoryzacji
app.php w sekcji Log => [
'auth' => [ 'className' => 'Cake\Log\Engine\FileLog', 'path' => LOGS, 'file' => 'auth', 'url' => env('LOG_AUTH_URL', null), 'scopes' => ['auth'], ],
Przedłużenie sesji PHP
.htaccess – 14 dni czas sesji
php_value session.gc_maxlifetime 1209600
reachFileManager plugin
https://github.com/servocoder/RichFilemanager/wiki/Configuration-options
Instalacja projektu w katalogu filemanager
# composer create-project --prefer-dist servocoder/richfilemanager filemanager
# chown -R www-data.www-data filemanager/userdata
– ustawienie virtualnego serwera np. https://mymanager.pl
– dostęp poprzez podany URL
Zmiana userfiles na media
# nano filemanager/connectors/php/filemanager.php $local->setRoot('media', true, true);
Dostęp do pliku
https://mymanager.pl/media/dir/file.png
Konfiguracja static IP
# apt-get -y install ifupdown resolvconf # ifconfig
Obecna konfiguracja DHCP
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.6 netmask 255.255.255.0 broadcast 192.168.1.255
# nano /etc/network/interfaces
debian dns slave server
Master
nano /etc/bind/named.conf.local
debian bind 9
https://www.itzgeek.com/debian/configure-dns-server-on-debian-9.html
Instalacja bind9
# apt-get install -y bind9 bind9utils bind9-doc dnsutils
Globalna konfiguracja
# cd /etc/bind/ # less named.conf - nie zmieniany # nano named.conf.local - plik do edycji
cakephp PDF wkhtmltopdf
https://wkhtmltopdf.org
https://github.com/FriendsOfCake/CakePdf
Pobrać plik instalacyjny silnika ze strony i zainstalować
# dpkg -i wkhtmltox_0.12.5-1.stretch_amd64.deb
Podlinkować do domyślnej lokalizacji
# ln -s /usr/local/bin/wkhtmltopdf /usr/bin/wkhtmltopdf
cakePHP updateAll
use Cake\Database\Expression\QueryExpression; ... function incrementCounters() { $expression = new QueryExpression('view_count=view_count +1'); $this->updateAll([$expression], ['published' => true]); }
cakephp buildRules
// In src/Model/Table/OrdersTable.php public function buildRules(RulesChecker $rules) { $check = function($order) { if($order->shipping_mode !== 'free') { return true; } return $order->price >= 100; }; $rules->add($check, [ 'errorField' => 'shipping_mode' , 'message' => 'Nie ma bezpłatnej dostawy poniżej 100zł' ]); return $rules; } // W kontrolerze $order->price = 50; $order->shipping_mode = 'free' ; $ordersTable->save($order); // Returns false