0% found this document useful (0 votes)
11 views6 pages

RHEL Python Project Setup Guide

This guide provides a comprehensive setup for a Python project on a RHEL Linux server, covering sudoers error fixes, yum repository configuration, Python 3 installation, and project setup steps. It includes instructions for production deployment using systemd, firewall configuration, and troubleshooting common issues. Additionally, a verification checklist and support commands are provided to ensure the environment is correctly configured.

Uploaded by

tricka325
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

RHEL Python Project Setup Guide

This guide provides a comprehensive setup for a Python project on a RHEL Linux server, covering sudoers error fixes, yum repository configuration, Python 3 installation, and project setup steps. It includes instructions for production deployment using systemd, firewall configuration, and troubleshooting common issues. Additionally, a verification checklist and support commands are provided to ensure the environment is correctly configured.

Uploaded by

tricka325
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# **RHEL Linux Server Python Project Setup Guide**

## ** Table of Contents**
1. [Sudoers Error Fix](#sudoers-error-fix)
2. [Yum Repository Fix](#yum-repository-fix)
3. [Python 3 Installation](#python-3-installation)
4. [Project Setup Steps](#project-setup-steps)
5. [Production Deployment](#production-deployment)
6. [Troubleshooting](#troubleshooting)

---

## ** Sudoers Error Fix**

### **Error:** `oracle is not in the sudoers file`

**Solution:**

```bash
# 1. Root user se login
ssh root@your-server-ip

# 2. Oracle user ko wheel group mein add karen


usermod -aG wheel oracle

# 3. visudo se confirm karen


visudo
```

**visudo file mein add karen:**


```
oracle ALL=(ALL) ALL
```

**Test:**
```bash
su - oracle
sudo whoami # Output: root
```

---

## ** Yum Repository Fix**

### **Error:** `[Link] [Errno 14]`

** QUICK FIX:**
```bash
# Step 1: DVD repo disable
sudo yum-config-manager --disable rhel-dvd

# Step 2: EPEL install


sudo rpm -Uvh [Link]

# Step 3: CentOS mirrors configure


sudo tee /etc/[Link].d/[Link] > /dev/null <<EOF
[rhel-7-server-rpms]
name=RHEL 7 Server - Base
baseurl=[Link]
gpgcheck=0
enabled=1

[rhel-7-server-extras-rpms]
name=RHEL 7 Server - Extras
baseurl=[Link]
gpgcheck=0
enabled=1

[rhel-7-server-updates-rpms]
name=RHEL 7 Server - Updates
baseurl=[Link]
gpgcheck=0
enabled=1
EOF

# Step 4: Clean & Update


sudo yum clean all
sudo yum makecache
sudo yum update -y
```

---

## ** Python 3 Installation**

```bash
# Install Python 3 & Pip
sudo yum install python3 python3-pip -y

# Development tools (optional)


sudo yum groupinstall "Development Tools" -y

# Verify installation
python3 --version # Python 3.6.8
pip3 --version
```

---

## ** Complete Project Setup**

### **Step 1: Project Directory**


```bash
su - oracle
mkdir -p ~/python_project
cd ~/python_project
```

### **Step 2: Virtual Environment**


```bash
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
```

### **Step 3: Project Upload**


**From Local Machine:**
```bash
scp -r /path/to/project/* oracle@server-ip:~/python_project/
```

**Or Git:**
```bash
git clone [Link] .
```

### **Step 4: Dependencies Install**


```bash
# Requirements file se
pip install -r [Link]

# Common packages
pip install flask gunicorn requests pandas numpy django
```

### **Step 5: Test Run**


```bash
# Simple script test
echo 'print("Hello Python 3!")' > [Link]
python [Link]

# Web app test


python [Link] # Flask
python [Link] runserver [Link]:8000 # Django
```

---

## ** Production Deployment**

### **Systemd Service Setup**

**1. Service File Create:**


```bash
sudo nano /etc/systemd/system/[Link]
```

**Content:**
```ini
[Unit]
Description=My Python Project
After=[Link] [Link]

[Service]
Type=simple
User=oracle
Group=oinstall
WorkingDirectory=/home/oracle/python_project
Environment="PATH=/home/oracle/python_project/venv/bin"
ExecStart=/home/oracle/python_project/venv/bin/python /home/oracle/python_project/[Link]
Restart=always
RestartSec=10

[Install]
WantedBy=[Link]
```

**2. Service Start:**


```bash
sudo systemctl daemon-reload
sudo systemctl enable myproject
sudo systemctl start myproject
sudo systemctl status myproject
```

---

## ** Firewall & SELinux**

### **Firewall Configuration:**


```bash
# Port 8000 open karen (Django/Flask)
sudo firewall-cmd --add-port=8000/tcp --permanent
sudo firewall-cmd --reload

# Check status
sudo firewall-cmd --list-all
```

### **SELinux (Oracle Environment):**


```bash
# Network connect allow
sudo setsebool -P httpd_can_network_connect 1

# Temporary disable (testing)


sudo setenforce 0
```

---

## ** Troubleshooting**

### **Common Issues & Solutions:**

| **Issue** | **Solution** |
|-----------|--------------|
| `ModuleNotFoundError` | `pip install missing-package` |
| `Permission denied` | `chmod +x [Link]` |
| `Address already in use` | `sudo lsof -i :8000` then `kill PID` |
| `SELinux blocking` | `sudo setenforce 0` (temporary) |
| `No space left` | `df -h` check disk space |

### **Monitoring Commands:**


```bash
# Service status
sudo systemctl status myproject

# Logs
sudo journalctl -u myproject -f

# Process check
ps aux | grep python

# Resource usage
top -p $(pgrep -f "python")
```
---

## ** Verification Checklist**

- [ ] **Repository working:** `yum repolist`


- [ ] **Sudo access:** `sudo whoami`
- [ ] **Python 3:** `python3 --version`
- [ ] **Virtual Env:** `source venv/bin/activate`
- [ ] **Dependencies:** `pip list`
- [ ] **Service running:** `systemctl status myproject`
- [ ] **Port accessible:** `curl localhost:8000`

---

## ** Support Commands**

```bash
# System info
cat /etc/redhat-release
uname -a

# Disk usage
df -h
du -sh ~/*

# Network
netstat -tlnp | grep python

You might also like