SSH Installation Manual for Implementing on cPanel

Prerequisites:

  • Ensure you have SSH access to your cPanel account.
  • Have your SSH credentials ready.

1. Access Your cPanel Account via SSH

  1. Open your terminal (Linux/Mac) or Command Prompt/PowerShell (Windows).
  2. Connect to your cPanel account using SSH:
   ssh username@yourdomain.com

Replace username with your cPanel username and yourdomain.com with your domain name.

2. Set Up Python Application

  1. Navigate to the Application Directory:
  • If you haven’t created a directory for your application, create one and navigate to it:
    bash mkdir -p ~/myapp cd ~/myapp
  1. Create a Virtual Environment:
  • Create a Python virtual environment:
    bash python3 -m venv venv
  1. Activate the Virtual Environment:
  • Activate the virtual environment:
    bash source venv/bin/activate
  1. Upload Your Project Files:
  • If you haven’t uploaded your project files, you can use scp (from your local machine) to copy them over:
    bash scp -r /path/to/your/project/files username@yourdomain.com:~/myapp
  • Alternatively, use an FTP client or the cPanel file manager to upload your files.
  1. Install Required Packages:
  • Ensure you have a requirements.txt file in your project directory and install the required packages:
    bash pip install -r requirements.txt

3. Configure the Application

  1. Environment Variables:
  • Create a .env file in your project directory with the necessary environment variables:
    bash touch .env nano .env
  • Add your environment variables in the .env file:
    GRAPH_API_TOKEN=your_graph_api_token WEBHOOK_VERIFY_TOKEN=your_webhook_verify_token
  1. Database Configuration:
  • Ensure your Flask app configuration is set to point to your MySQL database. For example, in your app.py:
    python app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://username:password@host/database'
  1. Initialize the Database:
  • Run the following commands to create the database tables:
    bash python from app import db, app with app.app_context(): db.create_all() exit()

4. Deploy and Run the Application

  1. Run the Flask Application:
  • For development purposes, you can run the Flask app directly:
    bash export FLASK_APP=app.py flask run
  • To keep the application running in the background, use a process manager like screen or tmux, or use a production server like gunicorn.
  1. Using Gunicorn:
  • Install Gunicorn:
    bash pip install gunicorn
  • Run the application with Gunicorn:
    bash gunicorn -w 4 -b 0.0.0.0:8000 app:app

5. Set Up Webhook URL in WhatsApp Business API

  1. Set the Webhook URL:
  • Set the webhook URL in the WhatsApp Business API settings to point to your webhook endpoint (e.g., https://yourdomain.com/webhook).
  1. Verify the Webhook:
  • Ensure the webhook verification token matches the one set in your .env file.

6. Optional: Set Up a Reverse Proxy with Apache or Nginx

  1. Apache Configuration:
  • Open your Apache configuration file and add a reverse proxy configuration: <VirtualHost *:80> ServerName yourdomain.com ProxyPass / http://127.0.0.1:8000/ ProxyPassReverse / http://127.0.0.1:8000/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
  • Restart Apache:
    bash sudo systemctl restart httpd
  1. Nginx Configuration:
  • Open your Nginx configuration file and add a reverse proxy configuration: server { listen 80; server_name yourdomain.com; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; }
  • Restart Nginx:
    bash sudo systemctl restart nginx

By following these steps, you should be able to set up and run your Positive Chat AI WhatsApp application on cPanel using SSH successfully.


Leave a Reply 0

Your email address will not be published. Required fields are marked *