- Yii2 Framework
-
Introduction & Setup
- Introduction to Yii2 Framework
- Installing Yii2 (Basic & Advanced Templates)
- Understanding Yii2 Directory Structure
- Yii2 Configuration Basics
- Routing & Pretty URLs in Yii2
-
Yii2 Core Concepts
- Yii2 Application Bootstrapping & Lifecycle
- Understanding Yii2 Request & Response Handling
- Working with Yii2 Components & Helpers
- Yii2 Widgets & Using Built-in Widgets
- Yii2 Helpers & Utility Classes
-
Models & Database Operations
- Yii2 Models, Active Record & Database Connections
- CRUD Operations in Yii2
- Yii2 Query Builder & DAO (Direct SQL Queries)
- Handling Relationships in Yii2 Active Record
- Yii2 Migrations & Seeding
-
Views, Layouts & Themes
- Yii2 Views & Layouts
- Yii2 Asset Bundles & Asset Management
- Integrating Bootstrap in Yii2
- Yii2 Theme Integration
- Yii2 Custom Widgets & Reusable Components
-
Forms, Validation & Data Presentation
- Yii2 Forms & Validation
- Using Yii2 GridView & ListView Widgets
- Yii2 Pagination & Sorting
- Yii2 File Uploads
-
Security & User Management
- User Authentication in Yii2
- Role-Based Access Control (RBAC) in Yii2
- Yii2 Security Features
-
Console Commands & Advanced Features
- Yii2 Console Commands
- Yii2 Events & Behaviors
- Yii2 RESTful API Development
- Consuming Third-Party APIs in Yii2
- Yii2 Background Jobs & Queue System
-
Performance Optimization & Caching
- Yii2 Caching Techniques
- Yii2 Performance Optimization
- Debugging & Logging in Yii2
-
Deployment & Best Practices
- Deploying Yii2 Applications
- Yii2 Best Practices & Large-Scale Application Structure
- Yii2 Multilingual & Localization Support
- Yii2 Module Development
- Integrating Yii2 with Frontend Frameworks (Angular/Vue/React)
-
Special Topics
- Dependency Injection (DI) in Yii2
Deploying Yii2 Applications
Deploying your Yii2 application on Hostinger using Git and SSH is a more secure and maintainable approach. Instead of directly uploading files into public_html
, we will:
- Use Git for version control
- Deploy the app to a separate directory (
projects/
) - Create a symbolic link to
public_html
for better structure
Use promo code DYNAMICDUNIYA
for 20% off on Hostinger hosting plans.
1. Setting Up Git for Deployment
First, upload your Yii2 project to GitHub, GitLab, or Bitbucket.
1.1 Add Your Project to GitHub
1. Initialize Git in your Yii2 project:
git init
2. Add a remote repository (GitHub, GitLab, or Bitbucket):
git remote add origin https://github.com/yourusername/your-repo.git
3. Push the Yii2 project:
git add .
git commit -m "Initial commit"
git push -u origin main
This ensures your project is version-controlled and ready for deployment.
2. Connect to Hostinger via SSH
2.1 Enable SSH Access on Hostinger
- Log in to Hostinger’s Control Panel
- Go to Advanced → SSH Access
- Copy the SSH credentials (Host, Username, Port)
2.2 Connect to Hostinger via SSH
On your local terminal, run:
ssh u820827383333@your-hostinger-ip -p 65002
Replace your-hostinger-ip
and 65002
with your Hostinger SSH details.
3. Deploy Yii2 to a Secure Directory
3.1 Create a Secure Directory for Yii2
Once logged into SSH, create a projects/
folder outside public_html
:
mkdir -p ~/projects/dynamicduniya
3.2 Clone Your Yii2 Project from GitHub
Navigate to the projects/
directory and clone your repository:
cd ~/projects
git clone https://github.com/yourusername/your-repo.git dynamicduniya
Your Yii2 project is now stored securely outside public_html
.
4. Set Up Symbolic Link to public_html
Since Hostinger serves content from public_html
, we create a symbolic link to point to our projects/dynamicduniya/web
folder.
4.1 Remove the Default public_html
Directory
rm -rf ~/domains/dynamicduniya/public_html
Deletes existing public_html
(make sure it's empty before running this).
4.2 Create a Symbolic Link to Yii2's web/
Folder
ln -s ~/projects/dynamicduniya/web ~/domains/dynamicduniya/public_html
Now, public_html
points to Yii2's web/
directory securely.
5. Configure Yii2 for Production
5.1 Set Up Database Connection
Edit config/db.php
with Hostinger’s MySQL details:
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=your_database',
'username' => 'your_user',
'password' => 'your_password',
'charset' => 'utf8',
];
5.2 Set Proper File Permissions
Ensure the runtime/
and web/assets/
folders are writable:
chmod -R 777 ~/projects/dynamicduniya/runtime ~/projects/dynamicduniya/web/assets
6. Automating Future Updates with Git
Each time you make updates, pull the latest changes from Git:
cd ~/projects/dynamicduniya
git pull origin main
This automatically updates your live app without re-uploading files manually.
7. Optimizing Yii2 for Performance on Hostinger
7.1 Enable Yii2 Caching
Edit config/web.php
to use file-based caching:
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
This reduces database load and speeds up page rendering.
7.2 Enable Gzip Compression
Edit .htaccess
in public_html
to enable Gzip compression:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css application/javascript
</IfModule>
7.3 Enable OPcache in PHP
- Go to Hostinger Panel →
PHP Configuration
- Enable OPcache to speed up PHP execution
8. Secure Your Yii2 Application
8.1 Secure the runtime/
and vendor/
Folders
Add these rules to .htaccess
in public_html
:
<FilesMatch "(runtime|vendor)">
Order Deny,Allow
Deny from all
</FilesMatch>
This blocks direct access to sensitive directories.
8.2 Force HTTPS (SSL)
Hostinger provides Free SSL. Add this to .htaccess
:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This redirects all traffic to HTTPS automatically.
9. Set Up Cron Jobs for Yii2 Tasks
If your Yii2 app requires scheduled tasks, configure cron jobs in Hostinger.
9.1 Add a Yii2 Console Command in CRON
- Go to Hostinger Panel →
Cron Jobs
- Add a new cron job:
php ~/projects/dynamicduniya/yii queue/run --verbose=1 --isolate=1
This runs Yii2 queue tasks automatically.
9.2 Example: Running a Yii2 Task Every Hour
0 * * * * php ~/projects/dynamicduniya/yii my-command
Modify my-command
as per your Yii2 CLI command.
Final Steps & Testing
- Flush Yii2 cache before testing:
php ~/projects/dynamicduniya/yii cache/flush-all
- Run database migrations (if needed):
php ~/projects/dynamicduniya/yii migrate
- Verify your app is running at
https://yourdomain.com
Conclusion
Deploying a Yii2 application on Hostinger using Git & SSH is the best approach for security, maintainability, and scalability. This method ensures:
- No direct file uploads to
public_html
- Easier updates with
git pull
- Improved security and performance
Use promo code DYNAMICDUNIYA
for 20% off on Hostinger plans.
Prepare for Interview
- Debugging in Python
- Multithreading and Multiprocessing in Python
- Context Managers in Python
- Decorators in Python
- Generators in Python
- Requests in Python
- Django
- Flask
- Matplotlib/Seaborn
- Pandas
- NumPy
- Modules and Packages in Python
- File Handling in Python
- Error Handling and Exceptions in Python
- Indexing and Performance Optimization in SQL
Random Blogs
- What is YII? and How to Install it?
- AI & Space Exploration – AI’s Role in Deep Space Missions and Planetary Research
- 5 Ways Use Jupyter Notebook Online Free of Cost
- Best Platform to Learn Digital Marketing in Free
- Career Guide: Natural Language Processing (NLP)
- Why to learn Digital Marketing?
- Quantum AI – The Future of AI Powered by Quantum Computing
- Avoiding the Beginner’s Trap: Key Python Fundamentals You Shouldn't Skip
- Mastering Python in 2025: A Complete Roadmap for Beginners
- How to Start Your Career as a DevOps Engineer
- 15 Amazing Keyword Research Tools You Should Explore
- Loan Default Prediction Project Using Machine Learning
- 10 Awesome Data Science Blogs To Check Out
- Convert RBG Image to Gray Scale Image Using CV2
- Datasets for Exploratory Data Analysis for Beginners
Datasets for Machine Learning
- Ozone Level Detection Dataset
- Bank Transaction Fraud Detection
- YouTube Trending Video Dataset (updated daily)
- Covid-19 Case Surveillance Public Use Dataset
- US Election 2020
- Forest Fires Dataset
- Mobile Robots Dataset
- Safety Helmet Detection
- All Space Missions from 1957
- OSIC Pulmonary Fibrosis Progression Dataset
- Wine Quality Dataset
- Google Audio Dataset
- Iris flower dataset
- Artificial Characters Dataset
- Bitcoin Heist Ransomware Address Dataset