最新 分享

Publish our news and thoughts with all.

Popular Articles

Recent Stories

在Linux服务器(ubuntu)上使用Apache为odoo openerp配置域名

Odoo is very well known ERP system today. Odoo 9 provides great features that will help to grow business. By default odoo runs over port 8069. So we are accessing server using domain:8069. What if we need to access server using only domain like a standard website? We can do it by configuring web server with odoo. Here I am going to show you configuration of Apache web server for odoo.
Before configuring apache with odoo, first check whether apache web server is installed on your machine or not. If not installed then execute below command to installed it.
sudo apt-get updatesudo apt-get install apache2
After installing apache on your machine, you need to enable some modes by executing below commands.
sudo a2enmod proxy proxy_http
Now go to the directory, “/etc/apache2/sites-available” and create a file with <domain-name>.conf.  Here I am going to use “openerp.iplantoo.com” domain for my odoo server. So the file name will be “demo.surekhatech.conf”. Add the below content into this file.
<VirtualHost *:80>    ServerName openerp.iplantoo.com    ServerAlias openerp.iplantoo.com    LogLevel warn    ErrorLog /var/log/apache2/openerp.iplantoo.com.error.log    CustomLog /var/log/apache2/openerp.iplantoo.com.access.log combined    ProxyPass / http://localhost:8069/    ProxyPassReverse / http://localhost:8069/</VirtualHost>
After adding the virtual host for odoo server, you need to enable site using the following command.
sudo a2ensite openerp.iplantoo.com.conf
A message will appear showing that site is enabled. After that you need to restart the apache server by executing below command.
sudo service apache2 restart
Make the host file entry in case you have made the configuration on the local machine. Open the “hosts” file by executing below command:
sudo nano /etc/hosts
Add the following entry into this file.
127.0.0.1 openerp.iplantoo.com
After completing with above configuration, you can access the odoo server by hitting the “openerp.iplantoo.com” in any browser. You can see that the odoo server is running over the “http”. But what if we need to run our odoo server over more secure channel i.e. “https”.
For that you need SSL certificate and key. You can buy the certificate from any trusted vendor. You can also generate certificates and used it. Certificate can be generated using the openssl toolkit. For linux machine you can generate certificate by using the following commands.
To generate key:
openssl genrsa -out openerp.iplantoo.com.key 2048
To generate Certificate:
openssl req -new -x509 -key openerp.iplantoo.com.key -out openerp.iplantoo.com.cert -days 3650-subj /CN=openerp.iplantoo.com
Once you have SSL key and certificate, you need to update the existing virtual host to run odoo server over “https”. Before that first enable the apache SSL mode by executing below command.
sudo a2enmod ssl
Now open “demo.surekhatech.conf” file from the “/etc/apache2/sites-available” and update the virtual host with the below contents.
<VirtualHost *:80>     ServerName openerp.iplantoo.com     ServerAlias openerp.iplantoo.com     Redirect / https://openerp.iplantoo.com/</VirtualHost><VirtualHost *:443>     ServerName openerp.iplantoo.com     ServerAlias openerp.iplantoo.com     LogLevel warn     ErrorLog /var/log/apache2/openerp.iplantoo.com.error.log     CustomLog /var/log/apache2/openerp.iplantoo.com.access.log combined     SSLEngine on     SSLProxyEngine on     SSLCertificateFile /etc/apache2/ssl/openerp.iplantoo.com.cert     SSLCertificateKeyFile /etc/apache2/ssl/openerp.iplantoo.com.key     ProxyPreserveHost On     ProxyPass / http://localhost:8069/ retry=0     ProxyPassReverse / http://localhost:8069/</VirtualHost>
Here we have added the path for the SSL certificate and key file. Create a directory with “ssl” name on “/etc/apache2” location. Copy the SSL certificate and key files into “/etc/apache2/ssl” directory.
Now restart the apache web server using the following command.
sudo service apache2 restart
Open any browser and hit the url “openerp.iplantoo.com”. You can see that it will automatically redirect your odoo server over “https”, a more secure channel. Any request to your odoo server will be serve over the “https”.
For more implementation details or support you may contact us at This email address is being protected from spambots. You need JavaScript enabled to view it..

安装odoo openerp时出现python setup.py egg_info

由于用homebrew安装了python2和python3,在运行pip install -r requirement.txt时出现以下错误:

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/xr/zpv3lqzs50n6v78nv4dmnhjm0000gn/T/pip-build-nfmxgoei/jcconv/

排查了很久发现:requirement.txt中涉及的模块有些在python3中不支持,需要用python2安装,所以使用的命令是:pip2 install -r requirement.txt

在MacOS下同时安装Python 2 和 3,并设置默认使用的版本

#Python 命令

  • 系统默认使用python2,使用brew可安装python3
  • python --version:查看python2版本
  • which python:查看python安装路径
  • 设置路径$path:
    • echo $PATH
    • vi /etc/paths
  • vi ~/.bash_profile
    • If you wish to have this formula's python executable in your PATH then addthe following to ~/.bash_profile:export PATH="/usr/local/opt/python/libexec/bin:$PATH"
    • 保存,source ~/.bash_profile
    • new 一个终端窗口才能看到调整后的结果

MacOS下 homebrew update 失败,提示路径不可写

运行 brew update 之后,提示:

You should probably change the ownership and permissions of /usr/local

back to your user account.

sudo chown -R $(whoami):admin /usr/local

发现:macOS 10.13 High Sierra 之后 /usr/local 路径不允许修改权限解决方案:Uninstall Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"Then re-install it:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
 

MAMP 选择php版本

MAMP默认控制面板只能选择2个php版本,如果要设置更低(更老)的版本,可以采用以下方法MAMP automatically rewrites the following line in your /Applications/MAMP/conf/apache/httpd.conf file when it restarts based on the settings in preferences. You can comment out this line and add the second one to the end of your file:

# Comment this out just under all the modules loaded# LoadModule php5_module /Applications/MAMP/bin/php/php5.x.x/modules/libphp5.so
At the bottom of the httpd.conf file, you'll see where additional configurations are loaded from the extra folder. Add this to the bottom of the httpd.conf file
# PHP Version ChangeInclude /Applications/MAMP/conf/apache/extra/httpd-php.conf
Then create a new file here: /Applications/MAMP/conf/apache/extra/httpd-php.conf
# Uncomment the version of PHP you want to run with MAMP# LoadModule php5_module /Applications/MAMP/bin/php/php5.2.17/modules/libphp5.so# LoadModule php5_module /Applications/MAMP/bin/php/php5.3.27/modules/libphp5.so# LoadModule php5_module /Applications/MAMP/bin/php/php5.4.19/modules/libphp5.soLoadModule php5_module /Applications/MAMP/bin/php/php5.5.3/modules/libphp5.so
After you have this setup, just uncomment the version of PHP you want to use and restart the servers!

小程序如何生成带参数二维码?

许多小程序开发者,都需要获取进入小程序不同页面的二维码:包括常见的四方形「QR 码」和新推出的「小程序码」。
这时候,我们直接在小程序后台中获取到的二维码,就远远无法满足我们以上需求了。贴心的是,微信提供了「获取小程序二维码」的接口
通过这个接口,商家和开发者能够制作进入不同页面的小程序二维码,而不会限定扫码进入小程序主页
下面,就以「鲜花日记」小程序的某个详情页为例,展示这个接口的使用方法。

准备工作

首先,我们需要确保在小程序的 app.json 代码中,已经注册了相应的页面
在本例的设定中,我们就需要在 pages 里,将 pages/detail/ 这个页面注册进去。
"pages":[  "pages/index/index",  "pages/detail/detail"]
当然,相应目录下也需要有相应的页面文件,且你的小程序已经有已发布的线上版本。否则,用户扫码后,微信会提示出错。
接下来,我们需要到微信小程序后台,获取小程序的 AppSecret(如果已经获取,这一步可以跳过)。
进入小程序后台,点击左侧「设置」,找到「开发设置」,我们就能找到 AppSecret 一项。点击「获取」或「重置」,扫码之后,网页就会显示新的 AppSecret。
需要注意的是,如果你之前生成过新的 AppSecret,那么旧的 AppSecret 会随这个操作而失效。开发者也需要记得妥善保管 AppSecret,尽可能保证 AppSecret 不会丢失、泄漏。

获取二维码

有了小程序的 AppID 和 AppSecret,我们就能利用服务器,获取小程序的二维码了。
在本例,我们通过模拟请求的方式,让大家了解这个接口的使用方法和原理。
首先,我们要利用 AppID 和 AppSecret,获取 Access Token
这一步,我们请求的地址是 https://api.weixin.qq.com/cgi-bin/token,你需要使用 GET 方法,传递你的 AppID 和 AppSecret。
从结果中,我们可以得知:执行这个操作后,微信会给你返回一个 JSON 数据包。解析这个数据包,我们就可以获得 Access Token。
有了 Access Token,我们就可以获取不同的小程序二维码了。
微信提供了两个 POST 获取小程序二维码的接口。你可以根据你的业务需求,自由选择任一接口,获取相应的小程序二维码(GET 参数中的 ACCESS_TOKEN 部分填入上一步我们获取到的 Access Token)。
  • 获取最新的「菊花式」小程序码,可以使用这个接口:https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN
  • 想要经典的「狗皮膏药式」QR 码,可以使用这个接口:https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN
POST 请求体中,需要包含小程序的页面地址,以及传入小程序的参数。记住,这个页面必须要在小程序里的 app.json 进行注册。
本例中,JSON 请求体如下:
{"path": "pages/detail/detail?id=1"}
发送请求后,微信会直接返回一张制作好的「小程序码」。现在,扫一扫这张小程序码,看看是不是到了指定页面了?

注意事项

除了我们文中举例的接口,微信还开放了另一个与二维码相关的接口,就是「扫普通二维码进入小程序」
通过这个接口,开发者自己就可以按照一定规律,自行批量生成 QR 码。但它需要开发者有已经备案的域名,且个人主体小程序无法使用这个接口。
微信将通过「获取小程序二维码」接口获取的二维码的数量限定在十万个,并且似乎并没有「注销以前生成的二维码」的功能和机制。
所以,如果你有非常大量的小程序二维码生成需求,建议使用普通链接二维码的方式生成 QR 码。如果需要使用微信提供的二维码生成接口,也要注意不要超过限额。