1οΈβ£ Installazione in locale (localhost)
2οΈβ£ Deploy su un server remoto (Ubuntu + Apache)
π₯οΈ 1οΈβ£ Installazione in LOCALE
π Struttura del progetto
/my-project
βββ /backend # Symfony 7.x + API Platform (backend)
β βββ /bin
β βββ /config
β βββ /migrations
β βββ /public
β βββ /src
β βββ /var
β βββ /vendor
β βββ .env
β βββ composer.json
βββ /frontend # Next.js + React Admin (frontend)
β βββ /components
β βββ /pages
β βββ /services
β βββ .env.local
β βββ package.json
βββ README.md
1. Creare il Backend (Symfony + API Platform)
1οΈβ£ Installare Symfony 7.x con API Platform
mkdir my-project
cd my-project
composer create-project symfony/skeleton backend
cd backend
composer require api
β
Ora il backend Γ¨ installato in /backend
.
2οΈβ£ Installare JWT per l’autenticazione
composer require security lexik/jwt-authentication-bundle
php bin/console lexik:jwt:generate-keypair
β Questo abilita l’autenticazione con JWT.
Modifica il file .env
:
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
JWT_PASSPHRASE=your-secret-passphrase
3οΈβ£ Configurare Symfony Security
π Modifica config/packages/security.yaml
security:
enable_authenticator_manager: true
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: "auto"
providers:
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
api_login:
pattern: ^/api/login
stateless: true
json_login:
check_path: /api/login
api:
pattern: ^/api/
stateless: true
jwt: ~
access_control:
- { path: ^/api/login, roles: PUBLIC_ACCESS }
- { path: ^/api/, roles: IS_AUTHENTICATED_FULLY }
β
Ora la rotta /api/login
genera un JWT per gli utenti autenticati.
4οΈβ£ Creare il Database
php bin/console doctrine:database:create
php bin/console make:migration
php bin/console doctrine:migrations:migrate
2. Creare il Frontend (Next.js + React Admin)
Spostati nella cartella principale:
cd ..
npx create-next-app@latest frontend
cd frontend
npm install react-admin @api-platform/admin
Modifica il file .env.local
:
NEXT_PUBLIC_API_URL=http://localhost:8000/api
Avvia il frontend:
npm run dev
β
Ora puoi accedere a http://localhost:3000
per vedere il frontend in azione!
π 2οΈβ£ Deploy su un SERVER REMOTO (Apache + PostgreSQL)
1. Preparare il Server
Accedi via SSH:
ssh user@your-server-ip
Aggiorna il sistema:
sudo apt update && sudo apt upgrade -y
Installa PHP, Composer, Node.js e PostgreSQL:
sudo apt install -y php8.3 php8.3-cli php8.3-mbstring php8.3-xml php8.3-bcmath php8.3-curl php8.3-zip php8.3-pgsql composer unzip curl git apache2 libapache2-mod-php nodejs npm
2. Clonare il progetto
Spostati nella cartella di deploy:
cd /var/www
git clone https://github.com/tuo-repo/my-project.git
cd my-project
3. Configurare il Backend (Symfony)
Spostati nella cartella /backend
:
cd backend
composer install --no-dev --optimize-autoloader
Configura il database in .env.local
:
APP_ENV=prod
DATABASE_URL="pgsql://user:password@localhost:5432/mydatabase"
Esegui le migrazioni:
php bin/console doctrine:migrations:migrate --no-interaction
Configura Apache per il backend:
sudo nano /etc/apache2/sites-available/api.conf
Aggiungi:
<VirtualHost *:80>
ServerName api.miosito.com
DocumentRoot /var/www/my-project/backend/public
<Directory /var/www/my-project/backend/public>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/api-error.log
CustomLog ${APACHE_LOG_DIR}/api-access.log combined
</VirtualHost>
Abilita il sito e riavvia Apache:
sudo a2ensite api.conf
sudo systemctl restart apache2
4. Configurare il Frontend (Next.js)
Spostati nella cartella /frontend
:
cd ../frontend
npm install
npm run build
Esegui Next.js con PM2 per mantenerlo attivo:
npm install -g pm2
pm2 start "npm run start" --name my-frontend
pm2 save
pm2 startup
β
Ora il frontend sarΓ visibile su http://miosito.com
!