ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
feat(wordpress): per-site PHP version + limits panel (#24)
Juan Denis1080d31118c4
diff --git a/backend/app/api/wordpress.py b/backend/app/api/wordpress.pyindex 5998da7a..cdac194e 100644--- a/backend/app/api/wordpress.py+++ b/backend/app/api/wordpress.py@@ -346,6 +346,40 @@ def install_wordpress():return jsonify(result), 201 if result['success'] else 400+@wordpress_bp.route('/sites/<int:app_id>/php', methods=['GET'])+@jwt_required()+def get_php(app_id):+ """Live PHP version + ini limits for a Docker WP site (read-only)."""+ current_user_id = get_jwt_identity()+ user = User.query.get(current_user_id)+ app = _resolve_app(app_id)+ if not app:+ return jsonify({'error': 'Application not found'}), 404+ if user.role != 'admin' and app.user_id != current_user_id:+ return jsonify({'error': 'Access denied'}), 403+ info = WordPressService.get_php_info(app.root_path)+ info['available_versions'] = WordPressService.get_available_php_versions()+ return jsonify({'php': info}), 200+++@wordpress_bp.route('/sites/<int:app_id>/php', methods=['POST'])+@jwt_required()+@admin_required+def set_php(app_id):+ """Switch the Docker WP site's PHP version (swaps image tag + recreates)."""+ app = _resolve_app(app_id)+ data = request.get_json() or {}+ if not app:+ return jsonify({'error': 'Application not found'}), 404+ if app.app_type not in ('wordpress', 'docker'):+ return jsonify({'error': 'Application is not a WordPress site'}), 400+ version = data.get('version')+ if not version:+ return jsonify({'error': 'version is required'}), 400+ result = WordPressService.set_php_version(app.root_path, version)+ return jsonify(result), 200 if result.get('success') else 400++@wordpress_bp.route('/sites/<int:app_id>/info', methods=['GET'])@jwt_required()def get_wordpress_info(app_id):diff --git a/backend/app/services/wordpress_service.py b/backend/app/services/wordpress_service.pyindex 50ad1a9c..405a721d 100644--- a/backend/app/services/wordpress_service.py+++ b/backend/app/services/wordpress_service.py@@ -212,6 +212,71 @@ define('WP_AUTO_UPDATE_CORE', 'minor');except Exception as e:return {'success': False, 'error': str(e)}+ @classmethod+ def get_php_info(cls, path: str) -> Dict:+ """Read the LIVE PHP version + key ini limits from inside the running+ WordPress container via the Docker-aware wp_cli bridge. Read-only.+ """+ info = {}+ ver = cls.wp_cli(path, ['eval', 'echo phpversion();'])+ if ver.get('success'):+ info['php_version'] = (ver.get('output') or '').strip()+ php = (+ "foreach(['memory_limit','upload_max_filesize','post_max_size',"+ "'max_execution_time','max_input_time'] as $k){"+ "echo $k.'='.ini_get($k).\"\\n\";}"+ )+ limits = cls.wp_cli(path, ['eval', php])+ parsed = {}+ if limits.get('success'):+ for line in (limits.get('output') or '').splitlines():+ line = line.strip()+ if '=' in line:+ k, v = line.split('=', 1)+ parsed[k.strip()] = v.strip()+ info['limits'] = parsed+ info['source'] = 'container'+ return info++ @classmethod+ def get_available_php_versions(cls) -> List[str]:+ """Official wordpress image PHP variant tags we support switching to."""+ return ['8.1', '8.2', '8.3']++ @classmethod+ def set_php_version(cls, path: str, version: str) -> Dict:+ """Switch a Docker WP site to a different PHP by rewriting the compose+ image tag (wordpress:<wp>-php<version>-apache) and recreating the app+ container. Volumes/DB persist. NOT host php-fpm. Brief downtime.+ """+ from app.services.docker_service import DockerService+ if version not in cls.get_available_php_versions():+ return {'success': False, 'error': f'Unsupported PHP version: {version}'}+ compose_file = os.path.join(path, 'docker-compose.yml')+ if not os.path.exists(compose_file):+ return {'success': False, 'error': 'Not a Docker-stack site (no docker-compose.yml)'}+ try:+ with open(compose_file, 'r') as f:+ content = f.read()+ import re as _re+ m = _re.search(r'image:\s*wordpress:([^\s]+)', content)+ if not m:+ return {'success': False, 'error': 'wordpress image line not found in compose file'}+ current_tag = m.group(1)+ wp_core = current_tag.split('-')[0] if current_tag and current_tag[0].isdigit() else ''+ new_tag = (f'{wp_core}-php{version}-apache' if wp_core else f'php{version}-apache')+ new_content = content.replace(f'image: wordpress:{current_tag}', f'image: wordpress:{new_tag}')+ with open(compose_file, 'w') as f:+ f.write(new_content)+ up = DockerService.compose_up(path, detach=True, build=False)+ if not up.get('success'):+ return {'success': False, 'error': up.get('error') or 'compose up failed', 'image_tag': new_tag}+ cls._wait_for_wp_ready(path)+ live = cls.get_php_info(path).get('php_version')+ return {'success': True, 'message': f'Switched to PHP {version}', 'image_tag': new_tag, 'php_version': live}+ except Exception as e:+ return {'success': False, 'error': str(e)}+@classmethoddef is_multisite(cls, path: str) -> bool:"""Return True if the WordPress install at ``path`` is a multisite network.diff --git a/docs/WORDPRESS_ROADMAP.md b/docs/WORDPRESS_ROADMAP.mdindex 0c680ede..9ca5e294 100644--- a/docs/WORDPRESS_ROADMAP.md+++ b/docs/WORDPRESS_ROADMAP.md@@ -222,7 +222,7 @@ The headline value of a managed platform, and the most net-new — but it leans- **Reuse:** `wp_cli`, `wordpress.yaml` compose template, `flush_cache`.- **Done when:** Object cache is enabled and reports a hit ratio.-### #24 — Per-site PHP version & limits panel `[M]` 🟡+### #24 — Per-site PHP version & limits panel `[M]` 🟡 — ✅ Done (read panel: live version + limits via wp eval; version switch via image tag + recreate. Arbitrary limit-WRITE deferred — needs a conf.d ini + compose bind-mount for durability)- **Today:** The full PHP-FPM API (`getPHPVersions`/`setDefaultPHPVersion`/`installPHPVersion`/`createPHPPool`/`getPHPPools`/`restartPHPFPM` in `services/system.js`) has **zero** frontend consumers; `php_version` on `Application` is write-once with no update route, and pools are decoupled from the WP model.- **Do:** A per-site PHP panel (version + `memory_limit`/upload size/`max_execution_time`/workers) bound to the WP environment + an update-pool/change-version route.- **Reuse:** `php_service`, `system.js`.diff --git a/frontend/src/pages/WordPressDetail.jsx b/frontend/src/pages/WordPressDetail.jsxindex 3fdd60a5..55e72cab 100644--- a/frontend/src/pages/WordPressDetail.jsx+++ b/frontend/src/pages/WordPressDetail.jsx@@ -70,7 +70,7 @@ const DetailPageSkeleton = () => (</div>);-const VALID_TABS = ['overview', 'environments', 'database', 'plugins', 'themes', 'git', 'backups'];+const VALID_TABS = ['overview', 'environments', 'database', 'plugins', 'themes', 'php', 'git', 'backups'];const WordPressDetail = () => {const { id } = useParams();@@ -323,6 +323,12 @@ const WordPressDetail = () => {><Palette size={14} /> Themes</div>+ <div+ className={`app-detail-tab ${activeTab === 'php' ? 'active' : ''}`}+ onClick={() => setActiveTab('php')}+ >+ <Settings size={14} /> PHP+ </div><divclassName={`app-detail-tab ${activeTab === 'git' ? 'active' : ''}`}onClick={() => setActiveTab('git')}@@ -375,6 +381,7 @@ const WordPressDetail = () => {{activeTab === 'database' && <DatabaseTab siteId={site.id} site={site} />}{activeTab === 'plugins' && <PluginsTab siteId={site.id} />}{activeTab === 'themes' && <ThemesTab siteId={site.id} />}+ {activeTab === 'php' && <PhpTab siteId={site.id} />}{activeTab === 'git' && <GitTab siteId={site.id} site={site} onUpdate={loadSite} />}{activeTab === 'backups' && <BackupsTab siteId={site.id} />}</ErrorBoundary>@@ -383,6 +390,105 @@ const WordPressDetail = () => {);};+// PHP Tab — live PHP version + ini limits for the Docker (apache/mod_php) site.+// Version is the image tag; switching recreates the container (volumes persist).+const PhpTab = ({ siteId }) => {+ const toast = useToast();+ const [php, setPhp] = useState(null);+ const [loading, setLoading] = useState(true);+ const [switching, setSwitching] = useState(false);++ const load = React.useCallback(async () => {+ setLoading(true);+ try {+ const data = await wordpressApi.getPhpInfo(siteId);+ setPhp(data.php || data);+ } catch (err) {+ toast.error(err.message || 'Failed to load PHP info');+ } finally {+ setLoading(false);+ }+ }, [siteId, toast]);++ useEffect(() => { load(); }, [load]);++ async function handleSwitch(version) {+ if (!window.confirm(`Switch this site to PHP ${version}? This pulls the wordpress:php${version}-apache image and recreates the container (brief downtime; database and files are preserved).`)) return;+ setSwitching(true);+ toast.info(`Switching to PHP ${version}...`, { duration: 4000 });+ try {+ const res = await wordpressApi.setPhpVersion(siteId, version);+ if (res.success === false) { toast.error(res.error || 'Failed to switch PHP version'); return; }+ toast.success(res.message || `Switched to PHP ${version}`);+ await load();+ } catch (err) {+ toast.error(err.message || 'Failed to switch PHP version');+ } finally {+ setSwitching(false);+ }+ }++ if (loading) return <div className="tab-loading"><p className="hint">Loading PHP info...</p></div>;++ const limits = php?.limits || {};+ const current = php?.php_version || 'Unknown';+ const versions = php?.available_versions || [];++ return (+ <div className="app-overview-grid">+ <div className="app-overview-left">+ <div className="app-panel">+ <div className="app-panel-header">PHP</div>+ <div className="app-panel-body">+ <div className="app-info-grid">+ <div className="app-info-item">+ <span className="app-info-label">PHP Version</span>+ <span className="app-info-value">{current}</span>+ </div>+ <div className="app-info-item">+ <span className="app-info-label">Memory Limit</span>+ <span className="app-info-value">{limits.memory_limit || '-'}</span>+ </div>+ <div className="app-info-item">+ <span className="app-info-label">Upload Max Filesize</span>+ <span className="app-info-value">{limits.upload_max_filesize || '-'}</span>+ </div>+ <div className="app-info-item">+ <span className="app-info-label">Post Max Size</span>+ <span className="app-info-value">{limits.post_max_size || '-'}</span>+ </div>+ <div className="app-info-item">+ <span className="app-info-label">Max Execution Time</span>+ <span className="app-info-value">{limits.max_execution_time || '-'}</span>+ </div>+ <div className="app-info-item">+ <span className="app-info-label">Max Input Time</span>+ <span className="app-info-value">{limits.max_input_time || '-'}</span>+ </div>+ </div>+ </div>+ </div>++ {versions.length > 0 && (+ <div className="app-panel">+ <div className="app-panel-header">Change PHP Version</div>+ <div className="app-panel-body">+ <p className="hint">Switching rebuilds the container from the official wordpress php-apache image. The database and uploaded files are preserved.</p>+ <div className="app-detail-actions">+ {versions.map(v => (+ <Button key={v} variant="outline" size="sm" disabled={switching || current.startsWith(v)} onClick={() => handleSwitch(v)}>+ {current.startsWith(v) ? `PHP ${v} (current)` : `PHP ${v}`}+ </Button>+ ))}+ </div>+ </div>+ </div>+ )}+ </div>+ </div>+ );+};+// Overview Tabconst OverviewTab = ({ site, onUpdate }) => {const toast = useToast();diff --git a/frontend/src/services/wordpress.js b/frontend/src/services/wordpress.jsindex d74b64a1..e35ba7bc 100644--- a/frontend/src/services/wordpress.js+++ b/frontend/src/services/wordpress.js@@ -132,6 +132,15 @@ const wordpressApi = {// Live WP-CLI info (core version + update_available / latest_version)getWordPressInfo: (siteId) => api.request(`${BASE_PATH}/${siteId}/info`),+ // Live PHP version + ini limits for a Docker WP site (read-only).+ getPhpInfo: (siteId) => api.request(`${BASE_PATH}/${siteId}/php`),++ // Switch the site's PHP version (swaps the Docker image tag + recreates the container).+ setPhpVersion: (siteId, version) => api.request(`${BASE_PATH}/${siteId}/php`, {+ method: 'POST',+ body: { version }+ }),+// Update plugins. Pass an array of slugs to update specific ones, omit for all.updatePlugins: (siteId, plugins) => api.request(`${BASE_PATH}/${siteId}/plugins/update`, {method: 'POST',