India English
Kenya English
United Kingdom English
South Africa English
Nigeria English
United States English
United States Español
Indonesia English
Bangladesh English
Egypt العربية
Tanzania English
Ethiopia English
Uganda English
Congo - Kinshasa English
Ghana English
Côte d’Ivoire English
Zambia English
Cameroon English
Rwanda English
Germany Deutsch
France Français
Spain Català
Spain Español
Italy Italiano
Russia Русский
Japan English
Brazil Português
Brazil Português
Mexico Español
Philippines English
Pakistan English
Turkey Türkçe
Vietnam English
Thailand English
South Korea English
Australia English
China 中文
Somalia English
Canada English
Canada Français
Netherlands Nederlands

How to Host a PHP Website: A Beginner-Friendly Step-by-Step Guide

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)

  1. Log in to Truehost’s cPanel.
  2. Open File Manager → Navigate to public_html.
  3. 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:

  1. In cPanel, open MySQL Databases.
  2. Create a Database: Name it something like mywebsite_db., where mywebsite is the name of your domain.
  3. Add a User: Assign a username and password.
  4. 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).
  • .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

  1. Create index.php:
<?php  
echo "<h1>Welcome to My Nairobi Coffee Shop!</h1>";  
echo "<p>Fresh coffee beans delivered across Kenya.</p>";  
?>  
  1. Upload it to public_html.
  2. 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!

× Let's Talk