/usr/share/zoneinfo/ - The system time-zone information directory.
/etc/localtime - The symlink to the timezone file
Image: Update Timezone to Asia/Colombo
Tuesday, December 12, 2017
Friday, March 27, 2015
Create a web application using Yii2
The latest version of Yii 2 is 2.0.3, released on March 1, 2015.Related Links
Environment
- OS: Ubuntu 14.04
Installation of an application template
- Find / Create a suitable directory in your hard drive.
- Install Composer
- $ curl -sS https://getcomposer.org/installer | php
- Install the Composer Asset Plugin
- $ php composer.phar global require "fxp/composer-asset-plugin:1.0.0"
- To install the basic application template, run the command below:
- php composer.phar create-project yiisoft/yii2-app-basic basic 2.0.3
- To install the advanced application template, run the command below:
- php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.3
$ curl -sS https://getcomposer.org/installer | php #!/usr/bin/env php All settings correct for using Composer Downloading... Composer successfully installed to: /Data/nuwan/Research/yii2/app1/composer.phar Use it: php composer.phar $ php composer.phar global require "fxp/composer-asset-plugin:1.0.0" Changed current directory to /home/nuwan/.composer ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) - Removing fxp/composer-asset-plugin (1.0.x-dev dc24e62) - Installing fxp/composer-asset-plugin (v1.0.0) Downloading: 100% Writing lock file Generating autoload files $ php composer.phar create-project yiisoft/yii2-app-basic basic 2.0.3 Installing yiisoft/yii2-app-basic (2.0.3) - Installing yiisoft/yii2-app-basic (2.0.3) Downloading: 100% Created project in basic Loading composer repositories with package information Installing dependencies (including require-dev) Reading bower.json of bower-asset/jquery.inputmask (3.1.51) Could not fetch https://api.github.com/repos/RobinHerbots/jquery.inputmask/contents/bower.json?ref=f29e2b535028bde8e1135deb65cb5ed2e081cf39, enter your GitHub credentials to go over the API rate limit A token will be created and stored in "/home/nuwan/.composer/auth.json", your password will never be stored To revoke access to this token you can visit https://github.com/settings/applications Username: srinuwanperera@gmail.com Password: Token successfully created Reading bower.json of bower-asset/bootstrap (v3.1.1) Reading bower.json of bower-asset/bootstrap (v3.3.1) - Installing yiisoft/yii2-composer (2.0.3) Downloading: 100% - Installing ezyang/htmlpurifier (v4.6.0) Loading from cache - Installing swiftmailer/swiftmailer (v5.4.0) Downloading: 100% - Installing bower-asset/jquery (2.1.3) Downloading: 100% - Installing bower-asset/yii2-pjax (v2.0.4) Downloading: 100% - Installing bower-asset/punycode (v1.3.2) Downloading: 100% - Installing bower-asset/jquery.inputmask (3.1.62) Downloading: 100% - Installing cebe/markdown (1.0.2) Downloading: 100% - Installing yiisoft/yii2 (2.0.3) Downloading: 100% - Installing yiisoft/yii2-swiftmailer (2.0.3) Downloading: 100% - Installing yiisoft/yii2-codeception (2.0.3) Downloading: 100% - Installing bower-asset/bootstrap (v3.3.4) Downloading: 100% - Installing yiisoft/yii2-bootstrap (2.0.3) Downloading: 100% - Installing yiisoft/yii2-debug (2.0.3) Downloading: 100% - Installing bower-asset/typeahead.js (v0.10.5) Downloading: 100% - Installing phpspec/php-diff (v1.0.2) Loading from cache - Installing yiisoft/yii2-gii (2.0.3) Downloading: 100% - Installing fzaninotto/faker (v1.4.0) Downloading: 100% - Installing yiisoft/yii2-faker (2.0.3) Downloading: 100% Writing lock file Generating autoload files chmod('runtime', 0777)...done. chmod('web/assets', 0777)...done. chmod('yii', 0755)...done. $ $ php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.3 Installing yiisoft/yii2-app-advanced (2.0.3) - Installing yiisoft/yii2-app-advanced (2.0.3) Downloading: 100% Created project in advanced Loading composer repositories with package information Installing dependencies (including require-dev) - Installing yiisoft/yii2-composer (2.0.3) Loading from cache - Installing ezyang/htmlpurifier (v4.6.0) Loading from cache - Installing swiftmailer/swiftmailer (v5.4.0) Loading from cache - Installing bower-asset/jquery (2.1.3) Loading from cache - Installing bower-asset/yii2-pjax (v2.0.4) Loading from cache - Installing bower-asset/punycode (v1.3.2) Loading from cache - Installing bower-asset/jquery.inputmask (3.1.62) Loading from cache - Installing cebe/markdown (1.0.2) Loading from cache - Installing yiisoft/yii2 (2.0.3) Loading from cache - Installing yiisoft/yii2-swiftmailer (2.0.3) Loading from cache - Installing yiisoft/yii2-codeception (2.0.3) Loading from cache - Installing bower-asset/bootstrap (v3.3.4) Loading from cache - Installing yiisoft/yii2-bootstrap (2.0.3) Loading from cache - Installing yiisoft/yii2-debug (2.0.3) Loading from cache - Installing bower-asset/typeahead.js (v0.10.5) Loading from cache - Installing phpspec/php-diff (v1.0.2) Loading from cache - Installing yiisoft/yii2-gii (2.0.3) Loading from cache - Installing fzaninotto/faker (v1.4.0) Loading from cache - Installing yiisoft/yii2-faker (2.0.3) Loading from cache Writing lock file Generating autoload files $ $ ll total 1068 drwxrwxr-x 4 nuwan nuwan 4096 මාර් 27 13:03 ./ drwxrwxr-x 3 nuwan nuwan 4096 මාර් 27 12:10 ../ drwxrwxr-x 9 nuwan nuwan 4096 මාර් 27 13:08 advanced/ drwxrwxr-x 13 nuwan nuwan 4096 මාර් 27 12:50 basic/ -rwxr-xr-x 1 nuwan nuwan 1075141 මාර් 27 12:12 composer.phar* $
Initialize the application (For advanced template)
- ./init
$ ./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 common/config/main-local.php generate common/config/params-local.php generate frontend/web/index-test.php generate frontend/web/index.php generate frontend/config/main-local.php generate frontend/config/params-local.php generate backend/web/index-test.php generate backend/web/index.php generate backend/config/main-local.php generate backend/config/params-local.php generate yii generate console/config/main-local.php generate console/config/params-local.php 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 ... initialization completed. $
Test the application using php server.
- Basic Application
- php -S localhost:8000 -t basic/web
- Advanced Application
- php -S localhost:8000 -t advanced/frontend/web/
- php -S localhost:8000 -t advanced/backend/web/
- Once the php server started, open a web browser and visit:
- http://localhost:8000/
$ php -S localhost:8000 -t advanced/frontend/web/ PHP 5.5.9-1ubuntu4.7 Development Server started at Fri Mar 27 13:28:22 2015 Listening on http://localhost:8000 Document root is /*******/advanced/frontend/web Press Ctrl-C to quit.
Tuesday, September 16, 2014
cannot enable executable stack as shared object requires: Permission denied
Story:
Today, One of our team member has been installed a clean installation of RHEL 6.3 (RedHat) and once we try to start the Apache web server, it went bad due to following error.Error:
Starting httpd:
httpd: Syntax error on line 218 of /etc/httpd/conf/httpd.conf: Cannot
load /etc/httpd/modules/libphp5.so into server:
/etc/httpd/modules/libphp5.so: cannot enable executable stack as
shared object requires: Permission denied
Solution:
- Log into the CLI - Command Line interface (As root user)
- Run Following Command
Image:
Tuesday, August 5, 2014
Abstract classes in PHP
Related Links
- http://php.net/manual/en/language.oop5.interfaces.php
- http://www.techflirt.com/tutorials/oop-in-php/abstract-classes-interface.html
What is class abstraction?
- PHP 5 introduces abstract classes and methods.
- Usually abstract class are also known as base class.
- Abstract classes are those classes which can not be directly initialized. Or in other word we can say that you can not create object of abstract classes.
- Any class that contains at least one abstract method must also be abstract.
- Abstract classes always created for inheritance purpose. You can only inherit abstract class in your child class.
- It can only act as parent class of any normal class. You can use abstract class in class hierarchy. Mean one abstract class can inherit another abstract class also.
- A protected abstract function can be implemented as either protected or public but not private.
Monday, October 7, 2013
How to set "auto_increment_increment" and "auto_increment_offset" - MySQL
Referred web sites:
What is "auto_increment_increment" and "auto_increment_offset" ?
Both "auto_increment_increment" and "auto_increment_offset" are system variables which required in MySQL Master-Master replication. By changing above variables you will be able to manage auto increment columns and avoid from data conflict issues in your database.What does it do ?
- "auto_increment_increment" controls the interval between successive column values
- auto_increment_offset determines the starting point for the AUTO_INCREMENT column value
How to access MySQL monitor (Ubuntu 12.04)
- Open Terminal window using "Dash Home".
- Log into MySQL Monitor (You may need a valid username and password)
mysqlor
mysql -urootor
mysql -uroot -p
mysql> SHOW VARIABLES LIKE 'auto_inc%';
mysql> CREATE DATABASE TEST_DB;
mysql> USE TEST_DB;
mysql> CREATE TABLE TestTable -> (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
mysql> INSERT INTO TestTable VALUES (NULL), (NULL), (NULL), (NULL);
mysql> SELECT * FROM TestTable;
mysql> SET @@auto_increment_increment=5;
mysql> INSERT INTO TestTable VALUES (NULL), (NULL), (NULL), (NULL);
mysql> SELECT * FROM TestTable;
- You can drop your "TestTable" and follow above instructions. But make sure to keep the table without any data.
- Also do not forget to set "auto_increment_increment"
mysql> SET @@auto_increment_offset=5;
mysql> INSERT INTO TestTable VALUES (NULL), (NULL), (NULL), (NULL);
Something to remember.
- You will be able to set "auto_increment_offset" greater then (>) "auto_increment_increment" and test again. But the value of "auto_increment_offset" will be ignore by the system.
- Because if the value of "auto_increment_offset" is greater than that of "auto_increment_increment", the value of auto_increment_offset is ignored.
Hardcode variables in my.cnf:
Also you can hardcode followings settings in your my.cnf file (/etc/my.cnf)# The MySQL server [mysqld] auto-increment-increment = 2 # No of replication servers auto-increment-offset = 1 # For first replication server
Tuesday, October 1, 2013
How to fix "It is not safe to rely on the system's timezone settings"
If you see one of following warnings when you run a PHP script:
- PHP Warning: mktime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Calcutta' for 'IST/5.0/no DST' instead in /opt/websites/www/sample.php on line 10
- PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Calcutta' for 'IST/5.0/no DST' instead in /opt/websites/www/sample.php on line 11
PHP Warning: mktime(): It is not safe to rely on the system's timezone settings. PHP Warning: date(): It is not safe to rely on the system's timezone settings.
You can try following solutions:
Solution 01
-
Find your timezone settings
(For Ubuntu)
cat /etc/timezone
(For Fedora/CentOS/RedHat)
cat /etc/sysconfig/clock
Figure: Ubuntu 12.04 Terminal
or simply select your timezone from http://php.net/manual/en/timezones.php -
Find your php.ini file to edit
(For Ubuntu)
cat /etc/php5/apache2/php.ini
(For Fedora/CentOS/RedHat)
cat /etc/php.ini
or You can locate all php.ini files using
locate php.ini
-
Restart Apache
(For Ubuntu)/etc/init.d/apache2 restart
orservice apache2 restart
(For Fedora/CentOS/RedHat)/etc/init.d/httpd restart
orservice httpd restart
Edit php.ini
Now insert following date-time settings into php.ini (replace "Asia/Colombo" using your timezone settings)[Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = Asia/Colombo
Solution 02
-
Edit your php script
if you are unable to access your php.ini, can set the default timezone at the beginning of your PHP scripts.
<?php date_default_timezone_set("Asia/Colombo");
Friday, September 6, 2013
Alternative PHP Cache (APC) - Installation guide.
Referred web sites:
- http://www.php.net/manual/en/book.apc.php
- http://php.find-info.ru/php/016/ch20lev1sec1.html
- http://linuxaria.com/howto/everything-you-need-to-know-about-apc-alternate-php-cache?lang=en
- http://lampzone.wordpress.com/2010/03/26/how-does-apc-work/
What is APC ?
- APC is stands for Alternative PHP Cache
- APC is a free and open opcode cache for PHP
- Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.
Who need APC ?
- System Administrator who need increase the performance of a PHP web site.
- Web designers/developers or programmers who develop web applications using Yii,WordPress,Drupal or any framework.
How can I find more information about APC ?
- You can read about apc on http://www.php.net/manual/en/book.apc.php
How APC works ?
- Information collected from linuxaria.com and lampzone.wordpress.com
- First of all, You need to know how a PHP application run by the Zend Engine (Opcodes and Op Arrays)
- The first step is reading the PHP code from the filesystem and put it into memory.
- Lexing : The php code inside is converted into tokens or Lexicons.
- Parsing : During this stage, tokens are processed to derive at meaningful expressions.
- Compiling : The derived expressions are compiled into opcodes.
- Executing : Opcodes are executed to get the final result.
- The goal of APC is bypass the steps from 1 to 4, caching in a shared memory segment the opcodes generated and then copies them into The execution process so Zend can actually execute the opcodes.
How to install APC ?
- There are 2 ways to install APC
- Install APC is with PECL
- With this method you’ll download the last source and compile it for you computer.
- For Debian and Ubuntu
sudo apt-get install php-pear php5-dev apache2-threaded-dev build-essential
sudo pecl install apc
- On Debian and Ubuntu APC is available on the main repository with this name:
sudo apt-cache search apc php php-apc - APC (Alternative PHP Cache) module for PHP 5 sudo aptitude install php-apc
sudo yum install php-pecl-apc
APC configurations
- Once installed APC must be enabled in the configuration file of PHP: php.ini, if you have installed APC from a package this is already done and you just have to restart Apache (or FastCGI daemon like FPM) to see a new APC section in phpinfo() which will confirm it’s enabled.
- Otherwise you have to include in your php.ini this line:
extension=apc.so
How to set APC runtime configuration ?
- Visit : php.net
Subscribe to:
Posts (Atom)