Posts

How to fix error : no module named sendgrid when try to use sendgrid python lib in PHP.

Image
"no module named sendgrid" error reported with below codes: <?php system("/usr/bin/python sendmail.py 2>&1"); system("/usr/bin/python --version 2>&1", $ret); ?> sendmail.py import sendgrid import os from sendgrid.helpers.mail import * sg = sendgrid.SendGridAPIClient( apikey = os.environ.get( ' SENDGRID_API_KEY ' )) from_email = Email( " test@example.com " ) to_email = Email( " test@example.com " ) subject = " Sending with SendGrid is Fun " content = Content( " text/plain " , " and easy to do anywhere, even with Python " ) mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post( request_body = mail.get()) print (response.status_code) print (response.body) print (response.headers) ....

nginx config your websites' favicon

Image
        1. vim nginx.conf         # set site favicon         location /favicon.ico {             root html;         }        2. place a favicon.ico file under html/        3. optional, add below codes to your index.html. <link rel="icon" href="/favicon.ico" mce_href="/favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="/favicon.ico" mce_href="/favicon.ico" type="image/x-icon">     # set site favicon location /favicon.ico { root html; }

How to extend file extensions to be parsed by PHP

Image
sudo vim /etc/php/7.0/fpm/pool.d/www.confsudo vim /etc/php/7.0/fpm/pool.d/www.conf By default, PHP only parse files with .php extension. We can extend extensions with security.limit_extensions directive. sudo vim /etc/php/7.0/fpm/pool.d/www.conf sudo vim /etc/php/7.0/fpm/pool.d/www.conf ; Limits the extensions of the main script FPM will allow to parse. This can ; prevent configuration mistakes on the web server side. You should only limit ; FPM to .php extensions to prevent malicious users to use other extensions to ; exectute php code. ; Note: set an empty value to allow all extensions. ; Default Value: .php ; You can add any extensions you want to be parsed as php security.limit_extensions = .php .php3 .php4 .php5 .php7 .ler sudo service php7.0-fpm restart Config nginx: /etc/nginx/nginx.conf         location ~ \.(php |ler )$ {             include fastcgi.conf;             fastcgi_pass   unix:/run/php/php7.0-fpm.sock;         } location ~ \.(php|ler)$ { r

How to set up LNMP(linux+nginx+mysql+php) developer tool on your ubuntu server

Image
Install all software: sudo apt-get install nginx sudo apt-get install php7.0-fpm sudo apt-get install php7.0-curl sudo apt-get install php7.0-gd php7.0-mcrypt php7.0-mysql sudo apt-get install mysql-server mysql-client Please remember your mysql database root password!!! Let's config up. 1. Add nginx user and group, nginx server and php-fpm will run as nginx user. sudo groupadd nginx sudo groupadd nginx sudo useradd -g nginx nginx sudo service php7.0-fpm restart 2. Config php-fpm /etc/php/7.0/fpm/php.ini cgi.fix_pathinfo=0 /etc/php/7.0/fpm/pool.d/www.conf listen = /run/php/php7.0-fpm.sock listen.owner = nginx listen.group = nginx sudo service php7.0-fpm restart 3. Config nginx /etc/nginx/nginx.conf user nginx nginx ; location ~ \.php$ {     include fastcgi.conf;     fastcgi_pass   unix:/run/php/php7.0-fpm.sock; } sudo service nginx restart PS:keep the user/group of php-fpm same as nginx server, I have marked as blue nginx above. And it should not the same user tha

Send email with attachments on your google compute engine via sendgrid-python

Image
precondition: Use the Google Cloud Launcher to sign up for the SendGrid Email service. Make a note of your SendGrid SMTP account credentials, which include username, password, and hostname. Your SMTP username and password are the same as what you used to sign up for the service. The SendGrid hostname is smtp.sendgrid.net. Create an API key: Sign in to Sendgrid and go to Settings > API Keys . Create an API key. Select the permissions for the key. At a minimum, the key will need Mail send permissions to send email. Click Save to create the key. SendGrid generates a new key. This is the only copy of the key so make sure to copy the key and save it for later.   Please remember your key and save it somewhere safe.   OK. Now we can use sendgrid python library to send email. Of cause, you can still follow offical help to use sendgrid with other solution. https://cloud.google.com/compute/docs/tutorials/sending-m

神先爱了我们

Image
当那日,我必为我的民,与田野的走兽和空中的飞鸟,并地上的昆虫立约;又必在国中折断弓刀,止息争战,使他们安然躺卧。  (何西阿书 2:18 和合本) In that day I will make a covenant for them with the beasts of the field, the birds in the sky and the creatures that move along the ground. Bow and sword and battle I will abolish from the land, so that all may lie down in safety.  (Hosea 2:18 NIV) 我必聘你永远归我为妻,以仁义、公平、慈爱、怜悯聘你归我;  (何西阿书 2:19 和合本) I will betroth you to me forever; I will betroth you in righteousness and justice, in love and compassion.  (Hosea 2:19 NIV) 也以诚实聘你归我,你就必认识我—耶和华。 (何西阿书 2:20 和合本) I will betroth you in faithfulness, and you will acknowledge the Lord .  (Hosea 2:20 NIV) 耶和华说:那日我必应允,我必应允天,天必应允地; (何西阿书 2:21 和合本) “In that day I will respond,” declares the Lord — “I will respond to the skies, and they will respond to the earth;  (Hosea 2:21 NIV) 地必应允五谷、新酒,和油,这些必应允耶斯列民(耶斯列就是 神栽种的意思) 。 (何西阿书 2:22 和合本) and the earth will respond to the grain, the new wine and the olive oil, and they will respond to Jezreel.  (Hosea 2:22 NIV) 我必将她种在这地。素不

The best way to force http request redirect to https in nginx

Image
Use 301 redirect.   server { listen 80; server_name blog.errong.win; return 301 https://$server_name$request_uri; } server { listen 80; server_name freevpn.errong.win; return 301 https://$server_name$request_uri; } server { listen 80; server_name www.errong.win errong.win; return 301 https://$server_name$request_uri; } server { listen 443 ssl; ssl_certificate /etc/letsencrypt/live/errong.win/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/errong.win/privkey.pem; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; server_name ~^(.+)?\.errong\.win$; #charset koi8-r; #access_log logs/host.access.log main; location / { root vhosts/$1; index index.html index.htm;