Debug School

rakesh kumar
rakesh kumar

Posted on

How I Integrated Flask and Laravel on One Server Using Apache Reverse Proxy

Step1:Create one git hub repository

step2:give production path

    GCP_CREDENTIALS_JSON = "/opt/lampp/htdocs/motoshare.jp/motoshare-web/gcp-service.json"
Enter fullscreen mode Exit fullscreen mode

step3: git clone repository

git clone git@github.com:Motosharein/motoshare_flask.git
Enter fullscreen mode Exit fullscreen mode

Also install system dependencies in Linux server

sudo apt-get update
sudo apt-get install -y tesseract-ocr libtesseract-dev
Enter fullscreen mode Exit fullscreen mode

Check binary path:

which tesseract

Should return:

/usr/bin/tesseract
Enter fullscreen mode Exit fullscreen mode

Install python
specific version

sudo apt update
sudo apt install python3-pip -y
Enter fullscreen mode Exit fullscreen mode

Check python version

python3 --version
apt install python3.12-venv
Enter fullscreen mode Exit fullscreen mode

Use Python 3.12 safely (venv)

# Check 3.12 exists
which python3.12 || sudo apt install -y python3.12 python3.12-venv

# Create venv with 3.12
cd /opt/lampp/htdocs/motoshare_flask
python3.12 -m venv venv
source venv/bin/activate

# Verify you're inside the venv
which python
python --version

# Install deps inside the venv
pip install --upgrade pip
pip install -r requirements.txt


pip install gunicorn

# 4A) run with gunicorn (recommended)
gunicorn --bind 127.0.0.1:5000 "app:create_app()"
Enter fullscreen mode Exit fullscreen mode

sudo apt install -y libgl1 libglib2.0-0 libsm6 libxext6 libxrender1
Enter fullscreen mode Exit fullscreen mode

Notes

See what your module actually exposes

Run this in your project folder:

cd /opt/lampp/htdocs/motoshare.jp/motoshare_flask
source venv/bin/activate
python -c "import app; print('attrs:', [a for a in dir(app) if a in ('app','application','create_app')])"
Enter fullscreen mode Exit fullscreen mode

Virtual host setup
http_vhost

<VirtualHost *:80>
    ServerName motoshare.jp
    ServerAlias www.motoshare.jp
    DocumentRoot "/opt/lampp/htdocs/motoshare.jp/motoshare-web/public"

    # ...your existing Directory + Alias blocks...

    # --- Proxy /image/* to Flask on localhost:5000 ---
    ProxyRequests Off
    ProxyPreserveHost On

    # Put these BEFORE any other ProxyPass lines; keep trailing slashes
    ProxyPass        /image/ http://127.0.0.1:5000/image/
    ProxyPassReverse /image/ http://127.0.0.1:5000/image/

    # No X-Forwarded-Prefix or Location rewrites (prevents double prefix)
    ProxyTimeout 120
    Timeout 120
</VirtualHost>
Enter fullscreen mode Exit fullscreen mode

httpd-ssl.conf

<VirtualHost *:443>
    ServerName motoshare.jp
    ServerAlias www.motoshare.jp
    DocumentRoot "/opt/lampp/htdocs/motoshare.jp/motoshare-web/public"

    SSLEngine On
    SSLCertificateFile      "/opt/lampp/etc/certs/motoshare.jp/motoshare.jp.cer"
    SSLCertificateKeyFile   "/opt/lampp/etc/certs/motoshare.jp/motoshare.jp.key"
    SSLCACertificateFile    "/opt/lampp/etc/certs/motoshare.jp/fullchain.cer"

    # ...your existing Directory + Alias blocks...

    # --- Proxy /image/* to Flask on localhost:5000 ---
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass        /image/ http://127.0.0.1:5000/image/
    ProxyPassReverse /image/ http://127.0.0.1:5000/image/
    ProxyTimeout 120
    Timeout 120
</VirtualHost>
Enter fullscreen mode Exit fullscreen mode

finally check:

https://motoshare.jp/imageverify/
Enter fullscreen mode Exit fullscreen mode

Top comments (0)