Hosting a PHP website might seem intimidating, but it’s straightforward once you break it down.
So, if you’re building a personal blog, an e-commerce store, or a business site, this guide will walk you through every step.
Key Takeaways:
- Learn to choose the right hosting plan for your needs.
- Upload files, set up databases, and configure security.
- Discover tools and tips to keep your site running smoothly.
1) Plan and Prepare Your Website
Choose a Hosting Provider
Pick a hosting provider that supports PHP and MySQL/MariaDB databases.
For beginners, Truehost’s Shared Hosting (starting at KSh 199/month) is ideal. Advanced users might prefer our VPS Hosting for more control.
What to Look For:
- Server location: Truehost’s servers in Kenya ensure faster speeds for local visitors.
- Uptime: Truehost guarantees 99.9% uptime.
- Support: 24/7 help via live chat or email.
Register a Domain Name
Your domain (e.g., www.yourstore.co.ke)
is your website’s address. Truehost offers free domain registration with some plans.
Organize Your Files
Prepare your PHP files, images, and scripts. For example:
📁 my_website
├── index.php
├── contact.php
├── styles.css
└── images/
Plan Your Database (If Needed)
Dynamic sites (like blogs or stores) need a database. Use tools like MySQL Workbench to design tables for users, products, or posts.
2) Set Up Your Truehost Account
i) Sign Up: Visit Truehost.co.ke, choose a plan, and complete registration.
ii) Access cPanel: For Shared Hosting, use Truehost’s cPanel to manage files, databases, and email.
iii) VPS Dashboard: For VPS plans, use SSH to configure your server.
3) Upload Your Website Files
Option A: Using File Manager (Beginner-Friendly)
- Log in to Truehost’s cPanel.
- Open File Manager → Navigate to
public_html.
- Upload a ZIP file of your website folder and extract it.
Option B: Using FTP (Advanced)
i) Download FileZilla (free FTP tool).
ii) Enter Truehost’s FTP credentials:
- Host:
ftp.yourdomain.com
- Username/Password: Provided in your welcome email.
iii) Drag files from your computer to public_html.
4) Create and Configure Your Database
For Shared Hosting:
- In cPanel, open MySQL Databases.
- Create a Database: Name it something like
mywebsite_db
., where mywebsite is the name of your domain. - Add a User: Assign a username and password.
- Link User to Database: Grant “All Privileges.”
Update Your PHP Code:
<?php
$servername = "localhost";
$username = "mywebsite_user";
$password = "SecurePassword123!";
$dbname = "mywebsite_db";
// Connect to the database
$conn = new mysqli($servername, $username, $password, $dbname);
?>
For VPS Hosting:
i) Connect via SSH:
ssh root@your_server_ip
ii) Install MySQL:
sudo apt install mysql-server
sudo mysql_secure_installation
iii) Create a database and user:
CREATE DATABASE mywebsite_db;
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON mywebsite_db.* TO 'user'@'localhost';
5) Configure File Permissions and Security
- File Permissions:
- Folders:
755
(read/write/execute for owner, read/execute for others). - Files:
644
(read/write for owner, read-only for others).
- Folders:
- .htaccess: Protect sensitive files with this code:
# Block access to .env files
<Files .env>
Order allow,deny
Deny from all
</Files>
6) Test Your PHP Website
i) Visit your domain (e.g., https://yourstore.co.ke
).
ii) Check for errors:
- Blank page? Enable PHP error logging in php.ini:
display_errors = On
error_reporting = E_ALL
- Database issues? Verify credentials in your PHP code.
7) Go Live and Maintain Your Site
Fix DNS Propagation Delays
It can take up to 48 hours for your domain to work globally. Use Cloudflare to speed this up.
Schedule Backups
Truehost offers daily backups for Shared Hosting. For VPS, automate backups with:
# Backup database daily
0 3 * * * mysqldump -u user -p password mywebsite_db > /backups/db_backup.sql
Boost Security
- Update PHP versions in Truehost’s cPanel.
- Use strong passwords (e.g.,
Ecommerce@2024!
). - Install a free SSL certificate via Let’s Encrypt.
Example: Hosting a Simple PHP Page
- Create index.php:
<?php
echo "<h1>Welcome to My Nairobi Coffee Shop!</h1>";
echo "<p>Fresh coffee beans delivered across Kenya.</p>";
?>
- Upload it to
public_html.
- Visit your domain. You’ll see:
Welcome to My Nairobi Coffee Shop!
Fresh coffee beans delivered across Kenya.
Why Truehost Makes PHP Hosting Easier
- 1-Click PHP Install: Set up WordPress, Joomla, or custom PHP scripts in minutes.
- Africa-Optimized Servers: Faster loading times for Kenyan and East African users.
- Free Migration: Truehost’s team can move your existing site for free.
Ready to Launch?
Visit Truehost.co.ke to start with a Shared Hosting plan at KSh 199/month or scale up to VPS Hosting as your business grows.
Got questions? Truehost’s support team is just a click away!