Cybersecurity

Secure PHP Website on Shared Hosting Checklist: 10 Basic Steps for cPanel Sites

Most hacks on budget hosting exploit simple slips: chatty error pages, 777 folders, exposed config files. This ten-step guide shows custom PHP site owners what to change in cPanel, php.ini, .htaccess and their code, current as of November 2026.

Ten-step secure PHP website checklist on a shield beside a shared hosting server rack with several website accounts
In this story11 sections
  1. What this secure PHP website on shared hosting checklist covers, and why shared servers draw attackers
  2. Step 1: Run a PHP branch that still receives security fixes
  3. Step 2: php.ini security settings for shared hosting, set from the MultiPHP INI Editor
  4. Step 3: Keep error messages in a log, not on the screen
  5. Step 4: Correct file permissions for PHP website cPanel accounts, and why 777 is never the fix
  6. Step 5: Protect config.php database password shared hosting accounts keep in plain text
  7. Step 6: .htaccess rules to secure PHP website folders and force HTTPS
  8. Step 7: Queries and forms that refuse to be tricked
  9. Step 8: A secure PHP file upload form on shared hosting, and passwords stored properly
  10. Steps 9 and 10: Host-side shields, tested backups and a monthly routine
  11. Frequently asked questions

Most break-ins on cheap hosting are not clever. A bot finds a forgotten backup file, a chatty error page or a form that trusts every character, and the site is gone by breakfast. This secure PHP website on shared hosting checklist is for owners and developers of hand-built PHP sites rather than WordPress installs. It walks through ten concrete steps in cPanel and in code, current as of November 2026.

ItemDetails
WhatTen hardening steps for a custom PHP site: PHP version, php.ini, errors, permissions, config files, .htaccess, queries, uploads, host tools and backups
Who it is forSmall business owners, freelance developers and freshers who run PHP sites on cPanel-based shared plans
Time neededAbout two to four hours for the first pass on a small site, then roughly 30 minutes a month
Official sourcePHP manual security chapter on php.net, plus cPanel documentation
What to do firstTake a full backup, note your PHP version and list everyone who has cPanel or FTP access

What this secure PHP website on shared hosting checklist covers, and why shared servers draw attackers

Shared hosting puts your site on one server with dozens or hundreds of other accounts. All of them share the same web server software, usually Apache or LiteSpeed, and the same PHP installation. It is like a flat in a housing society. The society runs the gate, but your own door is your business.

That split decides your job. The host patches the operating system and usually runs firewalls and scanners. You control your code, your php.ini overrides, your file permissions and your passwords.

Attackers rarely pick a small Indian site by name. Automated scanners sweep whole IP ranges for old PHP builds, exposed configuration files and leaky login forms. Hacked accounts become spam relays and phishing hosts.

The OWASP Top 10, the best-known ranking of web application risks, puts Broken Access Control first and Security Misconfiguration second in its 2025 edition, with Injection at fifth. Nearly every item in this guide maps to one of those three.

First, download a full backup, write down which PHP version each domain runs, and list every person and agency holding cPanel, FTP or database logins. You cannot lock doors you have not counted.

Step 1: Run a PHP branch that still receives security fixes

Run PHP 8.4 or 8.5 if your code allows it, and treat PHP 8.3 as the oldest acceptable fallback. According to the official supported-versions table on php.net, as of November 2026 the picture looks like this:

  • PHP 8.2: security fixes only, ending on 31 December 2026.
  • PHP 8.3: security patches only, through 31 December 2027.
  • PHP 8.4: full support ends 31 December 2026, security fixes run to 31 December 2028.
  • PHP 8.5: active support until 31 December 2027, security fixes until 31 December 2029.

Anything older, such as 7.4 or 8.0, gets no patches at all. On most cPanel servers you change the version per domain in MultiPHP Manager. Do it on a staging copy first, because old custom code often trips over removed functions and stricter type rules.

The language is only half the stack. Your project may use Composer dependencies such as a mailer, a PDF library or a payment SDK. If so, run composer outdated and composer audit on your own computer, then update, test and upload the refreshed vendor folder. A patched PHP engine running a three-year-old library is a new lock on a door with rotten hinges.

Step 2: php.ini security settings for shared hosting, set from the MultiPHP INI Editor

The php.ini security settings for shared hosting that matter most are a short list. Open cPanel, find MultiPHP INI Editor (usually in the Software group), and choose either Basic Mode, which shows switches, or Editor Mode, which shows raw text. Pick a single domain or your Home Directory. According to cPanel documentation, the tool writes your changes to php.ini, .user.ini and .htaccess, wherever each directive is supported.

  • expose_php = Off stops PHP from advertising its version in the X-Powered-By header. On some servers only the host can set it.
  • allow_url_include = Off blocks including code from remote URLs. It is off by default and deprecated since PHP 7.4. Make sure nothing has switched it on.
  • open_basedir limits which folders PHP may open. The manual calls it a safety net that is "in no way comprehensive".
  • disable_functions can block shell functions such as exec, but it is a system-level setting your host controls, and the manual warns it is not enough on shared servers.

Session cookie flags belong here too. The manual recommends session.cookie_httponly = On, session.cookie_secure = On and session.cookie_samesite = Lax (or Strict). It also calls session.use_strict_mode = On mandatory for secure sessions, even though it is off by default. Confirm each change with a temporary phpinfo() page, then delete that page immediately.

Settings card listing safe php.ini values such as expose_php Off and display_errors Off inside a cPanel-style editor
A handful of php.ini values does most of the work, though some can only be changed by the host.

Step 3: Keep error messages in a log, not on the screen

A live site should never print PHP errors to visitors. To disable display_errors PHP production servers need just one line, display_errors = Off, set through the MultiPHP INI Editor. The PHP manual is blunt: displaying errors is a development aid that "should never be used on production systems". The bundled php.ini-production file already sets it to Off, but check rather than assume.

Why does it matter so much? One warning on a contact page can reveal the server path, such as /home/username/public_html/includes/db.php, the database host and sometimes the query that failed. That is a free floor plan.

Pair the switch with log_errors = On, which the manual strongly advises for production. Then point error_log to a path outside public_html, such as a logs folder in your home directory. Read that file weekly.

The manual warns of one trap. Calling ini_set() to hide errors inside a script does not help when the script hits a fatal error, so set the value at the configuration level. Finally, give visitors a plain, friendly error page that says something went wrong and how to contact you.

Step 4: Correct file permissions for PHP website cPanel accounts, and why 777 is never the fix

In a standard setup, the correct file permissions for PHP website cPanel accounts are file permissions 644 and directory permissions 755. Leave public_html itself at its cPanel default of 0750. Those figures come from cPanel's own support article. It adds that on servers using suPHP, LSAPI or PHP-FPM with the right modules, folders can drop to 710 and files can go as tight as 400.

644 lets you read and write a file while others only read it. 755 lets others enter and list a folder but not add files to it. Configuration files holding passwords deserve tighter values such as 600 or 640 if your host's PHP handler still runs them. Test after each change.

Is 777 ever safe on shared hosting?

No. 777 means any user and any process on the server may write to that folder, which is precisely what a script dropped by an attacker wants. Several hosting knowledge bases also note that suPHP-style servers refuse to run scripts from world-writable locations and return a 500 error instead. If an upload folder "only works at 777", the real problem is ownership or the PHP handler, which your host can fix.

You can change permissions in cPanel File Manager by selecting a file and choosing Permissions, or over SFTP.

Folder tree of a shared hosting account with 750 for public_html, 755 for folders, 644 for files and a config folder outside
A safe layout keeps secrets above public_html and nothing at 777.

Step 5: Protect config.php database password shared hosting accounts keep in plain text

The simplest way to protect config.php database password shared hosting setups depend on is to move that file out of public_html altogether. Your cPanel home folder sits one level above the web root, and nothing there can be requested by a browser. Create a folder such as /home/username/config and put db.php inside it. From a file in public_html, load it with a path relative to the current script, for instance require __DIR__ . '/../config/db.php';

Servers get misconfigured. A handler change during a PHP upgrade, a stray .htaccess line or a leftover config.php.bak can expose the raw source, password and all.

Three more habits help:

  • Create a separate MySQL user for each site in cPanel's MySQL Databases screen and give it rights only on that site's database, not every privilege by default.
  • Keep credentials out of Git. A .env or config file pushed to a public repository is what automated secret scanners hunt for.
  • Change the database password whenever a developer or agency leaves, and update the config file in the same sitting.

Step 6: .htaccess rules to secure PHP website folders and force HTTPS

A few .htaccess rules to secure PHP website folders will close the most common leaks. They work on Apache and on LiteSpeed, which reads the same file. Apache's documentation notes that .htaccess only works where the host permits overrides, which nearly every cPanel host does.

  • Stop folder listings: Options -Indexes prevents a browser from seeing every file in a folder that has no index page.
  • Block sensitive files: wrap Require all denied inside a FilesMatch block that targets names ending in .env, .ini, .log, .sql, .bak or .old. On Apache 2.4 this is the correct syntax, while older guides show "Deny from all".
  • Force HTTPS: with Apache mod_rewrite, use RewriteEngine On, then RewriteCond %{HTTPS} off, then RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301].

Run the HTTPS redirect only after a valid certificate is in place. Most cPanel hosts issue free certificates through AutoSSL. Check the SSL/TLS Status page to confirm that every domain and the www version are covered.

Test after each rule. A 500 error straight after saving almost always means a typo, so restore the backup copy and try again line by line. Then request /config.php.bak or /.env in your browser and confirm you see a 403 or 404, not text.

Step 7: Queries and forms that refuse to be tricked

The cleanest way to prevent SQL injection PHP PDO prepared statements offer is keeping data and SQL in separate lanes. Instead of gluing a phone number into a query string, you send a template with a placeholder and pass the value separately, as in $stmt = $pdo->prepare('SELECT name FROM orders WHERE phone = ?'); $stmt->execute([$phone]);. The database never mistakes that value for a command. The mysqli extension offers the same idea through prepare() and bind_param().

The PHP manual adds a caveat worth printing out: prepared statements stop injection only if every part of the query built from outside input goes through them. Placeholders cannot stand in for column names, so if users can sort by a column, check their choice against a fixed allowlist.

Validate on the way in, escape on the way out

Validate every form field for type, length and format. filter_var() with FILTER_VALIDATE_EMAIL checks an email address. Casting an ID to an integer rejects anything else. When you print user-supplied text back on a page, pass it through htmlspecialchars() so a planted script tag shows as harmless text.

Forms that change data, such as a password reset or an order update, also need a CSRF token. This is a random value from random_bytes(), stored in the session and placed in a hidden field, then compared with hash_equals() on submit. Without it, another site can quietly submit the form on a logged-in user's behalf.

Step 8: A secure PHP file upload form on shared hosting, and passwords stored properly

A secure PHP file upload form on shared hosting assumes every incoming file is hostile until proven otherwise. The checks that matter:

  1. Allow only the extensions you need, such as jpg, png and pdf, and reject everything else.
  2. Check the real content type with the finfo functions instead of trusting the type the browser sends.
  3. Cap the size in code as well as in php.ini. PHP's default upload_max_filesize is 2M, and post_max_size must be larger.
  4. Rename each file to a random name and move it with move_uploaded_file().
  5. Store uploads outside public_html, or in a folder whose .htaccess denies any file ending in .php, .phtml or .phar.

Passwords for your admin panel or customer accounts follow one rule: never store them as plain text or with old MD5 or SHA1 hashes. Use password_hash() with PASSWORD_DEFAULT, which the manual says uses bcrypt, and check logins with password_verify(). From PHP 8.4 the default bcrypt cost rose from 10 to 12, making each guess slower for an attacker. Store the hash in a VARCHAR(255) column, as the manual suggests, so a future algorithm change still fits.

After logging a user in, call session_regenerate_id(true) so an old session ID cannot be reused.

Steps 9 and 10: Host-side shields, tested backups and a monthly routine

Your host can stop a large share of attacks before they reach your code, provided you switch the tools on. Use SFTP rather than plain FTP for uploads, since FTP sends your password across the network unencrypted. In cPanel's ModSecurity screen, keep the web application firewall enabled for every domain. cPanel's documentation recommends disabling it only while troubleshooting.

Many Indian cPanel hosts bundle Imunify360 for malware scanning and JetBackup for self-service restores. Run a malware scan after every major change, and test one restore to a subfolder so you know it works. A shop taking orders should back up its database daily and files at least weekly, with one copy kept off the server. If you ever find yourself typing "php website hacked on shared hosting what to do" into Google, a clean, dated backup is the first thing you will want.

The monthly routine, about 30 minutes:

  1. Check the PHP version and apply library updates.
  2. Read the error log and the cPanel access log for unknown IP addresses.
  3. Run a malware scan and search for new .php files in upload folders.
  4. Confirm a recent backup exists and restores.
  5. Remove old FTP accounts and former staff logins.
Monthly routine card for a PHP site on shared hosting with ticks for updates, backups, malware scan and login review
Thirty minutes a month keeps the checklist from going stale.

The PHP project keeps its own guidance in the security chapter of the PHP manual. Host menus and PHP defaults shift over time, so check the official documentation before relying on any value here. For customer data or a live breach, bring in a security expert. More guides sit in our cybersecurity news section.

Frequently asked questions

How can I tell if my PHP website has malware on shared hosting?

Run the malware scanner your host provides, such as Imunify360 or a cPanel virus scan, then look for recently modified .php files in upload and image folders. Google Search Console flags known problems under Security Issues. Unknown admin users or odd cron jobs are further clues.

What are the warning signs that a PHP site on shared hosting is compromised?

Common signs include redirects to betting or pharmacy pages, especially on mobile, and strange text in Google results. Watch too for a sudden spike in outgoing email, files you never uploaded, browser warnings or a suspended hosting account. Unexplained high CPU use is another clue.

What should I do right after my PHP site is hacked?

Change cPanel, FTP, database and email passwords from a clean device. Restore a backup taken before the infection, update PHP and libraries, and fix the hole that let the attacker in. Businesses covered by CERT-In rules must report listed incidents, website defacement among them, within six hours.

Can another account on the same shared server affect my website?

Another account can affect your site, though well-run hosts isolate accounts with per-user PHP handlers and file system restrictions. A shared IP can also land on a spam blacklist. Sloppy permissions like 777 on your side make cross-account attacks far easier, so tight permissions remain your first defence.

What PHP security mistakes do beginners make most often?

Beginners most often build SQL queries by joining strings, leave display_errors on and store passwords with MD5. Other common slips are 777 folders, database passwords in a public folder or Git repository, trusting the browser's file type and skipped updates. Each is easy to fix.

Is shared hosting secure enough for a small business website in India?

For a brochure site, a blog or a small catalogue, a well-run shared plan is usually adequate. Follow the steps in this guide and pick a host that offers a firewall, malware scanning and backups. Sites that store payment data, health records or large customer databases deserve isolated hosting and a professional security review.

Which Indian shared hosting plans include malware scanning and backups?

Offerings change often, so check each provider's current plan page rather than relying on a list. Look for named tools such as Imunify360 or a similar scanner, JetBackup or automatic daily backups with self-service restore, and ModSecurity. Ask how many days of backups are kept.

When should a small business move from shared hosting to a VPS for security?

Consider a VPS or managed cloud server when you handle sensitive personal or payment data, face repeated attacks or need server-level settings your host will not change. A VPS gives isolation and control but makes you responsible for patching the operating system, so budget for managed support if you lack in-house skills.

How can a Bhopal business check whether its developer followed PHP security practice?

Ask for a short written handover: PHP version, where the database config lives, how queries are written, how passwords are hashed, and where backups go. Test simple points yourself, such as error output. An independent review, like the one offered by our website development team, adds a second pair of eyes.

What belongs in a monthly PHP website security checklist?

A monthly checklist should confirm that PHP and Composer libraries are current and that a recent backup restores correctly. It should also cover the error and access logs, a malware scan and a review of cPanel and FTP accounts. Rotate the database password whenever someone with access leaves the business.

Built by Devmixa

Planning a website, web app or SEO upgrade?

Tell us what you need. We reply within one working day with a clear plan and price.

From the Devmixa Tech Desk
Yogesh Kumar Dewangan, editor of Devmixa Tech News
Founder, Devmixa · Editor, Tech News

Yogesh Kumar Dewangan

Yogesh leads the Devmixa Tech Desk from Bhopal. As a web developer and SEO strategist who builds and maintains business websites every day, he covers the tech news that lands on an Indian owner's desk: Google Search changes, website security, PHP and hosting updates, data protection rules, AI policy and startup schemes.

Every story is checked against the official source, such as a government notice, a regulator's advisory or a company's own documentation. Anything we could not confirm is clearly marked as reported. Spotted an error? Write to hello@devmixa.com and we will correct it.