Installation & Setup
Installation Overview
Section titled “Installation Overview”This comprehensive guide walks you through installing and configuring all components of the DealAI.lt platform from scratch. Follow each section carefully to ensure a successful deployment.
System Requirements
Section titled “System Requirements”Hardware Requirements
Section titled “Hardware Requirements”Minimum:
- CPU: 4 cores
- RAM: 8GB
- Storage: 100GB SSD
- Network: 100 Mbps
Recommended:
- CPU: 8+ cores
- RAM: 16GB+
- Storage: 250GB NVMe SSD
- Network: 1 Gbps
Software Requirements
Section titled “Software Requirements”- Ubuntu 20.04 LTS or Debian 11
- Root or sudo access
- Internet connectivity
Pre-Installation Checklist
Section titled “Pre-Installation Checklist”- Fresh Ubuntu/Debian installation
- Static IP address configured
- Domain name pointing to server (optional)
- SSH access configured
- Firewall rules planned
- Backup strategy defined
Step 1: System Preparation
Section titled “Step 1: System Preparation”Update System Packages
Section titled “Update System Packages”sudo apt update && sudo apt upgrade -ysudo apt install -y software-properties-common apt-transport-https ca-certificates curl wget git unzipConfigure Timezone
Section titled “Configure Timezone”sudo timedatectl set-timezone Europe/VilniusInstall Essential Build Tools
Section titled “Install Essential Build Tools”sudo apt install -y build-essential libssl-dev libffi-dev python3-devStep 2: Install PHP 8.x
Section titled “Step 2: Install PHP 8.x”Add PHP Repository
Section titled “Add PHP Repository”sudo add-apt-repository ppa:ondrej/php -ysudo apt updateInstall PHP and Extensions
Section titled “Install PHP and Extensions”sudo apt install -y php8.1 php8.1-fpm php8.1-cli php8.1-common \ php8.1-pgsql php8.1-curl php8.1-json php8.1-mbstring \ php8.1-xml php8.1-zip php8.1-gd php8.1-intl php8.1-bcmathConfigure PHP
Section titled “Configure PHP”sudo nano /etc/php/8.1/fpm/php.iniUpdate these settings:
memory_limit = 512Mupload_max_filesize = 64Mpost_max_size = 64Mmax_execution_time = 300max_input_time = 300date.timezone = Europe/VilniusRestart PHP-FPM:
sudo systemctl restart php8.1-fpmStep 3: Install PostgreSQL
Section titled “Step 3: Install PostgreSQL”Install PostgreSQL 13+
Section titled “Install PostgreSQL 13+”sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -sudo apt updatesudo apt install -y postgresql-13Configure PostgreSQL
Section titled “Configure PostgreSQL”Edit configuration:
sudo nano /etc/postgresql/13/main/postgresql.confRecommended settings:
max_connections = 200shared_buffers = 4GBeffective_cache_size = 12GBmaintenance_work_mem = 1GBwork_mem = 50MBConfigure access:
sudo nano /etc/postgresql/13/main/pg_hba.confAdd:
host dealai_products dealai_user 0.0.0.0/0 md5Restart PostgreSQL:
sudo systemctl restart postgresqlCreate Database and User
Section titled “Create Database and User”sudo -u postgres psqlCREATE DATABASE dealai_products;CREATE USER dealai_user WITH ENCRYPTED PASSWORD 'your_secure_password';GRANT ALL PRIVILEGES ON DATABASE dealai_products TO dealai_user;\qImport Database Schema
Section titled “Import Database Schema”psql -h localhost -U dealai_user -d dealai_products -f /path/to/schema.sqlStep 4: Install Elasticsearch
Section titled “Step 4: Install Elasticsearch”Import GPG Key
Section titled “Import GPG Key”wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -Add Repository
Section titled “Add Repository”echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.listInstall Elasticsearch
Section titled “Install Elasticsearch”sudo apt updatesudo apt install -y elasticsearchConfigure Elasticsearch
Section titled “Configure Elasticsearch”sudo nano /etc/elasticsearch/elasticsearch.ymlConfiguration:
cluster.name: dealai-clusternode.name: node-1network.host: 0.0.0.0http.port: 9200discovery.type: single-node
# Memory settingsbootstrap.memory_lock: true
# Indicesindex.number_of_shards: 3index.number_of_replicas: 1Set JVM heap:
sudo nano /etc/elasticsearch/jvm.options-Xms4g-Xmx4gStart Elasticsearch
Section titled “Start Elasticsearch”sudo systemctl enable elasticsearchsudo systemctl start elasticsearchVerify Installation
Section titled “Verify Installation”curl -X GET "localhost:9200/"Step 5: Install Web Server
Section titled “Step 5: Install Web Server”Option A: Apache
Section titled “Option A: Apache”sudo apt install -y apache2 libapache2-mod-php8.1
# Enable modulessudo a2enmod rewrite ssl headers proxy_fcgi setenvifsudo a2enconf php8.1-fpm
# Configure virtual hostsudo nano /etc/apache2/sites-available/dealai.conf<VirtualHost *:80> ServerName dealai.lt DocumentRoot /var/www/html
<Directory /var/www/html> AllowOverride All Require all granted </Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost>sudo a2ensite dealai.confsudo systemctl restart apache2Option B: Nginx
Section titled “Option B: Nginx”sudo apt install -y nginx
sudo nano /etc/nginx/sites-available/dealaiserver { listen 80; server_name dealai.lt; root /var/www/html; index index.php index.html;
location / { try_files $uri $uri/ /index.php?$args; }
location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; }
location ~ /\.ht { deny all; }}sudo ln -s /etc/nginx/sites-available/dealai /etc/nginx/sites-enabled/sudo nginx -tsudo systemctl restart nginxStep 6: Install WordPress
Section titled “Step 6: Install WordPress”Download WordPress
Section titled “Download WordPress”cd /tmpwget https://wordpress.org/latest.tar.gztar -xzf latest.tar.gzsudo mv wordpress/* /var/www/html/sudo chown -R www-data:www-data /var/www/htmlsudo chmod -R 755 /var/www/htmlConfigure WordPress
Section titled “Configure WordPress”cd /var/www/htmlcp wp-config-sample.php wp-config.phpnano wp-config.phpUpdate database settings:
define('DB_NAME', 'wordpress_db');define('DB_USER', 'wp_user');define('DB_PASSWORD', 'your_password');define('DB_HOST', 'localhost');
// For separate PostgreSQL (requires plugin)// Configure in theme functions.phpComplete WordPress Installation
Section titled “Complete WordPress Installation”Visit http://your-domain/wp-admin/install.php and follow the setup wizard.
Step 7: Install DealAI Theme
Section titled “Step 7: Install DealAI Theme”Clone Theme Repository
Section titled “Clone Theme Repository”cd /var/www/html/wp-content/themes/git clone <your-repository-url> productscd productsInstall Composer Dependencies
Section titled “Install Composer Dependencies”curl -sS https://getcomposer.org/installer | phpphp composer.phar installConfigure Environment
Section titled “Configure Environment”cp .env.example .envnano .env# PostgreSQL ConfigurationDB_HOST=162.55.174.116DB_PORT=5432DB_NAME=dealai_productsDB_USER=dealai_userDB_PASSWORD=your_password
# Elasticsearch ConfigurationELASTICSEARCH_HOST=91.99.113.45ELASTICSEARCH_PORT=9200ELASTICSEARCH_INDEX=products
# Scrapyd ConfigurationSCRAPYD_HOST=78.56.0.236SCRAPYD_PORT=6800SCRAPYD_PROJECT=dealai_scrapersSet Permissions
Section titled “Set Permissions”sudo chown -R www-data:www-data /var/www/html/wp-content/themes/productssudo chmod -R 755 /var/www/html/wp-content/themes/productsActivate Theme
Section titled “Activate Theme”- Log into WordPress admin
- Go to Appearance → Themes
- Activate “Products” theme
Step 8: Configure Elasticsearch Index
Section titled “Step 8: Configure Elasticsearch Index”Create Index with Lithuanian Analyzer
Section titled “Create Index with Lithuanian Analyzer”cd /var/www/html/wp-content/themes/products/scriptsphp -r "require 'elasticsearch-setup.php';"Or manually:
curl -X PUT "localhost:9200/products" -H 'Content-Type: application/json' -d'{ "settings": { "analysis": { "analyzer": { "lithuanian": { "type": "snowball", "language": "Lithuanian" } } }, "number_of_shards": 3, "number_of_replicas": 1 }, "mappings": { "properties": { "title": { "type": "text", "analyzer": "lithuanian" }, "brand": { "type": "keyword" }, "price": { "type": "float" }, "category": { "type": "keyword" } } }}'Step 9: Initial Data Sync
Section titled “Step 9: Initial Data Sync”Run Initial Sync
Section titled “Run Initial Sync”cd /var/www/html/wp-content/themes/products/scriptsphp elasticsearch-auto-sync.phpMonitor progress:
tail -f elasticsearch-auto-sync.logStep 10: Configure Cron Jobs
Section titled “Step 10: Configure Cron Jobs”Edit Crontab
Section titled “Edit Crontab”sudo crontab -eAdd Scheduled Tasks
Section titled “Add Scheduled Tasks”# Elasticsearch Auto-Sync (every 5 minutes)*/5 * * * * /usr/bin/php /var/www/html/wp-content/themes/products/scripts/elasticsearch-auto-sync.php >> /var/log/dealai/elasticsearch-sync.log 2>&1
# Product Crawler Manager (every 15 minutes)*/15 * * * * /usr/bin/php /var/www/html/wp-content/themes/products/scripts/product-crawler-manager.php >> /var/log/dealai/crawler-manager.log 2>&1
# Screenshot Manager (daily at 2 AM)0 2 * * * /usr/bin/php /var/www/html/wp-content/themes/products/scripts/product-screenshot-manager.php >> /var/log/dealai/screenshot-manager.log 2>&1
# Category Update (daily at 3 AM)0 3 * * * /usr/bin/php /var/www/html/wp-content/themes/products/scripts/cron/update-core-categories.php >> /var/log/dealai/category-update.log 2>&1Create Log Directory
Section titled “Create Log Directory”sudo mkdir -p /var/log/dealaisudo chown www-data:www-data /var/log/dealaiStep 11: Configure Firewall
Section titled “Step 11: Configure Firewall”UFW Configuration
Section titled “UFW Configuration”sudo ufw allow 22/tcp # SSHsudo ufw allow 80/tcp # HTTPsudo ufw allow 443/tcp # HTTPSsudo ufw enableFor Elasticsearch (if remote):
sudo ufw allow from <trusted-ip> to any port 9200Step 12: SSL/TLS Configuration (Optional)
Section titled “Step 12: SSL/TLS Configuration (Optional)”Using Let’s Encrypt
Section titled “Using Let’s Encrypt”sudo apt install -y certbot python3-certbot-apache # For Apache# ORsudo apt install -y certbot python3-certbot-nginx # For Nginx
sudo certbot --apache -d dealai.lt -d www.dealai.lt # Apache# ORsudo certbot --nginx -d dealai.lt -d www.dealai.lt # NginxAuto-renewal:
sudo certbot renew --dry-runStep 13: Verification
Section titled “Step 13: Verification”Test Database Connection
Section titled “Test Database Connection”cd /var/www/html/wp-content/themes/products/scriptsphp check-db.phpTest Elasticsearch
Section titled “Test Elasticsearch”curl -X GET "localhost:9200/_cat/indices?v"curl -X GET "localhost:9200/products/_count"Test WordPress
Section titled “Test WordPress”Visit: http://your-domain/
Test Search
Section titled “Test Search”Visit: http://your-domain/search/
Test Dashboards
Section titled “Test Dashboards”- Scrapyd Control:
http://your-domain/ - Elasticsearch Console:
http://your-domain/elasticsearch-console/ - Product Management:
http://your-domain/products/
Post-Installation
Section titled “Post-Installation”Security Hardening
Section titled “Security Hardening”# Remove default WordPress filesrm /var/www/html/readme.htmlrm /var/www/html/license.txt
# Restrict wp-config.phpchmod 600 /var/www/html/wp-config.phpPerformance Optimization
Section titled “Performance Optimization”Install caching plugin:
- W3 Total Cache
- WP Super Cache
- Redis Object Cache
Monitoring Setup
Section titled “Monitoring Setup”Install monitoring tools:
- New Relic / Datadog for APM
- Prometheus + Grafana for metrics
- ELK Stack for log aggregation
Troubleshooting
Section titled “Troubleshooting”See the Troubleshooting Guide for common issues and solutions.
Next Steps
Section titled “Next Steps”- Architecture Overview - Understand the system
- Core Systems - Explore components
- Development Setup - Configure development environment