Saturday, September 28, 2013

Setting Virtual Host (VHost) on Mac OS X

1. Preparation

In this section i'm used local.mysite.dev for sample
Start Apache
1. Go to System Preferences
2. Select "sharing"
3. Check the box "Web Sharing" -- for starting the apache

2. Edit the Host file

For editing you can use nano or mate text editor for command line
sudo nano /etc/hosts
or
sudo nano /private/etc/hosts
You can see the following codes:
#
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost
add new host local.mysite.dev at end of line
#
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost
127.0.0.1       local.mysite.dev


3. Switch in the httpd.conf file

sudo nano /etc/apache2/httpd.conf
find the "# Virtual hosts" string using ctl + w and type "# Virtual hosts" without (")
# Virtual hosts 
#Include /private/etc/apache2/extra/httpd-vhosts.conf
un comment the code to enable the VHost
# Virtual hosts 
Include /private/etc/apache2/extra/httpd-vhosts.conf


4. Add virtual host in apache

sudo nano /private/etc/apache2/extra/httpd-vhosts.conf
add these codes:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any  block.
#
                                                                                                   
< VirtualHost *:80>
  ServerName localhost
  DocumentRoot "/Library/WebServer/Documents"
< /VirtualHost>

< VirtualHost *:80>
  ServerAdmin local@mysite.dev
  DocumentRoot "/Library/WebServer/Documents/mysite/webroot/"
  ServerName local.mysite.dev
    < directory "/Library/WebServer/Documents/mysite/webroot/">
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      Allow from all
    < /directory>
  ErrorLog "/private/var/log/apache2/local.mysite.dev.com-error_log"
< /VirtualHost>


5. Restart Apache

finally, restart the Apache
sudo apachectl restart
Open your browser the type the url (http://local.mysite.dev) --for example

How to run TextMate command in terminal on Mac OS

I have installed TextMate on my Mac,
i wanna edit some file in terminal using TextMate, googling that issue and found some tutorial
here's the step:
Open your Terminal and type
sudo ln -s /Applications/TextMate.app/Contents/SharedSupport/Support/bin/mate /usr/bin
now, you can call TextMat app with "mate" command:
mate /path/file_you_want_to_edit.txt
for more help, just type:
mate --help

Sunday, September 15, 2013

How to remove rails uninstalled in gem list

I have uninstalled the rails old version but still list when i type "gem list"
Just type on your terminal:
sudo gem cleanup

Monday, May 20, 2013

How to encoding UTF-8 string to ASCII from Database

I have convert data from excel to mysql,
but when i printout to browser from database
seen string ugly..
i have resolve this issue, when i googling..


This simple way, just put the code like the bellow.
mb_convert_encoding($string_from_db, 'HTML-ENTITIES', 'UTF-8');

Wednesday, May 8, 2013

PHP Notice: A session had already been started - ignoring session_start()

I got this problem when redirect link location, but resolved this issue
this way:


Just put ob_start() function at beginning of the codes
< ?
ob_start();
header("location:home.php");
?>

Thursday, May 2, 2013

Turn off warnings and notice on PHP on Mac







To clear this issue, follow the step:
sudo cp -rf /etc/php.ini.default /etc/php.ini
sudo nano /etc/php.ini
then find and edit error_reporting
CTRL+W to find error_reporting module the change that code like the bellow line:
error_reporting = E_ALL & ~E_NOTICE
Restart your apache
sudo apachectl restart
that's all, reload your page.

Forbidden You don't have permission to access / on this server







I got this issue on Mac Lion OS X.
to fix this issue, just simple step.. here we go

Oper your terminal and type:
sudo nano /etc/apache2/extra/httpd-vhosts.conf 
add these line of codes:
< VirtualHost *:80>
   DocumentRoot "/Library/WebServer/Documents"
< /VirtualHost>
Restart your apache
sudo apachectl restart