Cara Install Yii di Ubuntu
Yii adalah framework bahasa pemrograman PHP yang dirilis pertama kali pada Desember 2008. Versi terbaru yaitu versi 2.0.13 atau biasa disebut yii2. Yii dibaca “Yee” yang dalam bahasa China artinya sederhana dan evolusioner. Yii juga merupakan akronim untuk “Yes It Is!”.
Kebutuhan Install Yii
LAMP Server
Sebelum install Yii, kita sudah harus memiliki web server misalnya LAMP. Silakan baca tutorial Cara Install LAMP Server di Ubuntu.
Composer
Direkomendasikan install Yii melalui composer, perangkat lunak dependency injection atau PHP package manager. Composer membutuhkan jaringan internet yang stabil pada saat melakukan download package.
1 2 3 | sudo apt-get install curl php-cli php-mbstring git unzip curl –sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer |
Install Yii
Yii memiliki dua application template yaitu basic dan advanced. Perbedaan keduanya lihat gambar di bawah ini.
Yii Basic
1 2 | cd /var/www/html composer create-project --prefer-dist yiisoft/yii2-app-basic yii2basic |
Buat file VirtualHost
1 | sudo nano /etc/apache2/sites-available/yiibsc.conf |
Isinya
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <VirtualHost *:80> ServerName yiibasic.local DocumentRoot /var/www/html/yii2basic/web <Directory /var/www/html/yii2basic/web> # use mod_rewrite for pretty URL support RewriteEngine on # If a directory or a file exists, use the request directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise forward the request to index.php RewriteRule . index.php # use index.php as index file DirectoryIndex index.php </Directory> </VirtualHost> |
Aktifkan VirtualHost
1 | sudo a2ensite yiibsc.conf |
Restart service
1 | sudo service apache2 restart |
Edit file /etc/hosts
1 | sudo nano /etc/hosts |
Tambahkan
1 | 127.0.0.1 yiibasic.local |
Sekarang akses http://yiibasic.local
Yii Advanced
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | cd /var/www/html composer create-project --prefer-dist yiisoft/yii2-app-advanced yii2advanced cd yii2advanced php init Yii Application Initialization Tool v1.0 Which environment do you want the application to be initialized in? [0] Development [1] Production Your choice [0-1, or "q" to quit] 0 Initialize the application under 'Development' environment? [yes|no] yes Start initialization ... generate backend/config/main-local.php generate backend/config/params-local.php generate backend/config/test-local.php generate backend/web/index-test.php generate backend/web/index.php generate backend/web/robots.txt generate common/config/main-local.php generate common/config/params-local.php generate common/config/test-local.php generate console/config/main-local.php generate console/config/params-local.php generate frontend/config/main-local.php generate frontend/config/params-local.php generate frontend/config/test-local.php generate frontend/web/index-test.php generate frontend/web/index.php generate frontend/web/robots.txt generate yii generate yii_test generate yii_test.bat generate cookie validation key in backend/config/main-local.php generate cookie validation key in frontend/config/main-local.php chmod 0777 backend/runtime chmod 0777 backend/web/assets chmod 0777 frontend/runtime chmod 0777 frontend/web/assets chmod 0755 yii chmod 0755 yii_test ... initialization completed. |
Membuat VirtualHost untuk Yii Advanced Frontend dan Backend
1 | sudo nano /etc/apache2/sites-available/yiiadv.conf |
Isinya
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <VirtualHost *:80> ServerName yii-frontend.local DocumentRoot /var/www/html/yii2advanced/frontend/web <Directory /var/www/html/yii2advanced/frontend/web> # use mod_rewrite for pretty URL support RewriteEngine on # If a directory or a file exists, use the request directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise forward the request to index.php RewriteRule . index.php # use index.php as index file DirectoryIndex index.php </Directory> </VirtualHost> <VirtualHost *:80> ServerName yii-backend.local DocumentRoot /var/www/html/yii2advanced/backend/web <Directory /var/www/html/yii2advanced/backend/web> # use mod_rewrite for pretty URL support RewriteEngine on # If a directory or a file exists, use the request directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise forward the request to index.php RewriteRule . index.php # use index.php as index file DirectoryIndex index.php </Directory> </VirtualHost> |
Aktifkan VirtualHost
1 | sudo a2ensite yiiadv.conf |
Restart service
1 | sudo service apache2 restart |
Edit file /etc/hosts
1 | sudo nano /etc/hosts |
Tambahkan
1 | 127.0.0.1 yii-frontend.local yii-backend.local |
Sekarang akses http://yii-frontend.local
Dan http://yii-backend.local
selamat mencoba 🙂
keren stah
mantap thanks mas