If you got 500 (Internal Server Error) PHP/Nginx/Apache – Where you can found logs/reason?

Oh, noooo. You got most popular developer error 🙂
Firstly, No despair – say “Yes, I CAN”, and concentrate on possible errors.

1 step: Double check your PHP/Python/ETC code.
find_errors_ercule
Show all errors (how to show all errors/warnings/nootices in php)
Also, you can do “fast debug” in main parts of you code (Sure, use die() command but very carefully)

 

2 step: Check server/Apache&PHP settings
domino_server_settings_phpFirstly check .htaccess file on strange symbols or sentences.
Also, if you using POST method with uploading files then check php settings in php.ini (max_post_size, max_executing_time…)

 

3 step: Check error logs (Ubuntu/Linux)
find_errors_in_logs
Standard Apache logs dev finiding here:

/var/log/apache2/...

nginx logs here:

/var/log/nginx/...

Also, some popular frameworks logs folders:
Continue reading If you got 500 (Internal Server Error) PHP/Nginx/Apache – Where you can found logs/reason?

How to get Swift Mailer Delivery/Failures/Errors Status when you sending emails

Example of send email method with using Swift_Mailer (Swift_SmtpTransport, Swift_Message)
If you want get Delivery/Failures/Errors Status you can use this construction:

 /**
     * Method for sending emails via Swift_Mailer
     * @param $email - object
     * example $email = \new StdClass();
     * $email->login = 'sender@mail.example';
     * $email->password = 'password_of_sender_email';
     * $email->host = 'imap.gmail.com'; //real example for Gmail
     * $email->first_name = 'Test Example Name';
     * $email->to = 'reciepient@mail.example'; //or array ['reciepient1@mail.example','reciepient2@mail.example','reciepient3@mail.example']
     * $email->subject = 'Example of subject';
     * $email->body = 'Example of <br/> email body message';
     * @return boolean
     */
    public static function sendEmail($email)
    {
        $isSent = $failures = false;
        try {
            $transport = \Swift_SmtpTransport::newInstance()->setHost($email->host)->setPort(465)->setUsername($email->login)->setPassword($email->password)->setEncryption('ssl');

            $mailMessage = \Swift_Message::newInstance()->setFrom([$email->login => $email->first_name])->setReturnPath($email->to)->setTo($email->to)->setSubject($email->subject)->setBody($email->body, 'text/html');

            $mailer = \Swift_Mailer::newInstance($transport);

            if ($mailer->send($mailMessage, $failures)) {
                $isSent = true;
                echo ' SUCCESS SENDING!:' . $email->login . ' to ' . $email->to;
            } else {
                echo ' SENDING ERROR TO :' . print_R($failures);
            }
        } catch (\Exception $e) {
            echo 'Catch Error with ' . $email->login . ' : ' . $e->getErrorMessage() . "\n";
        }
        return $isSent;
    }

swift_SmtpTransport / Swift_Message /Swift_Mailer

Fix Twilio SSL error. Services_Twilio_TinyHttpException SSL certificate problem

If you get on local yii site this error:
Services_Twilio_TinyHttpException
SSL certificate problem: self signed certificate in certificate chain

You can fix it in this file:
\vendor\twilio\sdk\Services\Twilio\TinyHttp.php
Just find and add this parameter CURLOPT_SSL_VERIFYPEER => FALSE for CURL connection:

$opts = $this->curlopts + array(
      CURLOPT_URL => $url,
      CURLOPT_HEADER => TRUE,
      CURLOPT_RETURNTRANSFER => TRUE,
      CURLOPT_INFILESIZE => -1,
      CURLOPT_POSTFIELDS => NULL,
      CURLOPT_TIMEOUT => 60,
      CURLOPT_SSL_VERIFYPEER => FALSE
    );

Thats all. Happy SMSing…

How to display/hide strict/all errors in php?

If you need to display all php errors on the web-page before production, you can use it settings
For display ALL errors/notices/warnings/deprecated info:
If you have access to php.ini then you can change 2 params.
Example (in php.ini) ↓

error_reporting = E_ALL
display_errors = On

Often, you need to check a separate part of functional and you don’t want display errors on the all site.
In this way, you can insert 2 lines in your php file with debug functional.
Example ↓

//Show all errors, notices
error_reporting(E_ALL);
ini_set('display_errors', 1);

Note: Display errors could be turned off in the php.ini or your Apache config file.
Continue reading How to display/hide strict/all errors in php?