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

Saturday, June 16, 2018

How to upgrade PHP 7.2.6 on WAMP 3.0.6 server?

Software Required
- WAMP 3.0.6
- PHP 7.2.6

In the development stage, upgrading of PHP to support new library or functionality is unavoidable. WAMP has been used for my project development, however, PHP 7.2.6 doesn't exists in the WAMP 3.0.6. Below are the steps that I performed to import PHP interpreter into my WAMP container.

PHP installation steps
  • Download PHP from https://windows.php.net/download#php-7.2
  • Unzip the PHP zip file into "php7.2.6" folder and copy into "D:\wamp64\bin\php" folder.
  • Copy wampserver.conf from "D:\wamp64\bin\php\php5.6.25" to "D:\wamp64\bin\php\php7.2.6"
  • Browse to "D:\wamp64\bin\php\php7.2.6" folder, rename "php.ini-development" to "php.ini.
  • Alter php.ini by changing the new configuration as shown below
extension_dir = "d:/wamp64/bin/php/php7.2.6/ext"
upload_tmp_dir ="d:/wamp64/tmp"
error_log ="d:/wamp64/logs/php_error.log"
  • Alter the extension section at php.ini 
extension=php_bz2.dll
extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_gmp.dll
extension=php_intl.dll
extension=php_imap.dll
;extension=php_interbase.dll
extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_exif.dll
extension=php_mysqli.dll
;extension=php_oci8_12c.dll  ; Use with Oracle Database 12c Instant Client
;extension=php_odbc.dll
extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_shmop.dll

; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
;extension=php_snmp.dll

extension=php_soap.dll
extension=php_sockets.dll
extension=php_sqlite3.dll
;extension=php_tidy.dll
extension=php_xmlrpc.dll
extension=php_xsl.dll
;extension=php_com_dotnet.dll
;extension=php_dba.dll
;extension=php_enchant.dll
;extension=php_ftp.dll
;extension=php_phpdbg_webhelper.dll
;extension=php_sodium.dll
;extension=php_sysvshm.dll
;extension=php_zend_test.dll
  • Duplicate php.ini file and save it as phpForApache.ini.
  • Alter wampserver.conf located at "D:\wamp64\bin\php\php7.2.6" folder
$phpConf['apache']['2.4']['LoadModuleName'] = 'php7_module';
$phpConf['apache']['2.4']['LoadModuleFile'] = 'php7apache2_4.dll';
$phpConf['apache']['2.4']['AddModule'] =  '';
  • Launch wampserver manager, browse to "PHP" > "Version" menu, version 7.2.6 option is ready for selection. 
  • After select "7.2.6" menu and wamp manager has been restarted, browse to the site, PHP version 7.2.6 is displayed.


Monday, October 3, 2016

How to setup OAuth 2.0 server using Apigility?

Software required 

- apigility 1.5
- composer version 1.2.0
- git version 2.10.0

Installation steps
  • Assume apigility has been upgraded to version 1.5 by executing the command below. Version before 1.5 is buggy
 composer update  
[APIGILITY_HOME] is your apigility installation home folder
  •  Launch your APIGILITY admin module, click on "Authentication" menu to launch the configuration page. Click "New adapter" button to launch the adapter configuration page.
  • Fill in the info as shown in the screenshot below, click on "Save" button to create adapter.

  •  Ensure the Status API authentication type is set to the newly created adapter, "oauth2".



 http://apigility/oauth/authorize?response_type=code&client_id=testclient&redirect_uri=/oauth/receivecode&state=xyz   
  • Approval page is displayed as shown in the screen below

  • Once the "testclient" is approved, an authentication code is generated.

  • Use postman with the configuration as shown in the screenshot below, generated access_token to access the API


  • Call the "status" api and "ping" services with the access_token as shown in the screenshot below.

Public Clients
  • client_secret value is omitted for this case. User ID, password and client_id is required. grant_type = "password" is used. Please refer to the screenshot below

Application Access

  • This is used for machine to machine integration. client_id and client_secret are required. grant_type = "client_credentials" is used. Please refer to the screenshot below

    Sunday, September 11, 2016

    How to fix "Error on rename of mysql frm due to permission denied" error message on mysql?

    Try to integrate "lucadegasperi", an OAuth  component on my application recently, I was required to patch the database by running the given patch script. I encountered error message as shown below when run the patch script.

    C:\wamp\www\lumen>php artisan migrate --seed
    Migration table created successfully.
    
    
      [Illuminate\Database\QueryException]
      SQLSTATE[HY000]: General error: 7 Error on rename of '.\[DATABASE_NAME]\#sql-2f6
      c_6.frm' to '.\[DATABASE_NAME]\oauth_session_scopes.frm' (Errcode: 13 - Permissi
      on denied) (SQL: alter table `oauth_session_scopes` add index `oauth_sessio
      n_scopes_session_id_index`(`session_id`))
    
    
    
      [PDOException]
      SQLSTATE[HY000]: General error: 7 Error on rename of '.\[DATABASE_NAME]\#sql-2f6
      c_6.frm' to '.\[DATABASE_NAME]\oauth_session_scopes.frm' (Errcode: 13 - Permissi
      on denied)
    

    I was using a superuser account to connect to mysql database. Should not prompt this error message

    Solution

    • The root cause is the Mcafee antivirus on my Windows 10 stop the MySql to edit the FRM file when "alter" command is executed.
    •  In order to run the patch script, I temporary turn off the real time scanning on my Mcafee. Launch Mcafee and click on "Virus and Spyware protection" option.
    • Select "Real-Time Scanning"option and turn off the "Real-Time scanning" option.

    • Rerun the command "php artisan migrate --seed", all tables was created successfully.

    Friday, November 8, 2013

    How to get your phing to print out timestamp within your timezone?

    Try to get the phing scripts below to echo the right timestamp but always unable to do so. The printed timestamp always based on the UTC timestamp.

        <tstamp>
            <format pattern="%Y%m%d_%H%M%S" property="build.time">  
        </format></tstamp>
    
     <target name="tstamp"> 
      <tstamp>
      <echo>build time = ${build.time}</echo> 
     </tstamp></target>
    Initially, I thought this was phing issue, put the locale attributes insides 'format pattern="%Y%m%d_%H%M%S" property="build.time" locale="Asia/Singapore"', but it doesn't solve the issue.
    Spent quite a long time to find the root cause, finally, got the clue on what was happening.

    Open the php.ini that your PHP is referring to, edit the locale as your current timezone. For other timezone, please refer to http://us1.php.net/manual/en/datetime.configuration.php#ini.date.timezone
    date.timezone = Asia/Singapore
    
    Rerun your phing with the same piece of code. Voila! it just work like a charm!

    Sunday, October 27, 2013

    not working in PHP 5.3.3

    Redeploy my app on WAMP that aare running on PHP version 5.3.3, out of sudden, discover my old code that use is not working. All my pages suddenly display "?>" or ">" characters everywhere in my web page.

    Search through the web and finally got the solution:-

    Open php.ini, set "short_open_tag" to "On" value as described below

    short_open_tag = On
    Restart your webserver, everything will be working fine now.

    Thursday, October 3, 2013

    How to send email through telnet command to SMTP server?

    Assumption
    SMTP Server : [SMTP_SERVER]
    Client Machine Name : [CLIENT_MACHINE_NAME]
    Email From: [EMAIL_FROM]
    Email Recipient: [RCPT_TO]

    Steps to use telnet command to send email through SMTP server

    1. Type in telnet command as described below to connect to the SMTP server.
    telnet [SMTP_SERVER] 25
    2. Type in the command below to introduce yourself to the SMTP server. For example, "hello localhost"
    helo [CLIENT_MACHINE_NAME]
    3. Type in the command as described below to set the email address that used to send email.
    MAIL FROM:[EMAIL_FROM]
    4. Type in the command below to set the recipient gmail id
    RCPT TO:[RCPT_TO]
    5. Enter the command "DATA" to proceed with composing the email body.
    DATA
    6. Enter the email body and follow by '.' to trigger email sending
    Hello Testing!
    .

    Tuesday, October 1, 2013

    How to get your PHPMailer sample code to work properly with your SMTP Server?

    Download PHPMailer recently to test on email sending through SMTP server, out of no luck, it just can't send email through the SMTP server  (Microsoft ESMTP MAIL Service, Version: 5.0.2195.738).

    Assume the parameters below represent

    SMTP Server: [SMTP_SERVER]
    Client Server Name: [CLIENT_SERVER_NAME]

    Configure all the necessary parameter in SMTP.php class provided by PHPMailer in examples folder, out of no luck, it just can't send email. Turn on the SMTP debug parameters in SMTP.php

    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug  = 2;
    
    The debug messages are displayed as described below:
    SMTP -> FROM SERVER:220 [SMTP_SERVER] Microsoft ESMTP MAIL Service, Version: 5.0.2195.7381 ready at Mon, 23 Sep 2013 14:38:12 +0800 
    CLIENT -> SMTP: EHLO [[CLIENT_SERVER_NAME]]
    SMTP -> FROM SERVER: 501 5.5.4 Invalid Address
    SMTP -> ERROR: EHLO not accepted from server: 501 5.5.4 Invalid Address
    CLIENT -> SMTP: HELO [[CLIENT_SERVER_NAME]]
    SMTP -> FROM SERVER: 501 5.5.4 Invalid Address
    SMTP -> ERROR: HELO not accepted from server: 501 5.5.4 Invalid Address
    CLIENT -> SMTP: AUTH LOGIN
    SMTP -> ERROR: AUTH not accepted from server: 503 5.5.2 Send hello first
    CLIENT -> SMTP: quit
    SMTP -> FROM SERVER:221 2.0.0 [SMTP_SERVER] Service closing transmission channel
    SMTP Connect() failed.
    Mailer Error: SMTP Connect() failed.
    
    Refer to the debug messages, message "Invalid Address" is keep prompting.

    Troubleshoot the debug message and discovered that special character '[' and ']' is appended to the [SMTP_SERVER_NAME] value.

    Comment out 5 lines of source code at line 720  in "class.smtp.php" as described below and replace with a new 5 lines of source code as described below that removed '[' and ']' characters:
        //if(!$this->SendHello('EHLO', "[" . $host . "]")) {
        //  if(!$this->SendHello('HELO', "[" . $host . "]")) {
        //    return false;
        //  }
        //}
     
        if(!$this->SendHello('EHLO', $host)) {
          if(!$this->SendHello('HELO',$host)) {
            return false;
          }
        }
    
    Try to resend email, it just work like a charm!

    Thursday, September 12, 2013

    How to configure PHPUnit and Aptana Studio 3?

    Try to get PHPUnit integrated with Aptana Studio 3 for my unit testing, discover that it is not straight forward. Aptana Studio 3 is not ready for that kind of tight integration. I have to make use of "External Tools" on Aptana Studio to launch PHPUnit through DOS command.

    Assumption
    - PEAR has been installed
    - Running on Window 7
    - Download PHPUnit 3.7.25 from https://github.com/sebastianbergmann/phpunit/ ("phpunit.phar" will be downloaded)
    - Follow the Zend 2 sample tutorial to prepare the unit testing script http://framework.zend.com/manual/2.0/en/user-guide/unit-testing.html

    Steps to configure

    1. Install phpunit on your machine by running the command as described below in "Command Prompt" window with phpunit.phar in the same directory.
      
    pear config-set auto_discover 1
    pear install pear.phpunit.de/PHPUnit
    
    2. Once phpunit has been installed, phpunit.bat file will be created in [PEAR_INSTALL_PATH]. Launch the "Command Prompt" window and type in the command as described below to check the version of PHPUnit.
    phpunit --version
    PHPUnit 3.7.25 by Sebastian Bergmann.
    
    Note: "phpunit" command is working provided you right click "Command Prompt" icon and select "Run as administrator" to launch the "Command Prompt" window.

    3. In Aptana Studio 3.0, "External Tools" menu will not be available in the "Run" menu. Steps as described below are required to turn on the "External Tools" option.
    - Right click the "Web Perspective" and select "Customize" menu, "Customize Perspective" screen will be displayed.


    - Select "Command Groups Availability" tab and check the "External Tools" check box as shown in the screenshots below.

    - Click on "Ok" button to dismiss the "Customize Perspective" screen. Click on "Run" menu, "External Tools" will be displayed.

    4. Select "Run" ->  "External Tools" -> "External Tools Configuration", the configuration screen will be displayed.


    5. Fill in the details as described below
    Name: PHPUnit

    Location: [PEAR_INSTALL_PATH]\phpunit.bat
    Note: Normally phpunit.bat is located at the PEAR installation path if PEAR is used to install PHPUnit.

    Working Directory: ${project_loc}/module/Application/test
    Note: Based on the tutorial provided by Zend2, http://framework.zend.com/manual/2.0/en/user-guide/unit-testing.html, this should be the folder that consists of "phpunit.xml.dist" file.

    6. Select unit testing class, for example, "IndexControllerText.php", click on "Run" -> "External Tools" -> "PHPUnit", the unit testing script will be executed and test result will be output to "Console" screen.

    Friday, September 6, 2013

    Issue encounter and simple note on Mantis exploration

    System Environment
    Mantis Version: 1.2.15
    WAMP version 2.4

    How to configure email notification on Mantis using Gmail SMTP Server?

    Note: Assume Gmail account has been created

    Steps to resolve
    1. Open config_defaults_inc.php, edit the parameters as described below:
    /**
      * Allow email notification.
      * Set to ON to enable email notifications, OFF to disable them. Note that
      * disabling email notifications has no effect on emails generated as part
      * of the user signup process. When set to OFF, the password reset feature
      * is disabled. Additionally, notifications of administrators updating
      * accounts are not sent to users.
      * @global int $g_enable_email_notification
    */
    $g_enable_email_notification = ON;
    
    /**
      * select the method to mail by:
      * PHPMAILER_METHOD_MAIL - mail()
      * PHPMAILER_METHOD_SENDMAIL - sendmail
      * PHPMAILER_METHOD_SMTP - SMTP
      * @global int $g_phpMailer_method
    */
    $g_phpMailer_method = PHPMAILER_METHOD_SMTP;
    
    /**
      * This option allows you to use a remote SMTP host.  Must use the phpMailer script
      * One or more hosts, separated by a semicolon, can be listed.
      * You can also specify a different port for each host by using this
      * format: [hostname:port] (e.g. "smtp1.example.com:25;smtp2.example.com").
      * Hosts will be tried in order.
      * @global string $g_smtp_host
    */
    $g_smtp_host = 'smtp.gmail.com';
    
    /**
      * These options allow you to use SMTP Authentication when you use a remote
      * SMTP host with phpMailer.  If smtp_username is not '' then the username
      * and password will be used when logging in to the SMTP server.
      * @global string $g_smtp_username
    */
    $g_smtp_username = '[GMAIL_ACCT_ID]';
    
    /**
      * SMTP Server Authentication password
      * @global string $g_smtp_password
    */
    $g_smtp_password = '[GMAIL_ACCT_PASSWD]';
    
    /**
      * This control the connection mode to SMTP server. Can be 'ssl' or 'tls'
      * @global string $g_smtp_connection_mode
    */
    $g_smtp_connection_mode = 'ssl';
    
    /**
      * The smtp port to use.  The typical SMTP ports are 25 and 587.  The port to use
      * will depend on the SMTP server configuration and hence others may be used.
      * @global int $g_smtp_port
    */
    $g_smtp_port = 465;
    
    
    How to send email using simple SMTP command through Gmail SMTP Server?

    Note: 
    - Assume Perl is installed on your machine to encode both user id and password in base64.
    - Assume OpenSSL is available on your machine

    Steps to resolve

    1. Using openssl to direct connect to the Gmail SMTP server, a SSL handshaking will be executed.
    openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof
    

    2. Type in the command below to introduce yourself to the mail server.
    ehlo [MY_DOMAIN] //Note: ehlo localhost
    

    3. Before hand, please use Perl on another command prompt to encode both your [GMAIL_USER_ID] and [GMAIL_USER_PASSWORD] into base64. Below are the command helping you to generate encoded user id and password for authentication purpose.
    perl -MMIME::Base64 -e "print encode_base64(qq(\000[GMAIL_USER_ID]\@gmail.com\000[GMAIL_USER_PASSWORD]))"
    
    Once the command has been executed, you will get an encoded output, let's assume it as [BASE64_USERID_PASSWORD]

    4. Back to your SMTP command prompt, type in the command as shown below to pass the authentication
    AUTH PLAIN [BASE64_USERID_PASSWORD]
    
    Response "2.7.0 Accepted" will be prompted

    5. Type in the command below to set the sender gmail id
    MAIL FROM: <[SENDER_GMAIL_ID]@gmail.com>
    

    6. Type in the command below to set the recipient gmail id
    RCPT TO: <[RECIPIENT_GMAIL_ID]@gmail.com>
    

    7. Enter the command "DATA" to proceed with composing the email subject and body.
    DATA
    

    8. Enter the email body and subject based on the description and shown below
    Subject: Hello Testing
    
    Hello Testing!
    .
    
    Note: The '.' is represented the email composing has been completed and trigger sent command

    How to resolve Mantis email problem when WAMP 2.4 is used?

    Configure email notification on Mantis that run on WAMP 2.4 through Gmail SMTP server, always unable to send email. Have a further investigation, discovered that I need to turn on php_openssl in my WAMP PHP extensions. When turn on the php_openssl extension, encounter the error as shown in the log file.
    [Mon Sep 09 14:57:33.670249 2013] [mpm_winnt:notice] [pid 1544:tid 352] AH00418: Parent: Created child process 2280
    [Mon Sep 09 14:57:34.174249 2013] [ssl:warn] [pid 2280:tid 244] AH01882: Init: this version of mod_ssl was compiled against a newer library (OpenSSL 1.0.1e 11 Feb 2013, version currently loaded is OpenSSL 1.0.1d 5 Feb 2013) - may result in undefined or erroneous behavior
    [Mon Sep 09 14:57:34.909049 2013] [ssl:warn] [pid 2280:tid 244] AH01882: Init: this version of mod_ssl was compiled against a newer library (OpenSSL 1.0.1e 11 Feb 2013, version currently loaded is OpenSSL 1.0.1d 5 Feb 2013) - may result in undefined or erroneous behavior
    [Mon Sep 09 14:57:35.824849 2013] [ssl:warn] [pid 2280:tid 244] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
    From the error log, seems like OpenSSL version is not correct and I found out the hyperlink as described below to explain steps to upgrade the OpenSSL version.

    http://stackoverflow.com/questions/17354788/enabling-openssl-in-wamp

    Once the OpenSSL version is upgraded to version OpenSSL 1.0.1e, I am able to turn on php_openssl in my WAMP PHP extensions and finally email notification is working in my Mantis installation.

    How to turn on LDAP authentication on Mantis?

    To turn on the LDAP authentication on Mantis that normally required by corporate users, below are some tips on how to achieve it.

    Steps to resolve

    1. Open config_defaults_inc.php, edit the parameters as described below:
    /**
    * login method
    * MD5, LDAP, BASIC_AUTH or HTTP_AUTH.
    * Note: you may not be able to easily switch encryption methods, so this
    * should be carefully chosen at install time. However, MantisBT will attempt
    * to "fall back" to older methods if possible.
    * @global int $g_login_method
    */
    $g_login_method = LDAP;
    
    //Examples, ldap://ldap.example.com:389
    $g_ldap_server = 'ldap://[LDAP_SERVER]:389';
    
    
    //Examples, dc=employee,dc=it,dc=departmentname,dc=companyname
    //Note: Please use the most exact DN instead of global DN. Otherwise,
    //Mantis will keep throwing empty response and the application will always 
    //show empty page
    $g_ldap_root_dn = '[LDAP_DN_PARAMETER]';
    
    //Use sAMAccountName for Active Directory
    $g_ldap_uid_field = 'sAMAccountName';
    
    /**
    * The distinguished of the user account to use for binding to the LDAP server.
    * For example, 'CN=ldap,OU=Administrators,DC=example,DC=com'.
    *
    * @global string $g_ldap_bind_dn
    */
    $g_ldap_bind_dn = '[DOMAIN_NAME]\[USERNAME]';
    
    /**
    * The password for the service account to be used for connecting to the LDAP server.
    *
    * @global string $g_ldap_bind_passwd
    */
    $g_ldap_bind_passwd = '[PASSWORD]';
    
    /**
    * Should we send to the LDAP email address or what MySql tells us
    * @global int $g_use_ldap_email
    */
    $g_use_ldap_email = ON;
    
    /**
    * The LDAP Protocol Version, if 0, then the protocol version is not set.  For Active Directory use version 3.
    *
    * @global int $g_ldap_protocol_version
    */
    $g_ldap_protocol_version = 3;
    

    How to turn on debug message in Mantis for LDAP troubleshooting?

    To turn on the debug message for LDAP troubleshooting, below are the steps and configuration that are required

    Steps to resolve
    1. Open php.ini which is located at "[WAMP_INSTALL_PATH]\bin\apache\Apache2.4.4\bin".
    2. Uncomment 'error_log = "[WAMP_INSTALL_PATH]/logs/php_error.log"'
    3. Open config_defaults_inc.php in Mantis, change the value of g_log_level to LOG_LDAP
    $g_log_level = LOG_LDAP;
    Restart your WAMP server, LDAP log will be available at [WAMP_INSTALL_PATH]\logs\php_error.log.

    How to reset your mysql user account password through command line?

    Open your mysql browser, type in the command as displayed below

    UPDATE mysql.user SET Password=PASSWORD('[MyNewPass]') WHERE User='root';
    FLUSH PRIVILEGES;
    
    Relogin again.