Showing posts with label :: PHP. Show all posts
Showing posts with label :: PHP. Show all posts

Sunday, March 2, 2014

How To Install Linux, Apache, MySQL, PHP on Centos 5

Firsly update packages on Centos
sudo yum update

1. Install Apache

sudo yum install httpd
sudo service httpd start

2. Install MySQL

sudo yum install mysql-server
sudo service mysqld start
You can set a root MySQL password with these command:
sudo /usr/bin/mysql_secure_installation

3. Install PHP

sudo yum install php php-mysql

   PHP Modules

You can see the libraries that are available by typing:
yum search php-
Then terminal will show list of modules:
php53-process.i386 : Modules for PHP script using system process interfaces
php53-pspell.i386 : A module for PHP applications for using pspell interfaces
php53-snmp.i386 : A module for PHP applications that query SNMP-managed devices
php53-soap.i386 : A module for PHP applications that use the SOAP protocol
php53-xml.i386 : A module for PHP applications which use XML
php53-xmlrpc.i386 : A module for PHP applications which use the XML-RPC protocol
To see more detail:
yum info name_of_module
To install the module:
yum install name_of_module
Finally, restart your apache to see the effect for the changed:
sudo service httpd restart

Friday, October 4, 2013

How to auto load file class in PHP

Here's the sample how to load class in the file of PHP
here we go! Let's put two files in the html(/var/www/html) directory on your computer.
First file contain of Class code:
# sample.php

< ?php

class Sample
{
    // property declaration
    public $var = 'hello world';

    // method declaration
    public function display() {
        echo $this->var;
    }
}

? >

Second file:
# load.php

< ?php

function __autoload($class_name) {
    include strtolower($class_name) . '.php';
}

$obj  = new Sample();

echo $obj->display();

? >

Next step is access load.php file from localhost:
http://localhost/load.php for more visit this page

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.

Monday, April 29, 2013

PHP Interactive Shell

Using the interactive shell you are able to type PHP code and have it executed directly.

  
$ php -a
Interactive shell

php > echo 5+8;
13

Friday, April 12, 2013

Execute PHP script from Crontab

Here's just example, the PHP code will excute in every 5 minutes
Open your terminal and type
crontab -e
and new line
*/5 * * * * /usr/bin/php /home/arul/myscript.php
For more informatioin about the guide Crontab, you can see on this Crontab Manual