Configuring the Document Root
ChargePanda, like all modern Laravel applications, requires that its root directory for the web server is pointed specifically to the public/ folder. This ensures that sensitive files, configuration data, and application source code remain secure and inaccessible from the web.
Here are the instructions to set the Document Root correctly based on your hosting environment.
🏗️ cPanel
Option A: Addon Domain or Subdomain (Recommended)
If you are hosting ChargePanda on an Addon Domain or a Subdomain, you can easily define its Document Root in cPanel:
- Log into your cPanel.
- Navigate to Domains (or Addon Domains / Subdomains depending on your cPanel version).
- Find your domain in the list and click Manage or click the pencil icon next to the Document Root path.
- Update the path to include
/publicat the end (e.g.,public_html/chargepanda/publicoryourdomain.com/public). - Click Update or Save.
Option B: Using .htaccess as a fallback
If you are installing ChargePanda on a primary domain (e.g. directly inside public_html) and your host doesn't let you alter the primary Document Root:
- Upload the entire project into
public_html. - Create or edit an
.htaccessfile insidepublic_html(the root of the project, not insidepublic/). - Add the following rules to seamlessly redirect traffic to the
public/directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>(Note: While this approach works, Option A is more secure. Always prefer native Document Root changes if allowed by your host.)
🌍 Plesk
To change the Document Root in Plesk:
- Log into your Plesk Panel.
- Go to Websites & Domains.
- Locate the domain where you uploaded ChargePanda and click on Hosting & DNS > Hosting Settings.
- In the Document root field, append
/publicto the existing directory path (e.g.,httpdocs/public). - Click OK or Apply at the bottom of the page.
⚙️ Custom Apache Server
If you have root access to an Apache server (e.g. VPS or Dedicated Server), you need to update the VirtualHost configuration.
- Open your Apache configuration file (often located at
/etc/apache2/sites-available/your-domain.confor/etc/httpd/conf.d/your-domain.conf). - Set the
DocumentRootdirective to point to thepublicfolder. - Make sure the directory block allows overrides.
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/chargepanda/public
<Directory /var/www/chargepanda/public>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>- Restart Apache:
sudo systemctl restart apache2 # or httpd🚀 Custom Nginx Server
For a custom Nginx installation, locate your server block configuration (typically at /etc/nginx/sites-available/your-domain or /etc/nginx/conf.d/your-domain.conf).
- Update the
rootdirective to point to the/publicdirectory. - Ensure you have the
$uri/ /index.php?$query_stringfallback in your location block.
server {
listen 80;
server_name yourdomain.com;
root /var/www/chargepanda/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}- Restart Nginx:
sudo systemctl restart nginx