Skip to content

Commit 674ba8e

Browse files
docs: Add comprehensive installation guide with system requirements, methods, and post-installation setup. (#97)
1 parent c83f49e commit 674ba8e

File tree

2 files changed

+266
-1
lines changed

2 files changed

+266
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ The Yii2 Web Application Basic template provides a complete foundation for build
5757
3. **Security features** including CSRF protection and input validation.
5858
4. **Development tools** for debugging, logging, and testing.
5959

60-
#### Why use this template?
60+
#### Why use this template
6161

6262
- **Rapid development**: Start building features immediately without setup overhead.
6363
- **Best practices**: Follow Yii2 conventions and modern web development standards.

docs/installation.md

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
# Installation guide
2+
3+
## System requirements
4+
5+
- [`PHP`](https://www.php.net/downloads) 8.1 or higher.
6+
- [`Composer`](https://getcomposer.org/download/) for dependency management.
7+
- [`Yii2`](https://github.com/yiisoft/yii2) 2.0.53+ or 22.x.
8+
- Web server (Apache, Nginx, or built-in PHP server).
9+
10+
### Optional requirements
11+
12+
- **Node.js**: For advanced asset compilation (optional)
13+
- **Docker**: For containerized development
14+
15+
## Installation methods
16+
17+
### Method 1: Using composer (recommended)
18+
19+
Create a new project using the Yii App Basic template.
20+
21+
```bash
22+
composer create-project --prefer-dist --stability=dev yii2-extensions/app-basic myapp
23+
cd myapp
24+
```
25+
26+
### Method 2: Manual installation
27+
28+
1. **Download the template**:
29+
```bash
30+
git clone https://github.com/yii2-extensions/app-basic.git myapp
31+
cd myapp
32+
```
33+
34+
2. **Install dependencies**
35+
```bash
36+
composer install
37+
```
38+
39+
### Method 3: Using git
40+
41+
Clone the repository and set up your project.
42+
43+
```bash
44+
git clone https://github.com/yii2-extensions/app-basic.git myapp
45+
cd myapp
46+
rm -rf .git
47+
git init
48+
composer install
49+
```
50+
51+
## Post-installation setup
52+
53+
### Directory permissions
54+
55+
Ensure the following directories are writable by the web server.
56+
57+
```bash
58+
chmod 775 public/assets runtime tests/_output
59+
```
60+
61+
### Environment configuration
62+
63+
1. **Create environment file** (optional)
64+
```bash
65+
cp .env.example .env
66+
```
67+
68+
2. **Configure database connection** in `config/web/components.php`
69+
```php
70+
<?php
71+
72+
return [
73+
'db' => [
74+
'class' => 'yii\db\Connection',
75+
'dsn' => 'mysql:host=localhost;dbname=myapp',
76+
'username' => 'root',
77+
'password' => '',
78+
'charset' => 'utf8',
79+
],
80+
];
81+
```
82+
83+
### Web server configuration
84+
85+
#### Apache
86+
87+
Create `public/.htaccess`.
88+
89+
```apache
90+
RewriteEngine on
91+
RewriteCond %{REQUEST_FILENAME} !-f
92+
RewriteCond %{REQUEST_FILENAME} !-d
93+
RewriteRule . index.php
94+
```
95+
96+
#### Nginx
97+
98+
Add to your Nginx configuration.
99+
100+
```nginx
101+
server {
102+
listen 80;
103+
server_name myapp.local;
104+
root /path/to/myapp/public;
105+
index index.php;
106+
107+
location / {
108+
try_files $uri $uri/ /index.php?$query_string;
109+
}
110+
111+
location ~ \.php$ {
112+
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
113+
fastcgi_index index.php;
114+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
115+
include fastcgi_params;
116+
}
117+
118+
location ~ /\.(ht|svn|git) {
119+
deny all;
120+
}
121+
}
122+
```
123+
124+
#### Built-in PHP server
125+
126+
For development purposes.
127+
128+
```bash
129+
# Method 1: Using PHP built-in server
130+
php -S localhost:8080 -t public
131+
132+
# Method 2: Using Yii console command
133+
./yii serve
134+
135+
# Method 3: Custom host and port
136+
./yii serve --host=0.0.0.0 --port=8080
137+
```
138+
139+
## Development setup
140+
141+
### Database setup
142+
143+
1. **Create database**
144+
```sql
145+
CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
146+
```
147+
148+
2. **Run migrations** (if available)
149+
```bash
150+
./yii migrate
151+
```
152+
153+
3. **Seed test data** (optional)
154+
```bash
155+
./yii fixture/load
156+
```
157+
158+
### Asset compilation
159+
160+
For advanced asset management.
161+
162+
```bash
163+
# Install Node.js dependencies
164+
npm install
165+
166+
# Compile assets
167+
npm run build
168+
169+
# Watch for changes during development
170+
npm run watch
171+
```
172+
173+
## Docker setup
174+
175+
### Using docker compose
176+
177+
Create `docker-compose.yml`.
178+
179+
```yaml
180+
version: '3.8'
181+
182+
services:
183+
web:
184+
image: yiisoftware/yii2-php:8.1-apache
185+
ports:
186+
- "8080:80"
187+
volumes:
188+
- .:/app
189+
depends_on:
190+
- db
191+
environment:
192+
- DB_HOST=db
193+
- DB_NAME=myapp
194+
- DB_USER=root
195+
- DB_PASSWORD=secret
196+
197+
db:
198+
image: mysql:8.0
199+
environment:
200+
- MYSQL_ROOT_PASSWORD=secret
201+
- MYSQL_DATABASE=myapp
202+
volumes:
203+
- mysql_data:/var/lib/mysql
204+
205+
volumes:
206+
mysql_data:
207+
```
208+
209+
Run the application.
210+
211+
```bash
212+
docker-compose up -d
213+
```
214+
215+
### Using Docker directly
216+
217+
```bash
218+
# Build custom image
219+
docker build -t myapp .
220+
221+
# Run container
222+
docker run -p 8080:80 myapp
223+
```
224+
225+
### Performance optimization
226+
227+
#### Enable OPcache
228+
229+
Add to your `php.ini`.
230+
231+
```ini
232+
opcache.enable=1
233+
opcache.enable_cli=1
234+
opcache.memory_consumption=128
235+
opcache.interned_strings_buffer=8
236+
opcache.max_accelerated_files=4000
237+
opcache.revalidate_freq=60
238+
opcache.fast_shutdown=1
239+
```
240+
241+
#### Configure caching
242+
243+
Enable cache components in `config/web/components.php`.
244+
245+
```php
246+
'cache' => [
247+
'class' => 'yii\caching\FileCache',
248+
],
249+
'urlManager' => [
250+
'enablePrettyUrl' => true,
251+
'showScriptName' => false,
252+
'enableStrictParsing' => false,
253+
'rules' => [
254+
// Your URL rules
255+
],
256+
],
257+
```
258+
259+
## Next steps
260+
261+
Once the installation is complete.
262+
263+
- ⚙️ [Configuration Reference](configuration.md)
264+
- 💡 [Usage Examples](examples.md)
265+
- 🧪 [Testing Guide](testing.md)

0 commit comments

Comments
 (0)