Deploy Yii Framework Application to InfinityFree Using GitHub Actions and FTP

This guide walks you through deploying a Yii2 Framework app to InfinityFree using GitHub Actions and FTP. You'll prepare the project locally, configure GitHub secrets, and deploy automatically through push or manual trigger.
Prerequisites
Yii2 Basic Template (or Advanced) installed locally
PHP, Composer, Git
A GitHub account and repository
An InfinityFree account
FTP login credentials
Optional: a MySQL database if your app uses one
1. Install Yii2 Locally
Install the Yii2 basic app:
composer create-project yiisoft/yii2-app-basic yii2-app
cd yii2-app
php yii serve
Visit http://localhost:8080
to verify the app runs.
2. Configure the .env
File or db.php
If no database is needed:
You can comment or remove the
'db'
component inconfig/web.php
Or make
config/db.php
return an empty array:
return [];
If using a MySQL database:
In InfinityFree, go to MySQL Databases
Create a new database
Take note of:
Host (e.g.
sqlXXX.epizy.com
)DB name, username, password
Update
config/db.php
:
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=sqlXXX.epizy.com;dbname=epiz_12345678_dbname',
'username' => 'epiz_12345678',
'password' => 'your_db_password',
'charset' => 'utf8',
];
- Export your local DB and import it using phpMyAdmin > Import in InfinityFree.
3. Add a Root .htaccess
Redirect
Since Yii2 places its frontend in the web/
directory, add this .htaccess
in the project root (not inside web/
):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ web/$1 [L]
</IfModule>
4. Comment All .gitignore
Rules
By default, vendor/
, runtime/
, .env
, and other essential folders are ignored. Since InfinityFree doesn’t support Composer or CLI, you must upload everything.
Instructions:
Locate all
.gitignore
files in your projectComment out all rules by adding
#
before each line:
# /vendor
# /runtime
# /.env
# /web/assets
- Save the files
This ensures the entire Yii2 project is included in the deployment.
5. Add Your Domain on InfinityFree
InfinityFree allows 3 main accounts and unlimited custom domains. Here's how the structure works:
The default domain (created when opening the account) uses the main
/htdocs/
directoryAny addon domain gets its own directory named after the domain — with its own
htdocs/
inside
(e.g.,/
yourdomain.com/htdocs/
)
Example:
Default domain →
/htdocs/
Addon domain (
example.com
) →/
example.com/htdocs/
Recommendation:
Before setting up deployment, add the domain in InfinityFree to ensure the path exists.
6. Add GitHub Secrets (Before Pushing)
In your GitHub repo:
Go to Settings > Secrets and Variables > Actions
Add these two repository secrets:
FTP_USERNAME = epiz_12345678
FTP_PASSWORD = your_ftp_password
These will be used by the workflow for authentication.
7. Create the GitHub Actions Workflow
Before pushing the code, create a workflow file at:
mkdir -p .github/workflows
nano .github/workflows/infinityfree-deploy.yml
Paste this:
name: Deploy to InfinityFree
on:
push:
branches:
- main
workflow_dispatch:
jobs:
deploy:
name: Deploy Yii2 App
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Upload via FTP
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
with:
server: ftpupload.net
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
server-dir: /yourdomain.com/htdocs/ # Use /htdocs/ for default domain
timeout: 86400000
log-level: standard
⚠️ Replace
/
yourdomain.com/htdocs/
with/htdocs/
if deploying to the main/default domain.
8. Initialize Git and Commit the Project
Set up Git and prepare your first commit:
git init
git add .
git commit -m "Initial Yii2 project with InfinityFree deployment"
9. Push to GitHub
Add your remote and push:
git remote add origin https://github.com/your-username/your-repo.git
git branch -M main
git push -u origin main
If everything is set, the deployment will start automatically based on the push
event.
10. Trigger the Deployment (Optional)
If you configured workflow_dispatch
, you can also deploy manually:
Go to the Actions tab in your GitHub repo
Select the deployment workflow
Click Run workflow
This is useful for re-deploying without making a new commit.
Deployment Notes
Max file size is ~1MB — avoid uploading large libraries or assets
Make sure
vendor/
,runtime/
,web/assets/
, and configs are includedUpload may take a few minutes to hours depending on project size
If no database is used, make sure session is configured to use
file
:
'session' => [
'class' => 'yii\web\Session',
],
Summary
Step | Action |
Yii2 app installed locally | ✅ |
DB configuration or disabling done | ✅ |
Root .htaccess added | ✅ |
All .gitignore rules commented out | ✅ |
Domain added and structure verified | ✅ |
GitHub secrets set before push | ✅ |
Workflow created pre-push | ✅ |
Project committed and pushed | ✅ |
Deployment triggered (automatically or manually) | ✅ |
Subscribe to my newsletter
Read articles from Dan Ongudi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
