Skip to content

Instantly share code, notes, and snippets.

@JQL
Last active February 25, 2019 21:43
Show Gist options
  • Save JQL/a1d78b4fdfeb14e4f14c68cdcf3ee2f7 to your computer and use it in GitHub Desktop.
Save JQL/a1d78b4fdfeb14e4f14c68cdcf3ee2f7 to your computer and use it in GitHub Desktop.
Configuring Yii2 Basic (in NetBeans IDE)

1. Virtual Host

C:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    ##ServerAdmin webmaster@tutorial
    DocumentRoot c:/xampp/htdocs/tutorial
    ServerName tutorial
    ServerAlias tutorial.local
</VirtualHost>

C:\Windows\System32\drivers\etc\hosts

127.0.0.1	tutorial
127.0.0.1	tutorial.local

2. PHPMyAdmin

either:

CREATE DATABASE IF NOT EXISTS `tutorial` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

or Manually

3. NetBeans

a) Properties

Project URL: http://tutorial/

b) config

db.php

<?php

return [
  'class' => 'yii\db\Connection',
  'dsn' => 'mysql:host=localhost;dbname=tutorial',
  'username' => 'root', // or your Username
  'password' => '',	// enter your password if you have used one
  'charset' => 'utf8',
  // Schema cache options (for production environment)
  //'enableSchemaCache' => true,
  //'schemaCacheDuration' => 60,
  //'schemaCache' => 'cache',
];

params.php

<?php

return [
  'adminEmail' => 'me@gmail.com',	// Your EMAIL address
  'supportEmail' => 'me@gmail.com',	// Your EMAIL address
  'user.passwordResetTokenExpire' => 3600,
  'company' => 'jlavelle.uk',		// Your Company name or your name
];

web.php

to $config = [ add: 'name' => 'yii2Stuff',

to $config = [ 'components' => [

uncomment:

    'urlManager' => [
      'enablePrettyUrl' => true,
      'showScriptName' => false,
      'rules' => [
      ],
    ],

c) .htaccess

Required if you've configured PrettyUrls

# Use UTF-8 encoding for anything served as `text/html` or `text/plain`.

AddDefaultCharset utf-8

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# Force UTF-8 for certain file formats.
<IfModule mod_mime.c>
  AddCharset utf-8 .atom .css .js .json .rss .vtt .webapp .xml
</IfModule>

# Block access to directories without a default document.
# Usually you should leave this uncommented because you shouldn't allow anyone
# to surf through every directory on your server (which may includes rather
# private places like the CMS's directories).
<IfModule mod_autoindex.c>
  Options -Indexes
</IfModule>

# prevent httpd from serving dotfiles (.htaccess, .svn, .git, etc.)
RedirectMatch 403 /\..*$

# Block access to hidden files and directories.
# This includes directories used by version control systems such as Git and SVN.

<IfModule mod_rewrite.c>
  RewriteCond %{SCRIPT_FILENAME} -d [OR]
  RewriteCond %{SCRIPT_FILENAME} -f
  RewriteRule "(^|/)\." - [F]
</IfModule>

# Used to create the "pretty URLs"
<IfModule mod_rewrite.c>
  # if a directory or a file exists, use it directly
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  # otherwise forward it to index.php
  # RewriteRule . index.php
  # RewriteRule ^(.*)\?*$ index.php/$1 [QSA] # for Pretty URLs plus Query Strings
  RewriteRule ^(.*)\?*$ index.php/$1
</IfModule>

# Block access to backup and source files.
# These files may be left by some text editors and can pose a great security
# danger when anyone has access to them.
<FilesMatch "(^#.*#|\.(bak|config|dist|fla|inc|ini|jql|log|psd|sh|sql|sw[op])|~)$">
  Order allow,deny
  Deny from all
  Satisfy All
</FilesMatch>

# ------------------------------------------------------------------------------
# | Content transformations                                                    |
# ------------------------------------------------------------------------------
# Prevent some of the mobile network providers from modifying the content of
# your site: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.5.
<IfModule mod_headers.c>
  Header set Cache-Control "no-transform"
</IfModule>

d) views/layout/main.php

NavBar

'brandLabel' => Yii::$app->name,

Footer

        <p class="pull-left">&copy;<?= date('Y') . ' ' . Yii::$app->params['company'] ?></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment