PHP Configuration Example

1. Check package
( You need to configure Apache http server, Mariadb in advance. )
# rpm -qa | grep -i php
php-cli.x86_64                           5.3.3-46.el6_6              @updates   
php-common.x86_64                        5.3.3-46.el6_6              @updates   

( you have to install "php-x.x.x.." rpm  and "php-mysql-x.x.x..." rpm .) 
 (  run: 
       # yum install php
       # yum install php-mysql
 )
2. Identify added packages
#  rpm -qa | grep php
php-mysql-5.3.3-49.el6.x86_64    (added)
php-5.3.3-49.el6.x86_64          (added)
php-pdo-5.3.3-49.el6.x86_64      (added)
php-cli-5.3.3-49.el6.x86_64
php-common-5.3.3-49.el6.x86_64
3. Identify php libraries
# ls -al /usr/lib64/php/modules
drwxr-xr-x 2 root root    4096 2017-06-09 06:05 .
drwxr-xr-x 4 root root    4096 2017-03-22 21:29 ..
-rwxr-xr-x 1 root root   66448 2017-03-22 21:29 curl.so
-rwxr-xr-x 1 root root 1843120 2017-03-22 21:29 fileinfo.so
-rwxr-xr-x 1 root root   36200 2017-03-22 21:29 json.so
-rwxr-xr-x 1 root root   54408 2017-03-22 21:29 mysql.so
-rwxr-xr-x 1 root root  136832 2017-03-22 21:29 mysqli.so
-rwxr-xr-x 1 root root  102456 2017-03-22 21:29 pdo.so
-rwxr-xr-x 1 root root   30112 2017-03-22 21:29 pdo_mysql.so
-rwxr-xr-x 1 root root   24640 2017-03-22 21:29 pdo_sqlite.so
-rwxr-xr-x 1 root root  261392 2017-03-22 21:29 phar.so
-rwxr-xr-x 1 root root   44368 2017-03-22 21:29 sqlite3.so
-rwxr-xr-x 1 root root   83088 2017-03-22 21:29 zip.so

4. Identify php library file and conf file in httpd directory
# ls -al /usr/lib64/httpd/modules/ 
drwxr-xr-x. 2 root root    4096 2017-06-09 06:01 .
drwxr-xr-x. 4 root root    4096 2015-10-01 21:49 ..
-rwxr-xr-x  1 root root 3699120 2017-03-22 21:29 libphp5.so            (added)
-rwxr-xr-x  1 root root   10416 2015-08-25 02:53 mod_actions.so
-rwxr-xr-x  1 root root   14608 2015-08-25 02:53 mod_alias.so
-rwxr-xr-x  1 root root   10416 2015-08-25 02:53 mod_asis.so
-rwxr-xr-x  1 root root   10448 2015-08-25 02:53 mod_auth_basic.so
-rwxr-xr-x  1 root root   31256 2015-08-25 02:53 mod_auth_digest.so



# ls -al  /etc/httpd/conf.d/  
drwxr-xr-x 2 root root 4096 2017-06-09 06:01 .
drwxr-xr-x 4 root root 4096 2015-10-01 21:47 ..
-rw-r--r-- 1 root root  392 2015-08-25 02:53 README
-rw-r--r-- 1 root root  674 2017-03-22 21:29 php.conf                   (added)
-rw-r--r-- 1 root root  299 2015-08-18 14:57 welcome.conf


#cat /etc/httpd/conf.d/php.conf

	#
	# PHP is an HTML-embedded scripting language which attempts to make it
	# easy for developers to write dynamically generated webpages.
	#
	
	  LoadModule php5_module modules/libphp5.so
	
	
	  LoadModule php5_module modules/libphp5-zts.so
	
	
	#
	# Cause the PHP interpreter to handle files with a .php extension.
	#
	AddHandler php5-script .php
	AddType text/html .php
	
	#
	# Add index.php to the list of files that will be served as directory
	# indexes.
	#
	DirectoryIndex index.php
	
	#
	# Uncomment the following line to allow PHP to pretty-print .phps
	# files as PHP source code:
	#
	#AddType application/x-httpd-php-source .phps


5. Modify php.ini
# vi /etc/php.ini

allow_url_fopen = Off
display_errors = Off
magic_quotes_gpc = Off
file_uploads = Off
log_errors = On
error_log = php_errors.log
date.timezone = America/New_York


 ( php_errors.log file is created in DocumentRoot "/var/www/html".
   If you don't set "date.timezone" , Some Warning may occur in  php_errors.log file like "PHP Warning:  strftime():" 

       date.timezone =   [timezamong list] 

      [timezamong list]        Refer to the link   http://php.net/manual/en/timezones.php 
        America/New_York
        Europe/Paris
        Europe/London
        Asia/Seoul
        Asia/Shanghai
        Asia/Tokyo
          .... 
7. Stop and Start httpd
# service httpd restart

or

# apachectl stop
# apachectl start
8. Check test web page ( php + Mariadb )
In yor browser (client pc) 
http://192.168.25.50/test.php 
 


# vi /var/www/html/test.php 


           <?php

           define('__HOST__',     '192.168.25.50');
           define('__DATABASE__', 'zamong') ;
           define('__PORT__',      3306 );
           define('__USER__',     'mong');
           define('__PASSWORD__', 'aaaaa');


              $conn = mysqli_connect(__HOST__, __USER__, __PASSWORD__ ,__DATABASE__ , __PORT__  );

             
              if ( !$conn )
                {  echo "db connection fail: ERROR "  .  mysqli_connect_error()  ;
                   exit ;
                }
              else
                {
                   echo "db connection success" ;
                   exit ;
                 }

           ?>



      
9. Check php error Log
# cat /var/www/html/php_errors.log
[17-Jan-2017 17:55:59] PHP Warning:  strftime(): It is not safe to rely on the system's timezone settings.
[18-jan-2017 13:24:44] PHP Warning:  mysqli_connect(): (28000/1045): Access denied for user 'mong'@'127.0.0.1' 
                      (using password: YES) in /var/www/html/ph/test.php on line 12

 ( php_errors.log will be created in documentRoot(/var/www/html) or subdirectory )

Other Tutorials

Zamong Setup
Installation and Configuration of Mariadb or Mysql
Installation and Configuration of Apache Http Server (RPM) on Centos