2014年7月19日 星期六

The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,'

function my_session_start()
{
    $sn = session_name();

    if (isset($_COOKIE[$sn])) {
        $sessid = $_COOKIE[$sn];
    } else if (isset($_GET[$sn])) {
        $sessid = $_GET[$sn];
    } else {
        return session_start();
    }

    if (!preg_match('/^[a-zA-Z0-9,\-]{22,40}$/', $sessid)) {
        return false;
    }

    return session_start();
}

if ( !my_session_start() ) {
    session_id( uniqid() );
    session_start();
    session_regenerate_id();
}

參考來源:
http://stackoverflow.com/questions/3185779/the-session-id-is-too-long-or-contains-illegal-characters-valid-characters-are

2014年7月16日 星期三

Apache Virtual Hosts on Ubuntu 14.04

1.建立新資料夾(放置web source)

預設document root在 /var/www,所以在此目錄下建一個新目錄:
sudo mkdir /var/www/example.com/


2.Grant Permissions


sudo chown -R $USER:$USER /var/www/example.com/
($USER設呈現在登入的user name)

sudo chmod -R 755 /var/www/example.com/

3.建立新的Virtual Host Files

sudo vi /etc/apache2/sites-available/example.com.conf
檔案內容如下:

ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined


4.Enable the New Virtual Host Files

sudo a2ensite example.com.conf

5.Apache重新載入設定:

sudo service apache2 reload
or
sudo service apache2 restart

apache支援.htaccess rewrite (ubuntu 14.04)

如果mod_rewrite.so已經載入,在 /etc/apache2/apache2.conf中,將


Options Indexes FollowSymLinks
AllowOverride None
Require all granted


改成


Options Indexes FollowSymLinks
AllowOverride ALL
Require all granted

就可以了。

Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

ubuntu apache 有下列error
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

1.開啟rewrite module
sudo a2enmod rewrite

2.重開apache
service apache2 restart

2014年7月15日 星期二

Install pcntl extension on ubuntu 14.04


1.抓php source code來編譯pcntl.so

mkdir tmp/phpsource
cd /tmp/phpsource
apt-get source php5
cd /tmp/phpsource/php5-*/ext/pcntl
phpize
./configure
make


2.將編好的pcntl.so複製到php lib裡


cd modules
cp pcntl.so /usr/lib/php5//


3.新增pcntl.ini


vi /etc/php5/mods-available/pcntl.ini
加入下列此行
extension=pcntl.so

4.link to mods-available/

cd /etc/php5/apache2/conf.d
ln -s /etc/php5/mods-available/pcntl.ini 20-pcntl.ini


5.編輯php.ini.


memory_limit  = 256M
找到下列這行,並再前方加上;(註解掉此行)
disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,

Install Apache + PHP on Ubuntu 14.04

1.更新apt-get
sudo apt-get update

2.安裝apache
sudo apt-get install apache2 libapache2-mod-auth-mysql


3.安裝php以及所需extension:
sudo apt-get install php5 php5-mysql php5-mcrypt php5-curl


4.重開apache service
sudo service apache2 restart


其他一些常用設定路徑:

1.Configuration File Path
/etc/php5/apache2/php.ini

2.Loaded Configuration File
/etc/apache2/apache2.conf

3.The default Ubuntu document root
/var/www/html

By default, Ubuntu does not allow access through the web browser to any file apart of those located in/var/www, public_html directories (when enabled) and /usr/share (for web applications). If your site is using a web document root located elsewhere (such as in /srv) you may need to whitelist your document root directory in /etc/apache2/apache2.conf.

The default Ubuntu document root is /var/www/html. You can make your own virtual hosts under /var/www. This is different to previous releases which provides better security out of the box.