Schlagwort-Archive: Symfony

Symfony und Doctrine: Entity- und Repository-Klassen nachträglich erstellen

Wer Symfony für ein bereits bestehendes Projekt nutzen will, steht vor dem Problem, dass es sehr mühsam (und erst recht fehleranfällig) sein kann, händisch die Entity- und Repository-Klassen nachträglich zu erstellen.

Um die Entity- und Repository-Klassen aus bestehenden Tabellen zu erzeugen, können Sie den folgenden Befehl verwenden:

php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity

Dieser Befehl wird die Entities aus den Tabellen Ihrer Datenbank im Annotation-Format im Verzeichnis app/src/Entity erzeugen.

Es kann durchaus der Fall sein, dass doctrine bestimmte Maßnahmen fordert. Ich musste zum Beispiel mehrmals nachträglich in meinen Tabellen (gerade in den unbedeutenden) Primärschlüssel erzeugen. Und der spezielle MySQL-Datentyp ENUM muss durch den allgemeineren Typ SET ersetzt werden. Aber diese Anpassungen sollten gefahrlos vorzunehmen sein.

Sie müssen dann die @ORM\Entity-Annotation in jeder Entity-Klasse ändern, um das entsprechende Repository anzugeben. Zum Beispiel:

@ORM\Entity (repositoryClass="App\Repository\UserRepository")

Sie können dann den folgenden Befehl verwenden, um die Entity-Klassen zu aktualisieren:

php bin/console make:entity --regenerate

Dann tauchen auch aufeinmal auch die getter- und setter-Methoden auf.

Beachten Sie, dass der Befehl doctrine:mapping:import von Doctrine im Jahr 2019 als veraltet markiert wurde und es keinen Ersatz dafür gibt. Stattdessen können Sie den Befehl make:entity vom Symfony Maker Bundle verwenden, um Ihnen bei der Erstellung des Codes Ihrer Doctrine-Entities zu helfen. Dieser Befehl erfordert jedoch eine manuelle Überwachung, da er keine Entities aus bestehenden Datenbanken erzeugt.

Stack: Ubuntu, Webmin, nginx, PostgreSQL, Samba, Symfony

Quellen:

https://ubuntu.com/

https://www.nginx.com/

https://symfony.com/

https://www.postgresql.org/

Ubuntu

Mehr Informationen:

https://ubuntu.com/tutorials/install-ubuntu-desktop#1-overview

SSH installieren

sudo apt install openssh-server
sudo systemctl status ssh
sudo systemctl enable ssh
sudo systemctl start ssh
sudo reboot

Einwahl über SSH-Client, wie bspw. Putty

Mehr Informationen:

https://www.ionos.de/digitalguide/server/konfiguration/ubuntu-ssh/

IPv6 ausschalten

sudo nano /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1"
GRUB_CMDLINE_LINUX="ipv6.disable=1"
sudo update-grub
sudo reboot

Mehr Informationen:

https://itsfoss.com/disable-ipv6-ubuntu-linux/

Shell pimpen

sudo apt-get install trash-cli # Papierkorb
sudo cp /etc/bash.bashrc /etc/bash.bashrc.bak
sudo nano /etc/bash.bashrc
alias +='pushd .'
alias ..='cd ..'
alias ...='cd ../..'
alias dir='ls -la  --color=auto'
alias d='ls -la  --color=auto'
alias gzcat='gunzip -c'
alias l='ls -alF'
alias la='ls -la'
alias ll='ls -la'
alias ls='/bin/ls $LS_OPTIONS'
alias ls-l='ls -l'
alias md='mkdir -p'
alias o='less'
alias rd='rmdir'
alias rehash='hash -r'
alias rm='rm -i'
alias unzip='tar xfvz'
alias which='type -p'
alias zip='tar cfvz'
alias sudo='sudo '
alias del='trash -rf'
sudo nano ~/.bashrc # ein kürzerer Prompt
GREEN="\[$(tput setaf 2)\]"
RESET="\[$(tput sgr0)\]"
PS1="${GREEN}$${RESET}"

Mehr Informationen:

https://1manfactory.com/pimp-my-shell-eine-vernuenftige-arbeitsumgebung-fuer-linux/

ein Zusatz-Admin zur Sicherheit

sudo adduser <NUTZER>
sudo adduser <NUTZER> sudo

Webmin

sudo apt update
curl -fsSL https://download.webmin.com/jcameron-key.asc | sudo gpg --dearmor -o /usr/share/keyrings/webmin.gpg
sudo nano /etc/apt/sources.list
deb [signed-by=/usr/share/keyrings/webmin.gpg] http://download.webmin.com/download/repository sarge contrib
sudo apt update
sudo apt install webmin
# Browser: http://<HOST>:10000

Mehr Informationen:

https://www.digitalocean.com/community/tutorials/how-to-install-webmin-on-ubuntu-22-04

nginx

sudo apt update
sudo apt install nginx
sudo systemctl status nginx
# Browser: http://<HOST>
sudo systemctl stop nginx # Stoppen
sudo systemctl start nginx # Starten
sudo systemctl restart nginx # Neustart
sudo systemctl reload nginx # sanfter Neustart nach Neu/Re-Konfiguration
sudo systemctl disable nginx # Autostart (Default) verhindern
sudo systemctl enable nginx # Autostart wieder ermöglichen

Rechte für /var/www/html

sudo chown -R www-data: /var/www/html/
sudo find /var/www/html -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +
sudo usermod -a -G www-data $USER
exit # Neueinwahl nötig

PHP für nginx

sudo apt-get install php8.1-fpm
sudo systemctl status php8.1-fpm # läuft der PHP-Service?
sudo nano /etc/nginx/sites-available/default

Folgendes muss angepasst werden:

  • index.php zur Indexliste hinzufügen (Zeile 8)
  • Entkommentieren der Zeilen 17, 18, 21, 24, 28, 29 und 30
server {
  # Example PHP Nginx FPM config file
  listen 80 default_server;
  listen [::]:80 default_server;
  root /var/www/html;

  # Add index.php to setup Nginx, PHP & PHP-FPM config
  index index.php index.html index.htm index.nginx-debian.html;

  server_name _;

  location / {
    try_files $uri $uri/ =404;
  }

  # pass PHP scripts on Nginx to FastCGI (PHP-FPM) server
  location ~ \.php$ {
    include snippets/fastcgi-php.conf;

    # Nginx php-fpm sock config:
    fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    # Nginx php-cgi config :
    # Nginx PHP fastcgi_pass 127.0.0.1:9000;
  }

  # deny access to Apache .htaccess on Nginx with PHP, 
  # if Apache and Nginx document roots concur
  location ~ /\.ht {
    deny all;
  }
} # End of PHP FPM Nginx config example
sudo nginx -t # um die Änderungen an der Konfiguration zu testen
sudo systemctl restart nginx # Neustart des Servers

Mehr Informationen:

https://1manfactory.com/nginx-ubuntu-php-fpm/

PHPINFO

sudo echo "<?php phpinfo(); ?>" >> /var/www/html/info.php
# Browser http://<HOST>/info.php

nginx-Modul für Webmin

Webmin -> Webmin Configuration -> Webmin Modules
Install from „From HTTP or FTP URL“
Quelle: https://github.com/Sumarious/nginx-webmin/raw/master/nginx.wbm.gz

Mehr Informationen:

https://github.com/Sumarious/nginx-webmin

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04

Composer

sudo apt update
sudo apt install php-cli unzip # benötigt
cd ~
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
HASH=`curl -sS https://composer.github.io/installer.sig`
echo $HASH
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer

Mehr Informationen:

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-22-04

PostgreSQL

sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql.service
sudo systemctl status postgresql

Mehr Informationen:

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-20-04

PostgreSQL in Webmin

Webmin -> Refresh Modules
Servers -> PostgreSQL Database Server

HeidiSQL für PostgreSQL

WICHTIG: IP6 muss deaktiviert sein (siehe oben)

sudo nano /etc/postgresql/14/main/postgresql.conf
listen_addresses = '*'
sudo nano /etc/postgresql/14/main/pg_hba.conf
# IPv4 local connections:
#host    all      all             127.0.0.1/32		scram-sha-256
host     all       all            0.0.0.0/0		scram-sha-256
sudo service postgresql restart

Da IP6 jetzt deaktiviert ist, muss noch eine Einstellung für nginx dringend angepasst werden:

sudo nano /etc/nginx/sites-available/default
#listen [::]:80 default_server; dieser Eintrag muss deaktiviert sein, wenn kein IP6
sudo systemctl restart nginx # nginx neu starten

neuer User für PostgreSQL

Webmin -> PostgreSQL -> PostgreSQL Users -> Create a new user

Samba

sudo apt-get install samba
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf_backup # Kopie schadet nie
systemctl status smbd # Status prüfen
sudo nano /etc/samba/smb.conf
[www]
  comment = Web Root Dir
  path = /var/www/html
  valid users = @www-data
  browseable = yes
  public = no
  writable = yes
  printable = no
  create mode = 0644
  directory mode = 0775
  force group = www-data
  force user = www-data
sudo usermod -aG www-data $USER
sudo smbpasswd -a $USER # für jeden Nutzer notwendig, der Samba nutzen soll
sudo service smbd restart
systemctl status smbd
sudo smbstatus --shares # zeigt aktive Verbindungen

In der Windows-Kommandozeile eine Verbindung herstellen:

net use X: \\<HOST>\www /user:<USER> <PASSWORD>

Symfony

Symfony-cli Binary installieren

sudo apt-get install php-xml # wird noch benötigt
cd ~
curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.deb.sh' | sudo -E bash
sudo apt install symfony-cli

ein neues Symfony-Projekt anlegen

sudo chown -R www-data:www-data /var/www/html/
sudo find /var/www/html/ -type d -exec chmod 775 {} \;
sudo find /var/www/html/ -type f -exec chmod 664 {} \;
sudo find /var/www/html/ -type d -exec chmod g+s {} \;
cd /var/www/html/
symfony new --webapp testprojekt
cd testprojekt/
composer require --dev symfony/profiler-pack
symfony server:start -d # Symfony Server starten

Aufruf über Symfony Server

Aufruf über nginx