Installation on AlmaLinux 9¶
This guide covers installing the RAG Chatbot on AlmaLinux 9. The same steps apply to RHEL 9 and Rocky Linux 9.
Prerequisites¶
Before starting, ensure you have:
- A fresh AlmaLinux 9 installation
- Root or sudo access
- At least 8 GB RAM and 50 GB storage
- Internet connectivity
Step 1: System Updates¶
Update the system and install essential tools:
Step 2: Install PHP 8.2¶
AlmaLinux 9 requires the Remi repository for PHP 8.2:
# Install Remi repository
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
# Enable PHP 8.2
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.2 -y
# Install PHP and required extensions
sudo dnf install -y php php-fpm php-cli php-pdo php-pgsql php-json \
php-mbstring php-curl php-xml php-zip php-gd php-opcache
Verify the installation:
Step 3: Install Apache Web Server¶
# Install Apache
sudo dnf install -y httpd mod_ssl
# Enable and start Apache
sudo systemctl enable httpd
sudo systemctl start httpd
# Configure firewall (firewalld)
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
# Or if using CSF (ConfigServer Firewall)
# Add ports to /etc/csf/csf.conf TCP_IN line: 80,443
sudo csf -r
Step 4: Configure PHP-FPM¶
Edit the PHP-FPM pool configuration:
Ensure these settings:
user = apache
group = apache
listen = /run/php-fpm/www.sock
listen.owner = apache
listen.group = apache
Start PHP-FPM:
Step 5: Deploy Application Files¶
Create the application directory and set permissions:
# Create web directory
sudo mkdir -p /var/www/chatbot
# Clone or copy your application files
# Option 1: From Git repository
cd /var/www
sudo git clone https://github.com/your-org/rag-chatbot.git chatbot
# Option 2: Extract from archive
sudo tar -xzf rag-chatbot.tar.gz -C /var/www/chatbot
# Set ownership
sudo chown -R apache:apache /var/www/chatbot
# Set permissions
sudo chmod -R 755 /var/www/chatbot
sudo chmod -R 775 /var/www/chatbot/logs
Step 6: Install Composer Dependencies¶
cd /var/www/chatbot
# Install Composer if not present
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
# Install dependencies
php composer.phar install --no-dev --optimize-autoloader
Step 7: Configure Apache Virtual Host¶
Create a virtual host configuration:
Add the following configuration:
<VirtualHost *:80>
ServerName your-domain.com
DocumentRoot /var/www/chatbot/public
<Directory /var/www/chatbot/public>
AllowOverride All
Require all granted
Options -Indexes +FollowSymLinks
# Enable URL rewriting
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</Directory>
# PHP-FPM configuration
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>
# Security headers
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "DENY"
Header always set X-XSS-Protection "1; mode=block"
# Logging
ErrorLog /var/log/httpd/chatbot-error.log
CustomLog /var/log/httpd/chatbot-access.log combined
</VirtualHost>
Enable required Apache modules:
# mod_rewrite should be enabled by default, verify with:
httpd -M | grep rewrite
# Restart Apache
sudo systemctl restart httpd
Step 8: Configure SELinux¶
If SELinux is enabled (recommended), configure it to allow the application:
# Allow Apache to connect to the network (for API calls)
sudo setsebool -P httpd_can_network_connect 1
# Allow Apache to connect to the database
sudo setsebool -P httpd_can_network_connect_db 1
# Set correct context for web files
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/chatbot/logs(/.*)?"
sudo restorecon -Rv /var/www/chatbot/logs
# If using Unix sockets for PHP-FPM
sudo setsebool -P httpd_execmem 1
Step 9: Configure Application¶
Copy the environment template and configure:
See the Configuration Guide for detailed settings.
Step 10: Create Log Directory¶
sudo mkdir -p /var/www/chatbot/logs
sudo chown apache:apache /var/www/chatbot/logs
sudo chmod 775 /var/www/chatbot/logs
Step 11: Test the Installation¶
Verify PHP is working:
Test the chat endpoint:
curl -X POST http://localhost/chat \
-H "Content-Type: application/json" \
-d '{"session_id":"test","message":"hello"}'
Next Steps¶
Troubleshooting¶
Permission Denied Errors¶
# Check SELinux denials
sudo ausearch -m avc -ts recent
# Temporarily disable SELinux for testing (not recommended for production)
sudo setenforce 0
PHP-FPM Not Starting¶
Apache Errors¶
# Check Apache configuration
sudo apachectl configtest
# View error logs
sudo tail -f /var/log/httpd/chatbot-error.log
Alternative: Nginx Installation¶
If you prefer Nginx over Apache:
# Install Nginx
sudo dnf install -y nginx
# Enable and start
sudo systemctl enable nginx
sudo systemctl start nginx
Create /etc/nginx/conf.d/chatbot.conf:
server {
listen 80;
server_name your-domain.com;
root /var/www/chatbot/public;
index index.php;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}
Update PHP-FPM for Nginx: