tag:blogger.com,1999:blog-75866952024-03-05T15:59:51.550+08:00Vagrant Dog - HarryWho are you? Where are you from? Where do you want to go?Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.comBlogger326125tag:blogger.com,1999:blog-7586695.post-42517150137822947572018-11-09T13:21:00.001+08:002018-11-09T13:21:12.617+08:00Prepare to swith to other alternatives <h4 class="media-heading" style="background-color: #f9f9f9; box-sizing: border-box; color: #21272b; font-family: Montserrat, sans-serif; font-size: 19px; font-weight: 400; line-height: 1.1; margin-bottom: 5px; margin-top: 0px;">
<br /></h4>
<div>
Odoo 12 Community Edition removed accounting module. Without accounting module, it become useless. Most importantly, can foresee more and more core modules will be moved to enterprise edition. </div>
<div>
<br /></div>
<div>
Sooner or later, we have to switch to other alternatives. </div>
<div>
<br /></div>
<div>
Do some study first. Will keep track of the movement and decide.</div>
<div>
<br /></div>
<div>
Odoo</div>
<div>
ERPNext</div>
<div>
Flectra</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
https://www.odoo.com/groups/community-59/community-32937746?mode=thread&date_begin=&date_end=</div>
<div>
<br /></div>
<div>
https://discuss.erpnext.com/t/odoo-vs-erpnext-sept-2017/28391/6</div>
<h4 class="media-heading" style="background-color: #f9f9f9; box-sizing: border-box; color: #21272b; font-family: Montserrat, sans-serif; font-size: 19px; font-weight: 400; line-height: 1.1; margin-bottom: 5px; margin-top: 0px;">
<br /></h4>
<h4 class="media-heading" style="background-color: #f9f9f9; box-sizing: border-box; color: #21272b; font-family: Montserrat, sans-serif; font-size: 19px; font-weight: 400; line-height: 1.1; margin-bottom: 5px; margin-top: 0px;">
Re: odoo vs. ERPNext</h4>
<small style="background-color: #f9f9f9; box-sizing: border-box; color: #282f33; font-family: "Open Sans", sans-serif; font-size: 12.9px;">by <span data-oe-contact-options="{"translate": false, "fields": ["name"], "type": "contact", "widget": "contact", "tagName": "span", "inherit_branding": null, "expression": "message.author_id"}" data-oe-many2one-id="617680" data-oe-many2one-model="res.partner" style="box-sizing: border-box; display: inline-block;"></span></small><br />
<address class="mb0" itemscope="itemscope" itemtype="http://schema.org/Organization" style="box-sizing: border-box; font-style: normal; line-height: 1.7; margin-bottom: 0px !important;">
<div style="box-sizing: border-box;">
<span itemprop="name" style="box-sizing: border-box;">Fabien Bourgeois</span></div>
<div itemprop="address" itemscope="itemscope" itemtype="http://schema.org/PostalAddress" style="box-sizing: border-box;">
</div>
<div style="box-sizing: border-box;">
</div>
</address>
<small style="background-color: #f9f9f9; box-sizing: border-box; color: #282f33; font-family: "Open Sans", sans-serif; font-size: 12.9px;"><span data-oe-contact-options="{"translate": false, "fields": ["name"], "type": "contact", "widget": "contact", "tagName": "span", "inherit_branding": null, "expression": "message.author_id"}" data-oe-many2one-id="617680" data-oe-many2one-model="res.partner" style="box-sizing: border-box; display: inline-block;"></span> - <span class="fa fa-calendar" style="-webkit-font-smoothing: antialiased; box-sizing: border-box; display: inline-block; font-family: FontAwesome; font-size: inherit; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 1; text-rendering: auto;"></span> <span data-oe-original="2017-09-19 05:22:04" style="box-sizing: border-box;">09/19/2017 05:22:04</span></small><span style="background-color: #f9f9f9; color: #282f33; font-family: "Open Sans", sans-serif; font-size: 15px;"></span><br />
<div style="background-color: #f9f9f9; box-sizing: border-box; color: #282f33; font-family: "Open Sans", sans-serif; font-size: 15px;">
<div style="box-sizing: border-box;">
Le 18/09/2017 à 14:25, Andreas Becker a écrit :</div>
<blockquote cite="mid:CAEJSRZvt9tqt6aC4cb-576qt6wmUFffQ6VkJP9a0KOOMPDixtA@mail.gmail.com" data-o-mail-quote="1" style="border-left: 3px solid rgb(220, 221, 222); box-sizing: border-box; margin: 0px 0px 25px; padding: 12.5px 25px;" type="cite">
<div dir="ltr" style="box-sizing: border-box;">
The CEO of Frappe brought an interesting input:<br style="box-sizing: border-box;" /><a href="https://discuss.erpnext.com/t/odoo-vs-erpnext-sept-2017/28391/4" style="box-sizing: border-box; color: #875a7b; font-weight: 600; text-decoration-line: none;">https://discuss.erpnext.com/t/odoo-vs-erpnext-sept-2017/28391/4</a></div>
</blockquote>
<br style="box-sizing: border-box;" />I have tried to summarize differences I see between the two solutions : <br style="box-sizing: border-box;" /><a href="https://discuss.erpnext.com/t/odoo-vs-erpnext-sept-2017/28391/5?u=yakulu" style="background-color: transparent; box-sizing: border-box; color: #875a7b; font-weight: 600; text-decoration-line: none;">https://discuss.erpnext.com/t/odoo-vs-erpnext-sept-2017/28391/5</a><br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" />Quick copy-paste here for archiving :<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" />I currently test the solution and the Frappé framework but I haven’t finished yet. So my analysis may be partial and not scientific… Please correct me if I’m wrong. To me, there a many little differences between these two open source ERP :<ol style="box-sizing: border-box; margin-bottom: 12.5px; margin-top: 0px;">
<li style="box-sizing: border-box;"><div style="box-sizing: border-box;">
<strong style="box-sizing: border-box;">Release model</strong></div>
<ul style="box-sizing: border-box; margin-bottom: 0px; margin-top: 0px;">
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">ERPNext</strong> has a <em style="box-sizing: border-box;">rolling</em>-release model and includes migration scripts. Therefore you always benefit from latest enhancements and features but you need to ensure that your customizations stays in line with master and features can change from one day to another.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">Odoo</strong> has a more classical release plan : each version is supported for three years and only bugfixes seems to be allowed in a stable versions. That said, no migration script is provided (<a href="https://github.com/OCA/OpenUpgrade" rel="nofollow
noopener" style="background-color: transparent; box-sizing: border-box; color: #875a7b; font-weight: 600; text-decoration-line: none;">OCA OpenUpgrade</a> project tries to handle this) and each major version needs an huge migration to be planned.</li>
</ul>
</li>
<li style="box-sizing: border-box;"><div style="box-sizing: border-box;">
<strong style="box-sizing: border-box;">Architecture</strong> : as already said, ERPNext goes to include many features, verticals too (already healthcare and education ones), that may be hidden after by customization. Goods points : coherence, quality and maintenance. On Odoo side, everything is very modular and you may only install contact management or project management on your database. But this can lead to fragmentation and testing complexities.</div>
</li>
<li style="box-sizing: border-box;"><div style="box-sizing: border-box;">
<strong style="box-sizing: border-box;">Community and manpower</strong> : Odoo SA employs dozens of people on Odoo. <a href="https://odoo-community.org/" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #875a7b; font-weight: 600; text-decoration-line: none;">OCA</a> and community is composed by hundreds of contributors. There are many (thousands) of modules existing. Frappé / ERPNext community is smaller, but growing.</div>
</li>
<li style="box-sizing: border-box;"><div style="box-sizing: border-box;">
<strong style="box-sizing: border-box;">Features</strong></div>
<ul style="box-sizing: border-box; margin-bottom: 0px; margin-top: 0px;">
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">ERPNext</strong> seems to offer more out-of-the-box than Odoo, especially in comparison to recent Odoo CE versions : contract / subscriptions, Gantt views, file management…</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">Odoo</strong>, with OCA repositories and other community modules, has a very large feature coverage and many of missing parts are filled that way. Out of the box, Odoo has more community oriented modules : surveys, forums, alternative to slack, mailing lists, slides (alternative to slideshare and youtube)…</li>
</ul>
</li>
<li style="box-sizing: border-box;"><div style="box-sizing: border-box;">
<strong style="box-sizing: border-box;">Framework</strong></div>
<ul style="box-sizing: border-box; margin-bottom: 0px; margin-top: 0px;">
<li style="box-sizing: border-box;">The <strong style="box-sizing: border-box;">Odoo</strong> framework needs a lot of Python and XML and a few JavaScript. The templating engine is QWeb, using XML attributes. It’s a productive business framework with includes many useful things, like good research and regroupments abilities, pivot table, charts, many views per model… Graphical customization is very limited and technical in CE version (in EE /closed source version, you have Odoo Studio…). Odoo v10 CE has no responsive backend theme nor mobile application by default (only frontend / website is responsive). The API is XML or JSON-RPC.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">Frappé framework</strong> is more balanced between Python and JavaScript. It uses JSON massively but you don’t write it directly. Frappé is the popular Jinja templating engine on Python side. Frappé includes many graphical customizations. It can finished technical but less than Odoo CE offering. Frappé has good options for own reporting and PDF drag&drop personalization. It also offer Web Forms, realtime, universal command bar… Frappé is mobile focused with responsive backend and have open source mobile applications. The API is REST + optional RPC.</li>
</ul>
</li>
<li style="box-sizing: border-box;"><div style="box-sizing: border-box;">
<strong style="box-sizing: border-box;">Governance</strong> (last but not least)</div>
<ul style="box-sizing: border-box; margin-bottom: 0px; margin-top: 0px;">
<li style="box-sizing: border-box;"><div style="box-sizing: border-box;">
<strong style="box-sizing: border-box;">Odoo</strong> is leaded by a company. Roadmap is not public and you can have surprises a few days before each new version. Odoo SA sells SaaS and services like implementation / development. It provides a partner program. Since 2015 and Odoo v9, there is an open source edition, Odoo CE and an enterprise proprietary edition, Odoo EE (that is Odoo CE + extra closed source modules). Migration code between major version is not open source, for many tears. OCA, Odoo Community Association, is a swiss non-profit foundation which coordinates open source community development, events… and manages quality software that enhances Odoo CE, add new features etc.</div>
</li>
<li style="box-sizing: border-box;"><div style="box-sizing: border-box;">
<strong style="box-sizing: border-box;">ERPNext</strong> is now driven by a non profit Indian Foundation. Roadmap is public and openly debated. All the code is open source, migration scripts included. The foundation handles events, promotion… and has its own developers. Frappé Tech still dominates ERPNext work, as the foundation is young and the number of contributors still low (but growing). Frappé Tech mainly offer SaaS hosting and is not a direct competitor for service providers.</div>
</li>
</ul>
</li>
</ol>
<div style="box-sizing: border-box; margin-bottom: 12.5px;">
Hope this is useful and quite objective. Feel free to amend / debate.</div>
</div>
Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-30884463067176544482018-11-08T12:50:00.004+08:002018-11-08T12:50:58.651+08:00Install and Configure Postfix as a Send-Only SMTP Server on Ubuntu 14.04<h3 id="introduction" style="background-color: white; box-sizing: border-box; color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: 22px; letter-spacing: 0.005em; margin: 14px auto 11px; padding: 0px; width: 745px;">
<br /></h3>
<div>
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-14-04</div>
<h3 id="introduction" style="background-color: white; box-sizing: border-box; color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: 22px; letter-spacing: 0.005em; margin: 14px auto 11px; padding: 0px; width: 745px;">
Introduction</h3>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Postfix is an MTA (Mail Transfer Agent), an application used to send and receive email. In this tutorial, we will install and configure Postfix so that it can be used to send emails by local applications only – that is, those installed on the same server that Postfix is installed on.</div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
<span style="box-sizing: border-box; font-weight: 600;">Why would you want to do that?</span></div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you're already using a third-party email provider for sending and receiving emails, you, of course, do not need to run your own mail server. However, if you manage a cloud server on which you have installed applications that need to send email notifications, running a local, send-only SMTP server is a good alternative to using a 3rd party email service provider or running a full-blown SMTP server.</div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
An example of an application that sends email notifications is OSSEC, which will send email alerts to any configured email address (see <a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ossec-security-notifications-on-ubuntu-14-04" style="border-bottom: 1px dotted rgb(0, 0, 0); box-sizing: border-box; color: black; text-decoration-line: none;">How To Install and Configure OSSEC Security Notifications on Ubuntu 14.04</a>). Though OSSEC or any other application of its kind can use a third-party email provider's SMTP server to send email alerts, it can also use a local (send-only) SMTP server.</div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
That's what you'll learn how to do in this tutorial: how to install and configure Postfix as a send-only SMTP server.</div>
<blockquote style="background-color: white; border-left: 4px solid rgba(0, 0, 0, 0.08); box-sizing: border-box; color: #666666; font-family: proxima-nova, sans-serif; font-size: 18px; margin: 0px auto 20px; padding: 0px 0px 0px 33px; width: 745px;">
<div style="box-sizing: border-box; margin-bottom: 22px; padding: 0px;">
<span style="box-sizing: border-box; font-weight: 600;">Note:</span> If your use case is to receive notifications from your server at a single address, emails being marked as spam is not a significant issue, since you can whitelist them.</div>
<div style="box-sizing: border-box; margin-bottom: 22px; padding: 0px;">
If your use case is to send emails to potential site users, such as confirmation emails for message board sign-ups, you should definitely do <span style="box-sizing: border-box; font-weight: 600;">Step 5</span> so your server's emails are more likely to be seen as legitimate. If you're still having problems with your server's emails being marked as spam, you will need to do further troubleshooting on your own.</div>
</blockquote>
<h3 id="prerequisites" style="background-color: white; box-sizing: border-box; color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: 22px; letter-spacing: 0.005em; margin: 14px auto 11px; padding: 0px; width: 745px;">
Prerequisites</h3>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Please complete the following prerequisites.</div>
<ul style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin: 0px auto 1.7rem; padding: 0px 0px 0px 2.5rem; width: 745px;">
<li style="box-sizing: border-box; list-style: disc outside none; margin: 0px 0px 0.8rem; padding: 0px 0px 0px 4px;">Ubuntu 14.04 Droplet</li>
<li style="box-sizing: border-box; list-style: disc outside none; margin: 0px 0px 0.8rem; padding: 0px 0px 0px 4px;">Go through the <a href="https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14-04" style="border-bottom: 1px dotted rgb(0, 0, 0); box-sizing: border-box; color: black; text-decoration-line: none;">initial setup</a>. That means you should have a standard user account with <code style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 15px; line-height: 22px; padding: 3px;">sudo</code>privileges</li>
<li style="box-sizing: border-box; list-style: disc outside none; margin: 0px 0px 0.8rem; padding: 0px 0px 0px 4px;">Have a valid domain name, like <span style="box-sizing: border-box; font-weight: 600;">example.com</span>, pointing to your Droplet</li>
<li style="box-sizing: border-box; list-style: disc outside none; margin: 0px 0px 0.8rem; padding: 0px 0px 0px 4px;">Your server's hostname should match this domain or subdomain. You can verify the server's hostname by typing <code style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 15px; line-height: 22px; padding: 3px;">hostname</code> at the command prompt. The output should match the name you gave the Droplet when it was being created, such as <span style="box-sizing: border-box; font-weight: 600;">example.com</span></li>
</ul>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If all the prerequisites have been met, you're now ready for the first step of this tutorial.</div>
<div data-unique="step-1-—-install-postfix" name="step-1-—-install-postfix" style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-left: auto; margin-right: auto; width: 745px;">
</div>
<h2 id="step-1-—-install-postfix" style="background-color: white; box-sizing: border-box; color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: 28px; font-weight: 400; letter-spacing: -0.5px; margin: 14px auto 10px; padding: 0px; width: 745px;">
Step 1 — Install Postfix</h2>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
In this step, you'll learn how to install Postfix. The most efficient way to install Postfix and other programs needed for testing email is to install the <code style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 15px; line-height: 22px; padding: 3px;">mailutils</code> package by typing:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;">sudo apt-get install mailutils
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Installing mailtuils will also cause Postfix to be installed, as well as a few other programs needed for Postfix to function. After typing that command, you will be presented with output that reads something like:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;">The following NEW packages will be installed:
guile-2.0-libs libgsasl7 libkyotocabinet16 libltdl7 liblzo2-2 libmailutils4 libmysqlclient18 libntlm0 libunistring0 mailutils mailutils-common mysql-common postfix ssl-cert
0 upgraded, 14 newly installed, 0 to remove and 3 not upgraded.
Need to get 5,481 kB of archives.
After this operation, 26.9 MB of additional disk space will be used.
Do you want to continue? [Y/n]
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Press ENTER to install them. Near the end of the installation process, you will be presented with a window that looks exactly like the one in the image below. The default option is <span style="box-sizing: border-box; font-weight: 600;">Internet Site</span>. That's the recommended option for this tutorial, so press TAB, then ENTER.</div>
<div class="growable" style="background-color: white; box-sizing: border-box; cursor: -webkit-zoom-in; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; position: relative; transition: width 0.25s linear 0s; width: 745px; z-index: 100;">
<img alt="Select Internet Site from the menu, then press TAB to select <Ok>, then ENTER" src="https://assets.digitalocean.com/articles/postfix_sendonly/1.png" style="border: 2px solid rgb(229, 229, 229); box-sizing: border-box; display: block; height: auto; margin-left: auto; margin-right: auto; max-width: 100%;" /></div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
After that, you'll get another window just like the one in this next image. The <span style="box-sizing: border-box; font-weight: 600;">System mail name</span> should be the same as the name you assigned to the Droplet when you were creating it. If it shows a subdomain like <span style="box-sizing: border-box; font-weight: 600;">mars.example.com</span>, change it to just <span style="box-sizing: border-box; font-weight: 600;">example.com</span>. When you're done, Press TAB, then ENTER.</div>
<div class="growable" style="background-color: white; box-sizing: border-box; cursor: -webkit-zoom-in; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; position: relative; transition: width 0.25s linear 0s; width: 745px; z-index: 100;">
<img alt="Enter your domain name, then press TAB to select <Ok>, ENTER" src="https://assets.digitalocean.com/articles/postfix_sendonly/2.png" style="border: 2px solid rgb(229, 229, 229); box-sizing: border-box; display: block; height: auto; margin-left: auto; margin-right: auto; max-width: 100%;" /></div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
After installation has completed successfully, proceed to Step 2.</div>
<div data-unique="step-2-—-configure-postfix" name="step-2-—-configure-postfix" style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-left: auto; margin-right: auto; width: 745px;">
</div>
<h2 id="step-2-—-configure-postfix" style="background-color: white; box-sizing: border-box; color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: 28px; font-weight: 400; letter-spacing: -0.5px; margin: 14px auto 10px; padding: 0px; width: 745px;">
Step 2 — Configure Postfix</h2>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
In this step, you'll read how to configure Postfix to process requests to send emails only from the server on which it is running, that is, from <span style="box-sizing: border-box; font-weight: 600;">localhost</span>. For that to happen, Postfix needs to be configured to listen only on the <em style="box-sizing: border-box;">loopback interface</em>, the virtual network interface that the server uses to communicate internally. To make the change, open the main Postfix configuration file using the nano editor.</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;">sudo nano /etc/postfix/main.cf
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
With the file open, scroll down until you see the entries shown in this code block.</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;">mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Change the line that reads <code style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 15px; line-height: 22px; padding: 3px;">inet_interfaces = all</code> to <code style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 15px; line-height: 22px; padding: 3px;">inet_interfaces = loopback-only</code>. When you're done, that same section of the file should now read:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;">mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849; display: inline;">loopback-only</span>
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
In place of <code style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 15px; line-height: 22px; padding: 3px;">loopback-only</code> you may also use <code style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 15px; line-height: 22px; padding: 3px;">localhost</code>, so that the modified section may also read:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;">mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849; display: inline;">localhost</span>
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
When you're done editing the file, save and close it (press CTRL+X, followed by pressing Y, then ENTER). After that, restart Postfix by typing:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;">sudo service postfix restart
</code></pre>
<div data-unique="step-3-—-test-that-the-smtp-server-can-send-emails" name="step-3-—-test-that-the-smtp-server-can-send-emails" style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-left: auto; margin-right: auto; width: 745px;">
</div>
<h2 id="step-3-—-test-that-the-smtp-server-can-send-emails" style="background-color: white; box-sizing: border-box; color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: 28px; font-weight: 400; letter-spacing: -0.5px; margin: 14px auto 10px; padding: 0px; width: 745px;">
Step 3 — Test That the SMTP Server Can Send Emails</h2>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
In this step, you'll read how to test whether Postfix can send emails to any external email account. You'll be using the <code style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 15px; line-height: 22px; padding: 3px;">mail</code> command, which is part of the <code style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 15px; line-height: 22px; padding: 3px;">mailutils</code> package that was installed in Step 1.</div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
To send a test email, type:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;">echo "This is the body of the email" | mail -s "This is the subject line" <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849; display: inline;">user@example.com</span>
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
In performing your own test(s), you may use the body and subject line text as-is, or change them to your liking. However, in place of <span style="box-sizing: border-box; font-weight: 600;"><span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;"><a href="mailto:user@example.com" style="border-bottom: 1px dotted rgb(0, 0, 0); box-sizing: border-box; color: black; text-decoration-line: none;">user@example.com</a></span></span>, use a valid email address, where the domain part can be <span style="box-sizing: border-box; font-weight: 600;">gmail.com</span>, <span style="box-sizing: border-box; font-weight: 600;">fastmail.com</span>, <span style="box-sizing: border-box; font-weight: 600;">yahoo.com</span>, or any other email service provider that you use.</div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Now check the email address where you sent the test message.</div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
You should see the message in your inbox. If not, check your spam folder.</div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
<span style="box-sizing: border-box; font-weight: 600;">Note:</span> With this configuration, the address in the <span style="box-sizing: border-box; font-weight: 600;">From</span> field for the test emails you send will be <span style="box-sizing: border-box; font-weight: 600;"><a href="mailto:sammy@example.com" style="border-bottom: 1px dotted rgb(0, 0, 0); box-sizing: border-box; color: black; text-decoration-line: none;">sammy@example.com</a></span>, where <span style="box-sizing: border-box; font-weight: 600;">sammy</span> is your Linux username and the domain part is the server's hostname. If you change your username, the <span style="box-sizing: border-box; font-weight: 600;">From</span> address will also change.</div>
<div data-unique="step-4-—-forward-system-mail" name="step-4-—-forward-system-mail" style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-left: auto; margin-right: auto; width: 745px;">
</div>
<h2 id="step-4-—-forward-system-mail" style="background-color: white; box-sizing: border-box; color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: 28px; font-weight: 400; letter-spacing: -0.5px; margin: 14px auto 10px; padding: 0px; width: 745px;">
Step 4 — Forward System Mail</h2>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
The last thing we want to set up is forwarding, so that you'll get emails sent to <span style="box-sizing: border-box; font-weight: 600;">root</span> on the system at your personal, external email address.</div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
To configure Postfix so that system-generated emails will be sent to your email address, you need to edit the <code style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 15px; line-height: 22px; padding: 3px;">/etc/aliases</code> file.</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;">sudo nano /etc/aliases
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
The full content of the file on a default installation of Ubuntu 14.04 is shown in this code block:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;"># See man 5 aliases for format
postmaster: root
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
With that setting, system generated emails are sent to the root user. What you want to do is edit it so that those emails are rerouted to your email address. To accomplish that, edit the file so that it reads:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;"># See man 5 aliases for format
postmaster: root
root: <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849; display: inline;">sammy@example.com</span>
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Replace <span style="box-sizing: border-box; font-weight: 600;"><a href="mailto:sammy@example.com" style="border-bottom: 1px dotted rgb(0, 0, 0); box-sizing: border-box; color: black; text-decoration-line: none;">sammy@example.com</a></span> with your personal email address. When done, save and close the file. For the change to take effect, run the following command:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;">sudo newaliases
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
You may now test that it works by sending an email to the root account using:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.05); border-radius: 3px; box-sizing: border-box; font-size: 14px; margin: 1rem auto; overflow-wrap: normal; overflow: auto !important; padding: 1rem; width: 745px;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; line-height: 22px; margin: 0px; padding: 0px;">echo "This is the body of the email" | mail -s "This is the subject line" root
</code></pre>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
You should receive the email at your email address. If not, check your spam folder.</div>
<h3 id="optional-step-5-—-protect-your-domain-from-spammers" style="background-color: white; box-sizing: border-box; color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: 22px; letter-spacing: 0.005em; margin: 14px auto 11px; padding: 0px; width: 745px;">
(Optional) Step 5 — Protect Your Domain from Spammers</h3>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
In this step, you'll be given links to articles to help you protect your domain from being used for spamming. This is an optional but highly recommended step, because if configured correctly, this makes it difficult to send spam with an address that appears to originate from your domain.</div>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Doing these additional configuration steps will also make it more likely for common mail providers to see emails from your server as legitimate, rather than marking them as spam.</div>
<ul style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin: 0px auto 1.7rem; padding: 0px 0px 0px 2.5rem; width: 745px;">
<li style="box-sizing: border-box; list-style: disc outside none; margin: 0px 0px 0.8rem; padding: 0px 0px 0px 4px;"><a href="https://www.digitalocean.com/community/tutorials/how-to-use-an-spf-record-to-prevent-spoofing-improve-e-mail-reliability" style="border-bottom: 1px dotted rgb(0, 0, 0); box-sizing: border-box; color: black; text-decoration-line: none;">How To use an SPF Record to Prevent Spoofing & Improve E-mail Reliability</a></li>
<li style="box-sizing: border-box; list-style: disc outside none; margin: 0px 0px 0.8rem; padding: 0px 0px 0px 4px;"><a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-dkim-with-postfix-on-debian-wheezy" style="border-bottom: 1px dotted rgb(0, 0, 0); box-sizing: border-box; color: black; text-decoration-line: none;">How To Install and Configure DKIM with Postfix on Debian Wheezy</a></li>
<li style="box-sizing: border-box; list-style: disc outside none; margin: 0px 0px 0.8rem; padding: 0px 0px 0px 4px;">Also, make sure the PTR record for your server matches the hostname being used by the mail server when it sends messages. At DigitalOcean, you can change your PTR record by changing your Droplet's name in the control panel</li>
</ul>
<div style="background-color: white; box-sizing: border-box; font-family: proxima-nova, sans-serif; font-size: 16px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Though the second article was written for Debian Wheezy, the same steps apply for Ubuntu 14.04.</div>
Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-85869372554987658592016-06-16T11:32:00.002+08:002016-06-16T11:32:56.965+08:00How To Serve Django Applications with uWSGI and Nginx on Ubuntu 16.04<div class="container tutorial-header" style="background-color: white; margin-bottom: 10px; margin-left: auto; margin-right: auto; width: 745px;">
<h1 class="content-title" style="margin: 0px 0px 10px; padding: 0px;">
<span style="color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: x-small;"><span style="font-weight: 300; line-height: 15.6px;">good guide.</span></span></h1>
<h1 class="content-title" style="margin: 0px 0px 10px; padding: 0px;">
<span style="color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: x-small;"><span style="font-weight: 300; line-height: 15.6px;">https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04</span></span></h1>
<div style="color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: 40px; font-weight: 300; letter-spacing: 0px; line-height: 1.2; margin: 0px 0px 10px; padding: 0px;">
<br /></div>
<h1 class="content-title" style="color: #3a3a3a; font-family: proxima-nova, sans-serif; font-size: 40px; font-weight: 300; letter-spacing: 0px; line-height: 1.2; margin: 0px 0px 10px; padding: 0px;">
How To Serve Django Applications with uWSGI and Nginx on Ubuntu 16.04</h1>
</div>
<div class="content-body tutorial-content" data-growable-markdown="" style="background-color: white; font-family: proxima-nova, sans-serif; font-size: 16px; overflow-x: auto;">
<h3 id="introduction" style="box-sizing: border-box; color: #2d2d2d; font-size: 22px; letter-spacing: -0.5px; margin: 14px auto 11px; padding: 0px; width: 745px;">
<br /></h3>
<h3 id="introduction" style="box-sizing: border-box; color: #2d2d2d; font-size: 22px; letter-spacing: -0.5px; margin: 14px auto 11px; padding: 0px; width: 745px;">
Introduction</h3>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Django is a powerful web framework that can help you get your Python application or website off the ground. Django includes a simplified development server for testing your code locally, but for anything even slightly production related, a more secure and powerful web server is required.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
In this guide, we will demonstrate how to install and configure some components on Ubuntu 16.04 to support and serve Django applications. We will configure the uWSGI application container server to interface with our applications. We will then set up Nginx to reverse proxy to uWSGI, giving us access to its security and performance features to serve our apps.</div>
<div data-unique="prerequisites-and-goals" name="prerequisites-and-goals" style="box-sizing: border-box; margin-left: auto; margin-right: auto; width: 745px;">
</div>
<h2 id="prerequisites-and-goals" style="box-sizing: border-box; color: #2d2d2d; font-size: 28px; font-weight: 400; letter-spacing: 0.2px; margin: 10px auto; padding: 0px; width: 745px;">
Prerequisites and Goals</h2>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
In order to complete this guide, you should have a fresh Ubuntu 16.04 server instance with a non-root user with <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">sudo</code> privileges configured. You can learn how to set this up by running through our <a href="https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04" style="background-color: transparent; border-bottom-color: rgb(0, 0, 0); border-bottom-style: dotted; border-bottom-width: 1px; box-sizing: border-box; color: black; text-decoration: none;">initial server setup guide</a>.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We will be installing Django within two different virtual environments. This will allow your projects and their requirements to be handled separately. We will be creating two sample projects so that we can run through the steps in a multi-project environment.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Once we have our applications, we will install and configure the uWSGI application server. This will serve as an interface to our applications which will translate client requests using HTTP to Python calls that our application can process. We will then set up Nginx in front of uWSGI to take advantage of its high performance connection handling mechanisms and its easy-to-implement security features.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Let's get started.</div>
<div data-unique="install-and-configure-virtualenv-and-virtualenvwrapper" name="install-and-configure-virtualenv-and-virtualenvwrapper" style="box-sizing: border-box; margin-left: auto; margin-right: auto; width: 745px;">
</div>
<h2 id="install-and-configure-virtualenv-and-virtualenvwrapper" style="box-sizing: border-box; color: #2d2d2d; font-size: 28px; font-weight: 400; letter-spacing: 0.2px; margin: 10px auto; padding: 0px; width: 745px;">
Install and Configure VirtualEnv and VirtualEnvWrapper</h2>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We will be installing our Django projects in their own virtual environments to isolate the requirements for each. To do this, we will be installing <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">virtualenv</code>, which can create Python virtual environments, and<code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">virtualenvwrapper</code>, which adds some usability improvements to the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">virtualenv</code> work flow.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We will be installing both of these components using <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">pip</code>, the Python package manager. We can install this utility from the Ubuntu repositories.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you are building your Django projects with Python 2, type:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo apt-get update
</li>
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo apt-get install python-pip
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you are using Python 3, type:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo apt-get update
</li>
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo apt-get install python3-pip
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Now that you have <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">pip</code> installed, we can install <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">virtualenv</code> and <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">virtualenvwrapper</code> globally.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you are using Python 2, type:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo pip install virtualenv virtualenvwrapper
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you are using Python 3, type:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo pip3 install virtualenv virtualenvwrapper
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
With these components installed, we can now configure our shell with the information it needs to work with the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">virtualenvwrapper</code> script. Our virtual environments will all be placed within a directory in our home folder called <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">Env</code> for easy access. This is configured through an environmental variable called<code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">WORKON_HOME</code>. We can add this to our shell initialization script and can source the virtual environment wrapper script.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you are using Python 3 and the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">pip3</code> command, you will have to add an additional line to your shell initialization script as well:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">echo "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3" >> ~/.bashrc
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Regardless of which version of Python you are using, you need to run the following commands:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">echo "export WORKON_HOME=~/Env" >> ~/.bashrc
</li>
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Now, source your shell initialization script so that you can use this functionality in your current session:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">source ~/.bashrc
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
You should now have directory called <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">Env</code> in your home folder which will hold virtual environment information.</div>
<div data-unique="create-django-projects" name="create-django-projects" style="box-sizing: border-box; margin-left: auto; margin-right: auto; width: 745px;">
</div>
<h2 id="create-django-projects" style="box-sizing: border-box; color: #2d2d2d; font-size: 28px; font-weight: 400; letter-spacing: 0.2px; margin: 10px auto; padding: 0px; width: 745px;">
Create Django Projects</h2>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Now that we have our virtual environment tools, we will create two virtual environments, install Django in each, and start two projects.</div>
<h3 id="create-the-first-project" style="box-sizing: border-box; color: #2d2d2d; font-size: 22px; letter-spacing: -0.5px; margin: 14px auto 11px; padding: 0px; width: 745px;">
Create the First Project</h3>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We can create a virtual environment easily by using some commands that the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">virtualenvwrapper</code> script makes available to us.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Create your first virtual environment with the name of your first site or project by typing:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">mkvirtualenv <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
This will create a virtual environment, install Python and <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">pip</code> within it, and activate the environment. Your prompt will change to indicate that you are now operating within your new virtual environment. It will look something like this: <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">(<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>)<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">user</span>@<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">hostname</span>:~$</code>. The value in the parentheses is the name of your virtual environment. Any software installed through <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">pip</code> will now be installed into the virtual environment instead of on the global system. This allows us to isolate our packages on a per-project basis.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Our first step will be to install Django itself. We can use <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">pip</code> for this without <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">sudo</code> since we are installing this locally in our virtual environment:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(firstsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">pip install django
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
With Django installed, we can create our first sample project by typing:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(firstsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">cd ~
</li>
<li class="line" prefix="(firstsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">django-admin.py startproject <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
This will create a directory called <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;"><span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span></code> within your home directory. Within this is a management script used to handle various aspects of the project and another directory of the same name used to house the actual project code.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Move into the first level directory so that we can begin setting up the minimum requirements for our sample project.</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(firstsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">cd ~/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Begin by migrating the database to initialize the SQLite database that our project will use. You can set up an alternative database for your application if you wish, but this is outside of the scope of this guide:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(firstsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">./manage.py migrate
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
You should now have a database file called <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">db.sqlite3</code> in your project directory. Now, we can create an administrative user by typing:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(firstsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">./manage.py createsuperuser
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
You will have to select a username, give a contact email address, and then select and confirm a password.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Next, open the settings file for the project with your text editor:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(firstsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">nano <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>/settings.py
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Since we will be setting up Nginx to serve our site, we need to configure a directory which will hold our site's static assets. This will allow Nginx to serve these directly, which will have a positive impact on performance. We will tell Django to place these into a directory called <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">static</code> in our project's base directory. Add this line to the bottom of the file to configure this behavior:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="~/firstsite/firstsite/settings.py">
~/firstsite/firstsite/settings.py</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">. . .
STATIC_URL = '/static/'
<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">STATIC_ROOT = os.path.join(BASE_DIR, 'static/')</span>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Save and close the file when you are finished. Now, collect our site's static elements and place them within that directory by typing:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(firstsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">./manage.py collectstatic
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
You can type "yes" to confirm the action and collect the static content. There will be a new directory called<code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">static</code> in your project directory.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Next, we can open a port so that we can access the Django development server. If you followed the initial server setup guide, you should have a UFW firewall enabled. Allow connections to port 8080 by typing:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(firstsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo ufw allow 8080
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
With all of that out of the way, we can test our project by temporarily starting the development server. Type:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(firstsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">./manage.py runserver 0.0.0.0:8080
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
This will start up the development server on port <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">8080</code>. Visit your server's domain name or IP address followed by <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">8080</code> in your browser:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">http://<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">server_domain_or_IP</span>:8080
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
You should see a page that looks like this:</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
<img alt="Django sample site" src="https://assets.digitalocean.com/articles/django_uwsgi_nginx_1404/sample_site.png" style="border: 0px; box-sizing: border-box; display: block; height: auto; margin-left: auto; margin-right: auto; max-width: 100%;" /></div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Add <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">/admin</code> to the end of the URL in your browser's address bar and you will be taken to the admin login page:</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
<img alt="Django admin login" src="https://assets.digitalocean.com/articles/django_uwsgi_nginx_1404/admin_login.png" style="border: 0px; box-sizing: border-box; display: block; height: auto; margin-left: auto; margin-right: auto; max-width: 100%;" /></div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Using the administrative login credentials you selected with the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">createsuperuser</code> command, log into the server. You will then have access to the administration interface:</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
<img alt="Django admin interface" src="https://assets.digitalocean.com/articles/django_uwsgi_nginx_1404/admin_interface.png" style="border: 0px; box-sizing: border-box; display: block; height: auto; margin-left: auto; margin-right: auto; max-width: 100%;" /></div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
After testing this functionality out, stop the development server by typing CTRL-C in your terminal. We can now move on to our second project.</div>
<h3 id="create-the-second-project" style="box-sizing: border-box; color: #2d2d2d; font-size: 22px; letter-spacing: -0.5px; margin: 14px auto 11px; padding: 0px; width: 745px;">
Create the Second Project</h3>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
The second project will be created in exactly the same way as the first. We will abridge the explanation in this section, seeing as how you have already completed this once.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Move back to your home directory and create a second virtual environment for your new project. Install Django inside of this new environment once it is activated:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">cd ~
</li>
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">mkvirtualenv <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>
</li>
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">pip install django
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
The new environment will be created <em style="box-sizing: border-box;">and</em> changed to, leaving your previous virtual environment. This Django instance is entirely separate from the other one you configured. This allows you to manage them independently and customize as necessary.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Create the second project and move into the project directory:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(secondsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">django-admin.py startproject <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>
</li>
<li class="line" prefix="(secondsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">cd ~/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Initialize the database and create an administrative user:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(secondsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">./manage.py migrate
</li>
<li class="line" prefix="(secondsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">./manage.py createsuperuser
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Open the settings file:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(secondsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">nano <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>/settings.py
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Add the location for the static files, just as you did in the previous project:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="~/secondsite/secondsite/settings.py">
~/secondsite/secondsite/settings.py</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">. . .
STATIC_URL = '/static/'
<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">STATIC_ROOT = os.path.join(BASE_DIR, 'static/')</span>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Save and close the file. Now, collect the static elements into that directory by typing:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(secondsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">./manage.py collectstatic
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Finally, fire up the development server to test out the site:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(secondsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">./manage.py runserver 0.0.0.0:8080
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
You should check the regular site at:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">http://<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">server_domain_or_IP</span>:8080
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Also log into the admin site:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">http://<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">server_domain_or_IP</span>:8080/admin
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
When you've confirmed that everything is working as expected, type CTRL-C in your terminal to stop the development server.</div>
<h3 id="backing-out-of-the-virtual-environment" style="box-sizing: border-box; color: #2d2d2d; font-size: 22px; letter-spacing: -0.5px; margin: 14px auto 11px; padding: 0px; width: 745px;">
Backing Out of the Virtual Environment</h3>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Since we are now done with the Django portion of the guide, we can deactivate our second virtual environment:</div>
<pre class="code-pre custom_prefix" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="(secondsite) $" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">deactivate
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you need to work on either of your Django sites again, you should reactivate their respective environments. You can do that by using the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">workon</code> command:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">workon <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Or:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">workon <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Again, deactivate when you are finished working on your sites:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">deactivate
</li>
</ul>
</code></pre>
<div data-unique="setting-up-the-uwsgi-application-server" name="setting-up-the-uwsgi-application-server" style="box-sizing: border-box; margin-left: auto; margin-right: auto; width: 745px;">
</div>
<h2 id="setting-up-the-uwsgi-application-server" style="box-sizing: border-box; color: #2d2d2d; font-size: 28px; font-weight: 400; letter-spacing: 0.2px; margin: 10px auto; padding: 0px; width: 745px;">
Setting up the uWSGI Application Server</h2>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Now that we have two Django projects set up and ready to go, we can configure uWSGI. uWSGI is an application server that can communicate with applications over a standard interface called WSGI. To learn more about this, read <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-ubuntu-14-04#definitions-and-concepts" style="background-color: transparent; border-bottom-color: rgb(0, 0, 0); border-bottom-style: dotted; border-bottom-width: 1px; box-sizing: border-box; color: black; text-decoration: none;">this section</a> of our guide on setting up uWSGI and Nginx on Ubuntu 14.04.</div>
<h3 id="installing-uwsgi" style="box-sizing: border-box; color: #2d2d2d; font-size: 22px; letter-spacing: -0.5px; margin: 14px auto 11px; padding: 0px; width: 745px;">
Installing uWSGI</h3>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Unlike the guide linked above, in this tutorial, we'll be installing uWSGI globally. This will create less friction in handling multiple Django projects. Before we can install uWSGI, we need the Python development files that the software relies on. We can install this directly from Ubuntu's repositories.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you are using Django with Python 2, type:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo apt-get install python-dev
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you are using Python 3, type:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo apt-get install python3-dev
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Now that the development files are available, we can install uWSGI globally through <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">pip</code>.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you are using Python 2, type:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo pip install uwsgi
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you are using Python 3, type:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo pip3 install uwsgi
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We can quickly test this application server by passing it the information for one of our sites. For instance, we can tell it to serve our first project by typing:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">uwsgi --http :8080 --home /home/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>/Env/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span> --chdir /home/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span> -w <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>.wsgi
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Here, we've told uWSGI to use our virtual environment located in our <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">~/Env</code> directory, to change to our project's directory, and to use the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">wsgi.py</code> file stored within our inner <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;"><span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span></code> directory to serve the file. For our demonstration, we told it to serve HTTP on port <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">8080</code>. If you go to server's domain name or IP address in your browser, followed by <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">:8080</code>, you will see your site again (the static elements in the<code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">/admin</code> interface, like CSS, won't work yet). When you are finished testing out this functionality, type CTRL-C in the terminal.</div>
<h3 id="creating-configuration-files" style="box-sizing: border-box; color: #2d2d2d; font-size: 22px; letter-spacing: -0.5px; margin: 14px auto 11px; padding: 0px; width: 745px;">
Creating Configuration Files</h3>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Running uWSGI from the command line is useful for testing, but isn't particularly helpful for an actual deployment. Instead, we will run uWSGI in "Emperor mode", which allows a master process to manage separate applications automatically given a set of configuration files.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Create a directory that will hold your configuration files. Since this is a global process, we will create a directory called <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">/etc/uwsgi/sites</code> to store our configuration files. Move into the directory after you create it:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo mkdir -p /etc/uwsgi/sites
</li>
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">cd /etc/uwsgi/sites
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
In this directory, we will place our configuration files. We need a configuration file for each of the projects we are serving. The uWSGI process can take configuration files in a variety of formats, but we will use<code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">.ini</code> files due to their simplicity.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Create a file for your first project and open it in your text editor:</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">sudo nano <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>.ini
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Inside, we must begin with the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">[uwsgi]</code> section header. All of our information will go beneath this header. We are also going to use variables to make our configuration file more reusable. After the header, set a variable called <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">project</code> with the name of your first project. Add a variable called <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">uid</code> which holds your<code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">sudo</code> username.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We will also add a variable called <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">base</code> with the path to your user's home directory. This will be constructed from the username we set using the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">%(variable_name)</code> syntax. This will be replaced by the value of the variable when the config is read:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/uwsgi/sites/firstsite.ini">
/etc/uwsgi/sites/firstsite.ini</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">[uwsgi]
project = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>
uid = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>
base = /home/%(uid)
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Next, we need to configure uWSGI so that it handles our project correctly. We need to change into the root project directory by setting the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">chdir</code> option. We can combine the home directory and project name using the same variable syntax.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
In a similar way, we will indicate the virtual environment for our project. By setting the module, we can indicate exactly how to interface with our project (by importing the "application" callable from the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">wsgi.py</code>file within our project directory). The configuration of these items will look like this:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/uwsgi/sites/firstsite.ini">
/etc/uwsgi/sites/firstsite.ini</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">[uwsgi]
project = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>
uid = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>
base = /home/%(uid)
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We want to create a master process with 5 workers. We can do this by adding this:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/uwsgi/sites/firstsite.ini">
/etc/uwsgi/sites/firstsite.ini</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">[uwsgi]
project = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>
uid = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>
base = /home/%(uid)
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 5
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Next we need to specify how uWSGI should listen for connections. In our test of uWSGI, we used HTTP and a network port. However, since we are going to be using Nginx as a reverse proxy, we have better options.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Instead of using a network port, since all of the components are operating on a single server, we can use a Unix socket. This is more secure and offers better performance. This socket will not use HTTP, but instead will implement uWSGI's <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">uwsgi</code> protocol, which is a fast binary protocol for designed for communicating with other servers. Nginx can natively proxy using the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">uwsgi</code> protocol, so this is our best choice.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We will also modify the ownership and permissions of the socket because we will be giving the web server write access. We'll set the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">vacuum</code> option so that the socket file will be automatically cleaned up when the service is stopped:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/uwsgi/sites/firstsite.ini">
/etc/uwsgi/sites/firstsite.ini</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">[uwsgi]
project = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>
uid = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>
base = /home/%(uid)
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 5
socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
With this, our first project's uWSGI configuration is complete. Save and close the file.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
The advantage of setting up the file using variables is that it makes it incredibly simple to reuse. Copy your first project's configuration file to use as a base for your second configuration file:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo cp /etc/uwsgi/sites/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>.ini /etc/uwsgi/sites/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>.ini
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Open the second configuration file with your text editor:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo nano /etc/uwsgi/sites/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>.ini
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We only need to change a single value in this file in order to make it work for our second project. Modify the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">project</code> variable with the name you've used for your second project:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/uwsgi/sites/secondsite.ini">
/etc/uwsgi/sites/secondsite.ini</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">[uwsgi]
project = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>
uid = <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>
base = /home/%(uid)
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 5
socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Save and close the file when you are finished. Your second project should be ready to go now.</div>
<h3 id="create-a-systemd-unit-file-for-uwsgi" style="box-sizing: border-box; color: #2d2d2d; font-size: 22px; letter-spacing: -0.5px; margin: 14px auto 11px; padding: 0px; width: 745px;">
Create a systemd Unit File for uWSGI</h3>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We now have the configuration files we need to serve our Django projects, but we still haven't automated the process. Next, we'll create a systemd unit file to automatically start uWSGI at boot.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We will create the unit file in the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">/etc/systemd/system</code> directory, where user-created unit files are kept. We will call our file <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">uwsgi.service</code>:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo nano /etc/systemd/system/uwsgi.service
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Start with the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">[Unit]</code> section, which is used to specify metadata and ordering information. We'll simply put a description of our service here:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/systemd/system/uwsgi.service">
/etc/systemd/system/uwsgi.service</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">[Unit]
Description=uWSGI Emperor service
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Next, we'll open up the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">[Service]</code> section. We'll use the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">ExecStartPre</code> directive to set up the pieces we need to run our server. This will make sure the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">/run/uwsgi</code> directory is created and that our normal user owns it with the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">www-data</code> group as the group owner. Both <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">mkdir</code> with the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">-p</code> flag and the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">chown</code>command return successfully even if their operation is not needed. This is what we want.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
For the actual start command, specified by the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">ExecStart</code> directive, we will point to the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">uwsgi</code>executable. We will tell it to run in "Emperor mode", allowing it to manage multiple applications using the files it finds in <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">/etc/uwsgi/sites</code>. We will also add the pieces needed for systemd to correctly manage the process. These are taken from the uWSGI documentation <a href="http://uwsgi-docs.readthedocs.io/en/latest/Systemd.html" style="background-color: transparent; border-bottom-color: rgb(0, 0, 0); border-bottom-style: dotted; border-bottom-width: 1px; box-sizing: border-box; color: black; text-decoration: none;">here</a>.</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/systemd/system/uwsgi.service">
/etc/systemd/system/uwsgi.service</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>:www-data /run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Now, all we need to do is add the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">[Install]</code> section. This allows us to specify when the service should be automatically started. We will tie our service to the multi-user system state. Whenever the system is set up for multiple users (the normal operating condition), our service will be activated:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/systemd/system/uwsgi.service">
/etc/systemd/system/uwsgi.service</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>:www-data /run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
When you are finished, save and close the file.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We will be unable to start the service successfully at this point because it relies on the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">www-data</code> user being available. We will have to wait to start the uWSGI service until after Nginx is installed.</div>
<div data-unique="install-and-configure-nginx-as-a-reverse-proxy" name="install-and-configure-nginx-as-a-reverse-proxy" style="box-sizing: border-box; margin-left: auto; margin-right: auto; width: 745px;">
</div>
<h2 id="install-and-configure-nginx-as-a-reverse-proxy" style="box-sizing: border-box; color: #2d2d2d; font-size: 28px; font-weight: 400; letter-spacing: 0.2px; margin: 10px auto; padding: 0px; width: 745px;">
Install and Configure Nginx as a Reverse Proxy</h2>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
With uWSGI configured and ready to go, we can now install and configure Nginx as our reverse proxy. This can be downloaded from Ubuntu's default repositories:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo apt-get install nginx
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Once Nginx is installed, we can go ahead and create a server block configuration file for each of our projects. Start with the first project by creating a server block configuration file:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo nano /etc/nginx/sites-available/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Inside, we can start our server block by indicating the port number and domain name where our first project should be accessible. We'll assume that you have a domain name for each:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/nginx/sites-available/firstsite">
/etc/nginx/sites-available/firstsite</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">server {
listen 80;
server_name <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>.com www.<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>.com;
}
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Next, we can tell Nginx not to worry if it can't find a favicon. We will also point it to the location of our static files directory where we collected our site's static elements:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/nginx/sites-available/firstsite">
/etc/nginx/sites-available/firstsite</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">server {
listen 80;
server_name <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>.com www.<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>;
}
}
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Next we can create a catch-all location block that will pass all additional queries straight to our application. We will include the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">uwsgi</code> parameters found in the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">/etc/nginx/uwsgi_params</code> and pass the traffic to the socket that the uWSGI server sets up:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/nginx/sites-available/firstsite">
/etc/nginx/sites-available/firstsite</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">server {
listen 80;
server_name <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>.com www.<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span>.sock;
}
}
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
With that, our first server block is complete.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
We will use this as a basis for our second project's Nginx configuration file. Copy it over now:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo cp /etc/nginx/sites-available/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span> /etc/nginx/sites-available/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Open the new file in your text editor:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo nano /etc/nginx/sites-available/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Here, you'll have to change any reference to <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;"><span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span></code> with a reference to <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;"><span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span></code>. You'll also have to modify the <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">server_name</code> so that your second project responds to a different domain name. When you are finished, it will look something like this:</div>
<div class="code-label " style="background-color: #eaeaea; border-radius: 3px 3px 0px 0px; box-sizing: border-box; color: #3a3a3a; font-size: 14px; margin-bottom: -30px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="/etc/nginx/sites-available/secondsite">
/etc/nginx/sites-available/secondsite</div>
<pre class="code-pre " style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin: 28px auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;">server {
listen 80;
server_name <span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>.com www.<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">sammy</span>/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span>.sock;
}
}
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Save and close the file when you are finished.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Next, link both of your new configuration files to Nginx's <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">sites-enabled</code> directory to enable them:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo ln -s /etc/nginx/sites-available/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">firstsite</span> /etc/nginx/sites-enabled
</li>
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo ln -s /etc/nginx/sites-available/<span class="highlight" style="background: 0px 0px; box-sizing: border-box; color: #e94849;">secondsite</span> /etc/nginx/sites-enabled
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Check the configuration syntax by typing:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo nginx -t
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If no syntax errors are detected, you can restart your Nginx service to load the new configuration:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo systemctl restart nginx
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If you remember from earlier, we never actually started the uWSGI server. Do that now by typing:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo systemctl start uwsgi
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Let's delete the UFW rule to port <code style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 15px; line-height: 22px; padding: 3px;">8080</code> and instead allow access to our Nginx server:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo ufw delete allow 8080
</li>
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo ufw allow 'Nginx Full'
</li>
</ul>
</code></pre>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
You should now be able to reach your two projects by going to their respective domain names. Both the public and administrative interfaces should work as expected.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
If this goes well, you can enable both of the services to start automatically at boot by typing:</div>
<pre class="code-pre command" style="background-color: rgba(0, 0, 0, 0.0470588); border-radius: 3px; box-sizing: border-box; font-family: monospace, monospace; font-size: 14px; margin-bottom: 28px; margin-left: auto; margin-right: auto; overflow: auto !important; padding: 13px 17px; width: 745px; word-wrap: normal;"><code langs="" style="background-color: transparent; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-family: monospace, monospace; line-height: 22px; margin: 0px; padding: 0px;"><ul class="prefixed" style="box-sizing: border-box; margin: 0px; padding: 0px; white-space: normal;">
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo systemctl enable nginx
</li>
<li class="line" prefix="$" style="box-sizing: border-box; line-height: 1.5 !important; list-style: disc outside none; margin-bottom: 3px; margin-left: 20px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; white-space: pre;">sudo systemctl enable uwsgi
</li>
</ul>
</code></pre>
<div class="code-label notes-and-warnings note" style="background-color: #eae9cc; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; font-size: 15px; line-height: 26px; margin-bottom: -3px; margin-left: auto; margin-right: auto; padding: 8px 15px; position: relative; text-align: center; width: 745px; z-index: 2;" title="Note">
Note</div>
<span class="note" style="background-color: #f4f2d4; border-radius: 3px; box-sizing: border-box; color: #3a3a3a; display: block; font-size: 15px; line-height: 26px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 13px 17px; width: 745px;"><div style="box-sizing: border-box; font-size: 16px; line-height: 28px; margin-bottom: 22px; padding: 0px;">
After configuring Nginx, the next step should be securing traffic to the server using SSL/TLS. This is important because without it, all information, including passwords are sent over the network in plain text.</div>
<div style="box-sizing: border-box; font-size: 16px; line-height: 28px; margin-bottom: 22px; padding: 0px;">
The easiest way get an SSL certificate to secure your traffic is using Let's Encrypt. Follow <a href="https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04" style="background-color: transparent; border-bottom-color: rgb(0, 0, 0); border-bottom-style: dotted; border-bottom-width: 1px; box-sizing: border-box; color: black; text-decoration: none;">this guide</a> to set up Let's Encrypt with Nginx on Ubuntu 16.04.</div>
</span><div data-unique="conclusion" name="conclusion" style="box-sizing: border-box; margin-left: auto; margin-right: auto; width: 745px;">
</div>
<h2 id="conclusion" style="box-sizing: border-box; color: #2d2d2d; font-size: 28px; font-weight: 400; letter-spacing: 0.2px; margin: 10px auto; padding: 0px; width: 745px;">
Conclusion</h2>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
In this guide, we've set up two Django projects, each in their own virtual environments. We've configured uWSGI to serve each project independently using the virtual environment configured for each. Afterwards, we set up Nginx to act as a reverse proxy to handle client connections and serve the correct project depending on the client request.</div>
<div style="box-sizing: border-box; line-height: 28px; margin-bottom: 22px; margin-left: auto; margin-right: auto; padding: 0px; width: 745px;">
Django makes creating projects and applications simple by providing many of the common pieces, allowing you to focus on the unique elements. By leveraging the general tool chain described in this article, you can easily serve the applications you create from a single server.</div>
</div>
Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com1tag:blogger.com,1999:blog-7586695.post-87944319302315879682015-11-15T16:18:00.001+08:002015-11-15T16:18:19.466+08:00odoo backup dababase<div dir="ltr"><div><div class="gmail_signature"><div dir="ltr"><p style="font-size:12.8px;margin:0px 0px 10px"><font color="#333333" face="Helvetica Neue, Helvetica, Arial, sans-serif"><span style="font-size:14px;line-height:16px"><a href="https://www.odoo.com/forum/help-1/question/how-to-setup-a-regular-postgresql-database-backup-4728" target="_blank">https://www.odoo.com/forum/help-1/question/how-to-setup-a-regular-postgresql-database-backup-4728</a></span></font><br></p><ol style="margin-top:0px;margin-bottom:10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px"><li style="margin-left:15px"><p style="margin:0px">Backup-Script <code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:12.6px;padding:2px 4px;color:rgb(199,37,78);border-radius:4px;background-color:rgb(249,242,244)">/var/scripts/dump_db.sh</code></p><pre style="white-space:pre-wrap;overflow:auto;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:13px;padding:9.5px;margin-top:0px;margin-bottom:10px;line-height:1.42857;word-wrap:break-word;border:1px solid rgb(204,204,204);border-radius:4px;background-color:rgb(245,245,245)"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:inherit;padding:0px;color:inherit;border-radius:0px;background-color:transparent">#!/bin/sh hostname=`hostname` ########################################## ## OpenERP Backup ## Backup databases: openerpdb1, openerpdb2 ########################################## # Stop OpenERP Server /etc/init.d/openerp-server stop # Dump DBs for db in openerpdb1 openerpdb2 do date=`date +"%Y%m%d_%H%M%N"` filename="/var/pgdump/${hostname}_${db}_${date}.sql" pg_dump -E UTF-8 -p 5433 -F p -b -f $filename $db gzip $filename done # Start OpenERP Server /etc/init.d/openerp-server start exit 0 </code></pre></li><li style="margin-left:15px"><p style="margin:0px">Housekeeping script <code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:12.6px;padding:2px 4px;color:rgb(199,37,78);border-radius:4px;background-color:rgb(249,242,244)">/var/scripts/housekeeping.sh</code> (deletes backups which are older than 30 days)</p><pre style="white-space:pre-wrap;overflow:auto;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:13px;padding:9.5px;margin-top:0px;margin-bottom:10px;line-height:1.42857;word-wrap:break-word;border:1px solid rgb(204,204,204);border-radius:4px;background-color:rgb(245,245,245)"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:inherit;padding:0px;color:inherit;border-radius:0px;background-color:transparent">#!/bin/sh path=/var/pgdump logfile=/var/log/$0 rm -f $logfile for file in `find /var/pgdump/ -mtime +30 -type f -name *.sql.gz` do echo "deleting: " $file >> $logfile rm $file done exit 0 </code></pre></li><li style="margin-left:15px"><p style="margin:0px">Create daily cronjobs in <code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:12.6px;padding:2px 4px;color:rgb(199,37,78);border-radius:4px;background-color:rgb(249,242,244)">/etc/crontab</code>. The backup runs daily at 1am and the housekeeping job runs daily at 5am.</p><pre style="white-space:pre-wrap;overflow:auto;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:13px;padding:9.5px;margin-top:0px;margin-bottom:10px;line-height:1.42857;word-wrap:break-word;border:1px solid rgb(204,204,204);border-radius:4px;background-color:rgb(245,245,245)"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:inherit;padding:0px;color:inherit;border-radius:0px;background-color:transparent"># m h dom mon dow user command 0 1 * * * postgres /var/scripts/dump_db.sh 0 5 * * * postgres /var/scripts/housekeeping.sh</code></pre></li></ol><p style="margin:0px 0px 10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px"><br></p><p style="margin:0px 0px 10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px"><br></p><p style="margin:0px 0px 10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px">Simples and efective...</p><p style="margin:0px 0px 10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px">The script is executed via cron with</p><pre style="white-space:pre-wrap;overflow:auto;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:13px;padding:9.5px;margin-top:0px;margin-bottom:10px;line-height:1.42857;word-wrap:break-word;color:rgb(51,51,51);border:1px solid rgb(204,204,204);border-radius:4px;background-color:rgb(245,245,245)"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:inherit;padding:0px;color:inherit;border-radius:0px;background-color:transparent"> 00 01 * * * nice -19 /home/mbmaster/scripts/backupdb > /dev/null 2>&1 </code></pre><p style="margin:0px 0px 10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px">the "nice -19" is important to lower the priority of the backup</p><pre style="white-space:pre-wrap;overflow:auto;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:13px;padding:9.5px;margin-top:0px;margin-bottom:10px;line-height:1.42857;word-wrap:break-word;color:rgb(51,51,51);border:1px solid rgb(204,204,204);border-radius:4px;background-color:rgb(245,245,245)"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:inherit;padding:0px;color:inherit;border-radius:0px;background-color:transparent"> # Backup script starts here. #!/bin/bash # Location of the backup logfile. logfile="/home/mbmaster/backups/logfile.log" # Location to place backups. backup_dir="/home/mbmaster/backups" touch $logfile timeslot=`date +%d%m%y%H%M%S` databases=`psql -U postgres -q -c "\l" | awk '{ print $1}' | grep -vE '^\||^-|^List|^Name|template[0|1]|^\('` for i in $databases; do timeinfo=`date '+%T %x'` echo "Backup and Vacuum started at $timeinfo for time slot $timeslot on database: $i " >> $logfile /usr/bin/vacuumdb -z -U postgres $i >/dev/null 2>&1 /usr/bin/pg_dump $i -U postgres | gzip > "$backup_dir/openerp-$i-$timeslot-database.gz" timeinfo=`date '+%T %x'` echo "Backup and Vacuum complete at $timeinfo for time slot $timeslot on database: $i " >> $logfile done #------------------------------------------------- # delete files more than 10 days old find $backup_dir/openerp* -mtime +10 -exec rm {} \;</code></pre><p style="margin:0px 0px 10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px"><br></p><p style="margin:0px 0px 10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px">1 - Backup-Script /var/lib/postgresql/postgres_db_backup.sh</p><pre style="white-space:pre-wrap;overflow:auto;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:13px;padding:9.5px;margin-top:0px;margin-bottom:10px;line-height:1.42857;word-wrap:break-word;color:rgb(51,51,51);border:1px solid rgb(204,204,204);border-radius:4px;background-color:rgb(245,245,245)"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:inherit;padding:0px;color:inherit;border-radius:0px;background-color:transparent">#!/bin/bash # Location to place backups. backup_dir="/var/backups/postgres_db/" #String to append to the name of the backup files backup_date=`date +%Y-%m-%d_%H-%M` #Numbers of days you want to keep copie of your databases number_of_days=3 databases=`psql -l -t | cut -d'|' -f1 | sed -e 's/ //g' -e '/^$/d'` for i in $databases; do if [ "$i" != "template0" ] && [ "$i" != "template1" ] && [ "$i" != "postgres" ]; then backupfile=$backup_dir$i.$backup_date.sql.gz echo Dumping $i to $backupfile pg_dump $i|gzip > $backupfile fi done find $backup_dir -type f -prune -mtime +$number_of_days -exec rm -f {} \; </code></pre><p style="margin:0px 0px 10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px">2 - open your terminal</p><ul style="margin-top:0px;margin-bottom:10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px"><li style="margin-left:15px"><p style="margin:0px">su</p></li><li style="margin-left:15px"><p style="margin:0px">su postgres</p></li><li style="margin-left:15px"><p style="margin:0px">crontab -e</p></li></ul><p style="margin:0px 0px 10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px">add</p><ul style="margin-top:0px;margin-bottom:10px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:16px"><li style="margin-left:15px">45 */4 * * * /var/lib/postgresql/postgres_db_backup.sh</li></ul></div></div></div> </div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-8328418874300417122015-09-23T18:18:00.000+08:002015-09-23T18:18:13.687+08:00Bit operation hacks<br />
<br />
http://graphics.stanford.edu/~seander/bithacks.html<br />
<h2>
Bit Twiddling Hacks</h2>
<h3>
By Sean Eron Anderson<br />seander@cs.stanford.edu</h3>
<small>Individually, the <strong>code snippets here are in the public domain</strong> (unless otherwise noted) — feel free to use them however you please. The aggregate collection and descriptions are © 1997-2005 Sean Eron Anderson. The code and descriptions are distributed in the hope that they will be useful, but <strong>WITHOUT ANY WARRANTY</strong> and without even the implied warranty of merchantability or fitness for a particular purpose. As of May 5, 2005, all the code has been tested thoroughly. Thousands of people have read it. Moreover, <a href="http://www-2.cs.cmu.edu/~bryant/">Professor Randal Bryant</a>, the Dean of Computer Science at Carnegie Mellon University, has personally tested almost everything with his <a href="http://www-2.cs.cmu.edu/~uclid/">Uclid code verification system</a>. What he hasn't tested, I have checked against all possible inputs on a 32-bit machine. <strong>To the first person to inform me of a legitimate bug in the code, I'll pay a bounty of US$10 (by check or Paypal)</strong>. If directed to a charity, I'll pay US$20.</small><br />
<br />
<br />
<h3>
Contents</h3>
<ul>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#OperationCounting">About the operation counting methodology</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign">Compute the sign of an integer</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#DetectOppositeSigns">Detect if two integers have opposite signs</a></li>
<a href="http://graphics.stanford.edu/~seander/bithacks.html#DetectOppositeSigns"></a>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#DetectOppositeSigns"></a><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs">Compute the integer absolute value (abs) without branching</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax">Compute the minimum (min) or maximum (max) of two integers without branching</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2">Determining if an integer is a power of 2</a></li>
<li>Sign extending<ul>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#FixedSignExtend">Sign extending from a constant bit-width</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#VariableSignExtend">Sign extending from a variable bit-width</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#VariableSignExtendRisky">Sign extending from a variable bit-width in 3 operations</a></li>
</ul>
</li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ConditionalSetOrClearBitsWithoutBranching">Conditionally set or clear bits without branching</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ConditionalNegate">Conditionally negate a value without branching</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#MaskedMerge">Merge bits from two values according to a mask</a></li>
<li>Counting bits set<ul>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetNaive">Counting bits set, naive way</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetTable">Counting bits set by lookup table</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan">Counting bits set, Brian Kernighan's way</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSet64">Counting bits set in 14, 24, or 32-bit words using 64-bit instructions</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel">Counting bits set, in parallel</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#CountBitsFromMSBToPos">Count bits set (rank) from the most-significant bit upto a given position</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#SelectPosFromMSBRank">Select the bit position (from the most-significant bit) with the given count (rank)</a></li>
</ul>
</li>
<li>Computing parity (1 if an odd number of bits set, 0 otherwise)<ul>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ParityNaive">Compute parity of a word the naive way</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ParityLookupTable">Compute parity by lookup table</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ParityWith64Bits">Compute parity of a byte using 64-bit multiply and modulus division</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ParityMultiply">Compute parity of word with a multiply</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel">Compute parity in parallel</a></li>
</ul>
</li>
<li>Swapping Values<ul>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#SwappingValuesSubAdd">Swapping values with subtraction and addition</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#SwappingValuesXOR">Swapping values with XOR</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#SwappingBitsXOR">Swapping individual bits with XOR</a></li>
</ul>
</li>
<li>Reversing bit sequences<ul>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious">Reverse bits the obvious way</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable">Reverse bits in word by lookup table</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv">Reverse the bits in a byte with 3 operations (64-bit multiply and modulus division)</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64Bits">Reverse the bits in a byte with 4 operations (64-bit multiply, no division)</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits">Reverse the bits in a byte with 7 operations (no 64-bit, only 32)</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel">Reverse an N-bit quantity in parallel with 5 * lg(N) operations</a></li>
</ul>
</li>
<li>Modulus division (aka computing <em>remainders</em>)<ul>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ModulusDivisionEasy">Computing modulus division by 1 << s without a division operation (obvious)</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ModulusDivision">Computing modulus division by (1 << s) - 1 without a division operation</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ModulusDivisionParallel">Computing modulus division by (1 << s) - 1 in parallel without a division operation</a></li>
</ul>
</li>
<li>Finding integer log base 2 of an integer (aka the position of the highest bit set)<ul>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious">Find the log base 2 of an integer with the MSB N set in O(N) operations (the obvious way)</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogIEEE64Float">Find the integer log base 2 of an integer with an 64-bit IEEE float</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup">Find the log base 2 of an integer with a lookup table</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog">Find the log base 2 of an N-bit integer in O(lg(N)) operations</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn">Find the log base 2 of an N-bit integer in O(lg(N)) operations with multiply and lookup</a></li>
</ul>
</li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10">Find integer log base 10 of an integer</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10Obvious">Find integer log base 10 of an integer the obvious way</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogFloat">Find integer log base 2 of a 32-bit IEEE float</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogRootFloat">Find integer log base 2 of the pow(2, r)-root of a 32-bit IEEE float (for unsigned integer r)</a></li>
<li>Counting consecutive trailing zero bits (or finding bit indices)<ul>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightLinear">Count the consecutive zero bits (trailing) on the right linearly</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightParallel">Count the consecutive zero bits (trailing) on the right in parallel</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightBinSearch">Count the consecutive zero bits (trailing) on the right by binary search</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightFloatCast">Count the consecutive zero bits (trailing) on the right by casting to a float</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightModLookup">Count the consecutive zero bits (trailing) on the right with modulus division and lookup</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup">Count the consecutive zero bits (trailing) on the right with multiply and lookup</a></li>
</ul>
</li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2Float">Round up to the next highest power of 2 by float casting</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2">Round up to the next highest power of 2</a></li>
<li>Interleaving bits (aka computing <em>Morton Numbers</em>)<ul>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#InterleaveTableObvious">Interleave bits the obvious way</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#InterleaveTableLookup">Interleave bits by table lookup</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#Interleave64bitOps">Interleave bits with 64-bit multiply</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN">Interleave bits by Binary Magic Numbers</a></li>
</ul>
</li>
<li>Testing for ranges of bytes in a word (and counting occurances found)<ul>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord">Determine if a word has a zero byte</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#ValueInWord">Determine if a word has a byte equal to n</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#HasLessInWord">Determine if a word has byte less than n</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#HasMoreInWord">Determine if a word has a byte greater than n</a></li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#HasBetweenInWord">Determine if a word has a byte between m and n</a></li>
</ul>
</li>
<li><a href="http://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation">Compute the lexicographically next bit permutation</a></li>
</ul>
<hr />
<h3>
<a href="https://www.blogger.com/null" name="OperationCounting">About the operation counting methodology</a></h3>
When totaling the number of operations for algorithms here, any C operator is counted as one operation. Intermediate assignments, which need not be written to RAM, are not counted. Of course, this operation counting approach only serves as an approximation of the actual number of machine instructions and CPU time. All operations are assumed to take the same amount of time, which is not true in reality, but CPUs have been heading increasingly in this direction over time. There are many nuances that determine how fast a system will run a given sample of code, such as cache sizes, memory bandwidths, instruction sets, etc. In the end, benchmarking is the best way to determine whether one method is really faster than another, so consider the techniques below as possibilities to test on your target architecture.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="CopyIntegerSign">Compute the sign of an integer</a></h3>
<pre>int v; // we want to find the sign of v
int sign; // the result goes here
// CHAR_BIT is the number of bits per byte (normally 8).
sign = -(v < 0); // if v < 0 then -1, else 0.
// or, to avoid branching on CPUs with flag registers (IA32):
sign = -(int)((unsigned int)((int)v) >> (sizeof(int) * CHAR_BIT - 1));
// or, for one less instruction (but not portable):
sign = v >> (sizeof(int) * CHAR_BIT - 1);
</pre>
The last expression above evaluates to sign = v >> 31 for 32-bit integers. This is one operation faster than the obvious way, sign = -(v < 0). This trick works because when signed integers are shifted right, the value of the far left bit is copied to the other bits. The far left bit is 1 when the value is negative and 0 otherwise; all 1 bits gives -1. Unfortunately, this behavior is architecture-specific.<br />
Alternatively, if you prefer the result be either -1 or +1, then use:<br />
<pre>sign = +1 | (v >> (sizeof(int) * CHAR_BIT - 1)); // if v < 0 then -1, else +1
</pre>
On the other hand, if you prefer the result be either -1, 0, or +1, then use:<br />
<pre>sign = (v != 0) | -(int)((unsigned int)((int)v) >> (sizeof(int) * CHAR_BIT - 1));
// Or, for more speed but less portability:
sign = (v != 0) | (v >> (sizeof(int) * CHAR_BIT - 1)); // -1, 0, or +1
// Or, for portability, brevity, and (perhaps) speed:
sign = (v > 0) - (v < 0); // -1, 0, or +1
</pre>
If instead you want to know if something is non-negative, resulting in +1 or else 0, then use:<br />
<pre>sign = 1 ^ ((unsigned int)v >> (sizeof(int) * CHAR_BIT - 1)); // if v < 0 then 0, else 1
</pre>
Caveat: On March 7, 2003, Angus Duggan pointed out that the 1989 ANSI C specification leaves the result of signed right-shift implementation-defined, so on some systems this hack might not work. For greater portability, Toby Speight suggested on September 28, 2005 that CHAR_BIT be used here and throughout rather than assuming bytes were 8 bits long. Angus recommended the more portable versions above, involving casting on March 4, 2006. <a href="http://rpg-314.blogspot.com/">Rohit Garg</a> suggested the version for non-negative integers on September 12, 2009.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="DetectOppositeSigns">Detect if two integers have opposite signs</a></h3>
<pre>int x, y; // input values to compare signs
bool f = ((x ^ y) < 0); // true iff x and y have opposite signs
</pre>
Manfred Weis suggested I add this entry on November 26, 2009.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="IntegerAbs">Compute the integer absolute value (abs) without branching</a></h3>
<pre>int v; // we want to find the absolute value of v
unsigned int r; // the result goes here
int const mask = v >> sizeof(int) * CHAR_BIT - 1;
r = (v + mask) ^ mask;
</pre>
Patented variation:<br />
<pre>r = (v ^ mask) - mask;
</pre>
Some CPUs don't have an integer absolute value instruction (or the compiler fails to use them). On machines where branching is expensive, the above expression can be faster than the obvious approach, r = (v < 0) ? -(unsigned)v : v, even though the number of operations is the same.<br />
On March 7, 2003, Angus Duggan pointed out that the 1989 ANSI C specification leaves the result of signed right-shift implementation-defined, so on some systems this hack might not work. I've read that ANSI C does not require values to be represented as two's complement, so it may not work for that reason as well (on a diminishingly small number of old machines that still use one's complement). On March 14, 2004, Keith H. Duggar sent me the patented variation above; it is superior to the one I initially came up with, <code>r=(+1|(v>>(sizeof(int)*CHAR_BIT-1)))*v</code>, because a multiply is not used. Unfortunately, this method has been <a href="http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&p=1&u=/netahtml/search-adv.htm&r=1&f=G&l=50&d=ptxt&S1=6073150&OS=6073150&RS=6073150">patented</a> in the USA on June 6, 2000 by Vladimir Yu Volkonsky and assigned to <a href="http://www.sun.com/">Sun Microsystems</a>. On August 13, 2006, Yuriy Kaminskiy told me that the patent is likely invalid because the method was published well before the patent was even filed, such as in <a href="http://www.goof.com/pcg/doc/pentopt.txt">How to Optimize for the Pentium Processor</a> by Agner Fog, dated November, 9, 1996. Yuriy also mentioned that this document was translated to Russian in 1997, which Vladimir could have read. Moreover, the Internet Archive also has an old <a href="http://web.archive.org/web/19961201174141/www.x86.org/ftp/articles/pentopt/PENTOPT.TXT">link</a> to it. On January 30, 2007, Peter Kankowski shared with me an <a href="http://smallcode.weblogs.us/2007/01/31/microsoft-probably-uses-the-abs-function-patented-by-sun/">abs version</a> he discovered that was inspired by Microsoft's Visual C++ compiler output. It is featured here as the primary solution. On December 6, 2007, Hai Jin complained that the result was signed, so when computing the abs of the most negative value, it was still negative. On April 15, 2008 Andrew Shapira pointed out that the obvious approach could overflow, as it lacked an (unsigned) cast then; for maximum portability he suggested <code>(v < 0) ? (1 + ((unsigned)(-1-v))) : (unsigned)v</code>. But citing the ISO C99 spec on July 9, 2008, Vincent Lefèvre convinced me to remove it becasue even on non-2s-complement machines -(unsigned)v will do the right thing. The evaluation of -(unsigned)v first converts the negative value of v to an unsigned by adding 2**N, yielding a 2s complement representation of v's value that I'll call U. Then, U is negated, giving the desired result, -U = 0 - U = 2**N - U = 2**N - (v+2**N) = -v = abs(v).<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="IntegerMinOrMax">Compute the minimum (min) or maximum (max) of two integers without branching</a></h3>
<pre>int x; // we want to find the minimum of x and y
int y;
int r; // the result goes here
r = y ^ ((x ^ y) & -(x < y)); // min(x, y)
</pre>
On some rare machines where branching is very expensive and no condition move instructions exist, the above expression might be faster than the obvious approach, r = (x < y) ? x : y, even though it involves two more instructions. (Typically, the obvious approach is best, though.) It works because if x < y, then -(x < y) will be all ones, so r = y ^ (x ^ y) & ~0 = y ^ x ^ y = x. Otherwise, if x >= y, then -(x < y) will be all zeros, so r = y ^ ((x ^ y) & 0) = y. On some machines, evaluating (x < y) as 0 or 1 requires a branch instruction, so there may be no advantage.<br />
To find the maximum, use:<br />
<pre>r = x ^ ((x ^ y) & -(x < y)); // max(x, y)
</pre>
<h4>
Quick and dirty versions:</h4>
If you know that INT_MIN <= x - y <= INT_MAX, then you can use the following, which are faster because (x - y) only needs to be evaluated once.<br />
<pre>r = y + ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))); // min(x, y)
r = x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))); // max(x, y)
</pre>
Note that the 1989 ANSI C specification doesn't specify the result of signed right-shift, so these aren't portable. If exceptions are thrown on overflows, then the values of x and y should be unsigned or cast to unsigned for the subtractions to avoid unnecessarily throwing an exception, however the right-shift needs a signed operand to produce all one bits when negative, so cast to signed there.<br />
On March 7, 2003, Angus Duggan pointed out the right-shift portability issue. On May 3, 2005, Randal E. Bryant alerted me to the need for the precondition, INT_MIN <= x - y <= INT_MAX, and suggested the non-quick and dirty version as a fix. Both of these issues concern only the quick and dirty version. Nigel Horspoon observed on July 6, 2005 that gcc produced the same code on a Pentium as the obvious solution because of how it evaluates (x < y). On July 9, 2008 Vincent Lefèvre pointed out the potential for overflow exceptions with subtractions in r = y + ((x - y) & -(x < y)), which was the previous version. Timothy B. Terriberry suggested using xor rather than add and subract to avoid casting and the risk of overflows on June 2, 2009.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="DetermineIfPowerOf2">Determining if an integer is a power of 2</a></h3>
<pre>unsigned int v; // we want to see if v is a power of 2
bool f; // the result goes here
f = (v & (v - 1)) == 0;
</pre>
Note that 0 is incorrectly considered a power of 2 here. To remedy this, use:<br />
<pre>f = v && !(v & (v - 1));
</pre>
<hr />
<h3>
<a href="https://www.blogger.com/null" name="FixedSignExtend">Sign extending from a constant bit-width</a></h3>
Sign extension is automatic for built-in types, such as chars and ints. But suppose you have a signed two's complement number, x, that is stored using only b bits. Moreover, suppose you want to convert x to an int, which has more than b bits. A simple copy will work if x is positive, but if negative, the sign must be extended. For example, if we have only 4 bits to store a number, then -3 is represented as 1101 in binary. If we have 8 bits, then -3 is 11111101. The most-significant bit of the 4-bit representation is replicated sinistrally to fill in the destination when we convert to a representation with more bits; this is sign extending. In C, sign extension from a constant bit-width is trivial, since bit fields may be specified in structs or unions. For example, to convert from 5 bits to an full integer:<br />
<pre>int x; // convert this from using 5 bits to a full int
int r; // resulting sign extended number goes here
struct {signed int x:5;} s;
r = s.x = x;
</pre>
The following is a C++ template function that uses the same language feature to convert from B bits in one operation (though the compiler is generating more, of course).<br />
<pre>template <typename b="" t="" unsigned="">
inline T signextend(const T x)
{
struct {T x:B;} s;
return s.x = x;
}
int r = signextend<signed int="">(x); // sign extend 5 bit number x to r
</signed></typename></pre>
John Byrd caught a typo in the code (attributed to html formatting) on May 2, 2005. On March 4, 2006, Pat Wood pointed out that the ANSI C standard requires that the bitfield have the keyword "signed" to be signed; otherwise, the sign is undefined.<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="VariableSignExtend">Sign extending from a variable bit-width</a></h3>
Sometimes we need to extend the sign of a number but we don't know a priori the number of bits, b, in which it is represented. (Or we could be programming in a language like Java, which lacks bitfields.)<br />
<pre>unsigned b; // number of bits representing the number in x
int x; // sign extend this b-bit number to r
int r; // resulting sign-extended number
int const m = 1U << (b - 1); // mask can be pre-computed if b is fixed
x = x & ((1U << b) - 1); // (Skip this if bits in x above position b are already zero.)
r = (x ^ m) - m;
</pre>
The code above requires four operations, but when the bitwidth is a constant rather than variable, it requires only two fast operations, assuming the upper bits are already zeroes.<br />
A slightly faster but less portable method that doesn't depend on the bits in x above position b being zero is:<br />
<pre>int const m = CHAR_BIT * sizeof(x) - b;
r = (x << m) >> m;
</pre>
Sean A. Irvine suggested that I add sign extension methods to this page on June 13, 2004, and he provided <code>m = (1 << (b - 1)) - 1; r = -(x & ~m) | x;</code> as a starting point from which I optimized to get m = 1U << (b - 1); r = -(x & m) | x. But then on May 11, 2007, Shay Green suggested the version above, which requires one less operation than mine. Vipin Sharma suggested I add a step to deal with situations where x had possible ones in bits other than the b bits we wanted to sign-extend on Oct. 15, 2008. On December 31, 2009 Chris Pirazzi suggested I add the faster version, which requires two operations for constant bit-widths and three for variable widths.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="VariableSignExtendRisky">Sign extending from a variable bit-width in 3 operations</a></h3>
The following may be slow on some machines, due to the effort required for multiplication and division. This version is 4 operations. If you know that your initial bit-width, b, is greater than 1, you might do this type of sign extension in 3 operations by using r = (x * multipliers[b]) / multipliers[b], which requires only one array lookup.<br />
<pre>unsigned b; // number of bits representing the number in x
int x; // sign extend this b-bit number to r
int r; // resulting sign-extended number
#define M(B) (1U << ((sizeof(x) * CHAR_BIT) - B)) // CHAR_BIT=bits/byte
static int const multipliers[] =
{
0, M(1), M(2), M(3), M(4), M(5), M(6), M(7),
M(8), M(9), M(10), M(11), M(12), M(13), M(14), M(15),
M(16), M(17), M(18), M(19), M(20), M(21), M(22), M(23),
M(24), M(25), M(26), M(27), M(28), M(29), M(30), M(31),
M(32)
}; // (add more if using more than 64 bits)
static int const divisors[] =
{
1, ~M(1), M(2), M(3), M(4), M(5), M(6), M(7),
M(8), M(9), M(10), M(11), M(12), M(13), M(14), M(15),
M(16), M(17), M(18), M(19), M(20), M(21), M(22), M(23),
M(24), M(25), M(26), M(27), M(28), M(29), M(30), M(31),
M(32)
}; // (add more for 64 bits)
#undef M
r = (x * multipliers[b]) / divisors[b];
</pre>
The following variation is not portable, but on architectures that employ an arithmetic right-shift, maintaining the sign, it should be fast.<br />
<pre>const int s = -b; // OR: sizeof(x) * CHAR_BIT - b;
r = (x << s) >> s;
</pre>
Randal E. Bryant pointed out a bug on May 3, 2005 in an earlier version (that used multipliers[] for divisors[]), where it failed on the case of x=1 and b=1.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ConditionalSetOrClearBitsWithoutBranching">Conditionally set or clear bits without branching</a></h3>
<pre>bool f; // conditional flag
unsigned int m; // the bit mask
unsigned int w; // the word to modify: if (f) w |= m; else w &= ~m;
w ^= (-f ^ w) & m;
// OR, for superscalar CPUs:
w = (w & ~m) | (-f & m);
</pre>
On some architectures, the lack of branching can more than make up for what appears to be twice as many operations. For instance, informal speed tests on an AMD Athlon™ XP 2100+ indicated it was 5-10% faster. An Intel Core 2 Duo ran the superscalar version about 16% faster than the first. Glenn Slayden informed me of the first expression on December 11, 2003. Marco Yu shared the superscalar version with me on April 3, 2007 and alerted me to a typo 2 days later.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ConditionalNegate">Conditionally negate a value without branching</a></h3>
If you need to negate only when a flag is false, then use the following to avoid branching:<br />
<pre>bool fDontNegate; // Flag indicating we should not negate v.
int v; // Input value to negate if fDontNegate is false.
int r; // result = fDontNegate ? v : -v;
r = (fDontNegate ^ (fDontNegate - 1)) * v;
</pre>
If you need to negate only when a flag is true, then use this:<br />
<pre>bool fNegate; // Flag indicating if we should negate v.
int v; // Input value to negate if fNegate is true.
int r; // result = fNegate ? -v : v;
r = (v ^ -fNegate) + fNegate;
</pre>
Avraham Plotnitzky suggested I add the first version on June 2, 2009. Motivated to avoid the multiply, I came up with the second version on June 8, 2009. Alfonso De Gregorio pointed out that some parens were missing on November 26, 2009, and received a bug bounty.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="MaskedMerge">Merge bits from two values according to a mask</a></h3>
<pre>unsigned int a; // value to merge in non-masked bits
unsigned int b; // value to merge in masked bits
unsigned int mask; // 1 where bits from b should be selected; 0 where from a.
unsigned int r; // result of (a & ~mask) | (b & mask) goes here
r = a ^ ((a ^ b) & mask);
</pre>
This shaves one operation from the obvious way of combining two sets of bits according to a bit mask. If the mask is a constant, then there may be no advantage.<br />
Ron Jeffery sent this to me on February 9, 2006.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="CountBitsSetNaive">Counting bits set (naive way)</a></h3>
<pre>unsigned int v; // count the number of bits set in v
unsigned int c; // c accumulates the total bits set in v
for (c = 0; v; v >>= 1)
{
c += v & 1;
}
</pre>
The naive approach requires one iteration per bit, until no more bits are set. So on a 32-bit word with only the high set, it will go through 32 iterations.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="CountBitsSetTable">Counting bits set by lookup table</a></h3>
<pre>static const unsigned char BitsSetTable256[256] =
{
# define B2(n) n, n+1, n+1, n+2
# define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2)
# define B6(n) B4(n), B4(n+1), B4(n+1), B4(n+2)
B6(0), B6(1), B6(1), B6(2)
};
unsigned int v; // count the number of bits set in 32-bit value v
unsigned int c; // c is the total bits set in v
// Option 1:
c = BitsSetTable256[v & 0xff] +
BitsSetTable256[(v >> 8) & 0xff] +
BitsSetTable256[(v >> 16) & 0xff] +
BitsSetTable256[v >> 24];
// Option 2:
unsigned char * p = (unsigned char *) &v;
c = BitsSetTable256[p[0]] +
BitsSetTable256[p[1]] +
BitsSetTable256[p[2]] +
BitsSetTable256[p[3]];
// To initially generate the table algorithmically:
BitsSetTable256[0] = 0;
for (int i = 0; i < 256; i++)
{
BitsSetTable256[i] = (i & 1) + BitsSetTable256[i / 2];
}
</pre>
On July 14, 2009 Hallvard Furuseth suggested the macro compacted table.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="CountBitsSetKernighan">Counting bits set, Brian Kernighan's way</a></h3>
<pre>unsigned int v; // count the number of bits set in v
unsigned int c; // c accumulates the total bits set in v
for (c = 0; v; c++)
{
v &= v - 1; // clear the least significant bit set
}
</pre>
Brian Kernighan's method goes through as many iterations as there are set bits. So if we have a 32-bit word with only the high bit set, then it will only go once through the loop.<br />
Published in 1988, the C Programming Language 2nd Ed. (by Brian W. Kernighan and Dennis M. Ritchie) mentions this in exercise 2-9. On April 19, 2006 Don Knuth pointed out to me that this method "was first published by Peter Wegner in CACM 3 (1960), 322. (Also discovered independently by Derrick Lehmer and published in 1964 in a book edited by Beckenbach.)"<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="CountBitsSet64">Counting bits set in 14, 24, or 32-bit words using 64-bit instructions</a></h3>
<pre>unsigned int v; // count the number of bits set in v
unsigned int c; // c accumulates the total bits set in v
// option 1, for at most 14-bit values in v:
c = (v * 0x200040008001ULL & 0x111111111111111ULL) % 0xf;
// option 2, for at most 24-bit values in v:
c = ((v & 0xfff) * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f;
c += (((v & 0xfff000) >> 12) * 0x1001001001001ULL & 0x84210842108421ULL)
% 0x1f;
// option 3, for at most 32-bit values in v:
c = ((v & 0xfff) * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f;
c += (((v & 0xfff000) >> 12) * 0x1001001001001ULL & 0x84210842108421ULL) %
0x1f;
c += ((v >> 24) * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f;
</pre>
This method requires a 64-bit CPU with fast modulus division to be efficient. The first option takes only 3 operations; the second option takes 10; and the third option takes 15.<br />
Rich Schroeppel originally created a 9-bit version, similiar to option 1; see the Programming Hacks section of <a href="http://www.inwap.com/pdp10/hbaker/hakmem/hakmem.html">Beeler, M., Gosper, R. W., and Schroeppel, R. HAKMEM. MIT AI Memo 239, Feb. 29, 1972.</a>His method was the inspiration for the variants above, devised by Sean Anderson. Randal E. Bryant offered a couple bug fixes on May 3, 2005. Bruce Dawson tweaked what had been a 12-bit version and made it suitable for 14 bits using the same number of operations on Feburary 1, 2007.<br />
<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="CountBitsSetParallel">Counting bits set, in parallel</a></h3>
<pre>unsigned int v; // count bits set in this (32-bit value)
unsigned int c; // store the total here
static const int S[] = {1, 2, 4, 8, 16}; // Magic Binary Numbers
static const int B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF};
c = v - ((v >> 1) & B[0]);
c = ((c >> S[1]) & B[1]) + (c & B[1]);
c = ((c >> S[2]) + c) & B[2];
c = ((c >> S[3]) + c) & B[3];
c = ((c >> S[4]) + c) & B[4];
</pre>
The B array, expressed as binary, is:<br />
<pre>B[0] = 0x55555555 = 01010101 01010101 01010101 01010101
B[1] = 0x33333333 = 00110011 00110011 00110011 00110011
B[2] = 0x0F0F0F0F = 00001111 00001111 00001111 00001111
B[3] = 0x00FF00FF = 00000000 11111111 00000000 11111111
B[4] = 0x0000FFFF = 00000000 00000000 11111111 11111111
</pre>
We can adjust the method for larger integer sizes by continuing with the patterns for the <em>Binary Magic Numbers,</em> B and S. If there are k bits, then we need the arrays S and B to be ceil(lg(k)) elements long, and we must compute the same number of expressions for c as S or B are long. For a 32-bit v, 16 operations are used.<br />
The best method for counting bits in a 32-bit integer v is the following:<br />
<pre>v = v - ((v >> 1) & 0x55555555); // reuse input as temporary
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
</pre>
The best bit counting method takes only 12 operations, which is the same as the lookup-table method, but avoids the memory and potential cache misses of a table. It is a hybrid between the purely parallel method above and the earlier methods using multiplies (in the section on counting bits with 64-bit instructions), though it doesn't use 64-bit instructions. The counts of bits set in the bytes is done in parallel, and the sum total of the bits set in the bytes is computed by multiplying by 0x1010101 and shifting right 24 bits.<br />
A generalization of the best bit counting method to integers of bit-widths upto 128 (parameterized by type T) is this:<br />
<pre>v = v - ((v >> 1) & (T)~(T)0/3); // temp
v = (v & (T)~(T)0/15*3) + ((v >> 2) & (T)~(T)0/15*3); // temp
v = (v + (v >> 4)) & (T)~(T)0/255*15; // temp
c = (T)(v * ((T)~(T)0/255)) >> (sizeof(T) - 1) * CHAR_BIT; // count
</pre>
See <a href="http://groups.google.com/groups?q=reverse+bits&num=100&hl=en&group=comp.graphics.algorithms&imgsafe=off&safe=off&rnum=2&ic=1&selm=4fulhm%248dn%40atlas.uniserve.com">Ian Ashdown's nice newsgroup post</a> for more information on counting the number of bits set (also known as <em>sideways addition</em>). The best bit counting method was brought to my attention on October 5, 2005 by <a href="http://onezero.org/">Andrew Shapira</a>; he found it in pages 187-188 of <a href="http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25112.PDF">Software Optimization Guide for AMD Athlon™ 64 and Opteron™ Processors</a>. Charlie Gordon suggested a way to shave off one operation from the purely parallel version on December 14, 2005, and Don Clugston trimmed three more from it on December 30, 2005. I made a typo with Don's suggestion that Eric Cole spotted on January 8, 2006. Eric later suggested the arbitrary bit-width generalization to the best method on November 17, 2006. On April 5, 2007, Al Williams observed that I had a line of dead code at the top of the first method.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="#CountBitsFromMSBToPos">Count bits set (rank) from the most-significant bit upto a given position</a></h3>
The following finds the the rank of a bit, meaning it returns the sum of bits that are set to 1 from the most-signficant bit downto the bit at the given position.<br />
<pre> uint64_t v; // Compute the rank (bits set) in v from the MSB to pos.
unsigned int pos; // Bit position to count bits upto.
uint64_t r; // Resulting rank of bit at pos goes here.
// Shift out bits after given position.
r = v >> (sizeof(v) * CHAR_BIT - pos);
// Count set bits in parallel.
// r = (r & 0x5555...) + ((r >> 1) & 0x5555...);
r = r - ((r >> 1) & ~0UL/3);
// r = (r & 0x3333...) + ((r >> 2) & 0x3333...);
r = (r & ~0UL/5) + ((r >> 2) & ~0UL/5);
// r = (r & 0x0f0f...) + ((r >> 4) & 0x0f0f...);
r = (r + (r >> 4)) & ~0UL/17;
// r = r % 255;
r = (r * (~0UL/255)) >> ((sizeof(v) - 1) * CHAR_BIT);
</pre>
Juha Järvi sent this to me on November 21, 2009 as an inverse operation to the computing the bit position with the given rank, which follows.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="#SelectPosFromMSBRank">Select the bit position (from the most-significant bit) with the given count (rank)</a></h3>
The following 64-bit code selects the position of the r<sup>th</sup> 1 bit when counting from the left. In other words if we start at the most significant bit and proceed to the right, counting the number of bits set to 1 until we reach the desired rank, r, then the position where we stop is returned. If the rank requested exceeds the count of bits set, then 64 is returned. The code may be modified for 32-bit or counting from the right.<br />
<pre> uint64_t v; // Input value to find position with rank r.
unsigned int r; // Input: bit's desired rank [1-64].
unsigned int s; // Output: Resulting position of bit with rank r [1-64]
uint64_t a, b, c, d; // Intermediate temporaries for bit count.
unsigned int t; // Bit count temporary.
// Do a normal parallel bit count for a 64-bit integer,
// but store all intermediate steps.
// a = (v & 0x5555...) + ((v >> 1) & 0x5555...);
a = v - ((v >> 1) & ~0UL/3);
// b = (a & 0x3333...) + ((a >> 2) & 0x3333...);
b = (a & ~0UL/5) + ((a >> 2) & ~0UL/5);
// c = (b & 0x0f0f...) + ((b >> 4) & 0x0f0f...);
c = (b + (b >> 4)) & ~0UL/0x11;
// d = (c & 0x00ff...) + ((c >> 8) & 0x00ff...);
d = (c + (c >> 8)) & ~0UL/0x101;
t = (d >> 32) + (d >> 48);
// Now do branchless select!
s = 64;
// if (r > t) {s -= 32; r -= t;}
s -= ((t - r) & 256) >> 3; r -= (t & ((t - r) >> 8));
t = (d >> (s - 16)) & 0xff;
// if (r > t) {s -= 16; r -= t;}
s -= ((t - r) & 256) >> 4; r -= (t & ((t - r) >> 8));
t = (c >> (s - 8)) & 0xf;
// if (r > t) {s -= 8; r -= t;}
s -= ((t - r) & 256) >> 5; r -= (t & ((t - r) >> 8));
t = (b >> (s - 4)) & 0x7;
// if (r > t) {s -= 4; r -= t;}
s -= ((t - r) & 256) >> 6; r -= (t & ((t - r) >> 8));
t = (a >> (s - 2)) & 0x3;
// if (r > t) {s -= 2; r -= t;}
s -= ((t - r) & 256) >> 7; r -= (t & ((t - r) >> 8));
t = (v >> (s - 1)) & 0x1;
// if (r > t) s--;
s -= ((t - r) & 256) >> 8;
s = 65 - s;
</pre>
If branching is fast on your target CPU, consider uncommenting the if-statements and commenting the lines that follow them.<br />
Juha Järvi sent this to me on November 21, 2009.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ParityNaive">Computing parity the naive way</a></h3>
<pre>unsigned int v; // word value to compute the parity of
bool parity = false; // parity will be the parity of v
while (v)
{
parity = !parity;
v = v & (v - 1);
}
</pre>
The above code uses an approach like Brian Kernigan's bit counting, above. The time it takes is proportional to the number of bits set.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ParityLookupTable">Compute parity by lookup table</a></h3>
<pre>static const bool ParityTable256[256] =
{
# define P2(n) n, n^1, n^1, n
# define P4(n) P2(n), P2(n^1), P2(n^1), P2(n)
# define P6(n) P4(n), P4(n^1), P4(n^1), P4(n)
P6(0), P6(1), P6(1), P6(0)
};
unsigned char b; // byte value to compute the parity of
bool parity = ParityTable256[b];
// OR, for 32-bit words:
unsigned int v;
v ^= v >> 16;
v ^= v >> 8;
bool parity = ParityTable256[v & 0xff];
// Variation:
unsigned char * p = (unsigned char *) &v;
parity = ParityTable256[p[0] ^ p[1] ^ p[2] ^ p[3]];
</pre>
Randal E. Bryant encouraged the addition of the (admittedly) obvious last variation with variable p on May 3, 2005. Bruce Rawles found a typo in an instance of the table variable's name on September 27, 2005, and he received a $10 bug bounty. On October 9, 2006, Fabrice Bellard suggested the 32-bit variations above, which require only one table lookup; the previous version had four lookups (one per byte) and were slower. On July 14, 2009 Hallvard Furuseth suggested the macro compacted table.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ParityWith64Bits">Compute parity of a byte using 64-bit multiply and modulus division</a></h3>
<pre>unsigned char b; // byte value to compute the parity of
bool parity =
(((b * 0x0101010101010101ULL) & 0x8040201008040201ULL) % 0x1FF) & 1;
</pre>
The method above takes around 4 operations, but only works on bytes.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="#ParityMultiply">Compute parity of word with a multiply</a></h3>
The following method computes the parity of the 32-bit value in only 8 operations using a multiply.<br />
<pre> unsigned int v; // 32-bit word
v ^= v >> 1;
v ^= v >> 2;
v = (v & 0x11111111U) * 0x11111111U;
return (v >> 28) & 1;
</pre>
Also for 64-bits, 8 operations are still enough.<br />
<pre> unsigned long long v; // 64-bit word
v ^= v >> 1;
v ^= v >> 2;
v = (v & 0x1111111111111111UL) * 0x1111111111111111UL;
return (v >> 60) & 1;
</pre>
Andrew Shapira came up with this and sent it to me on Sept. 2, 2007.<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ParityParallel">Compute parity in parallel</a></h3>
<pre>unsigned int v; // word value to compute the parity of
v ^= v >> 16;
v ^= v >> 8;
v ^= v >> 4;
v &= 0xf;
return (0x6996 >> v) & 1;
</pre>
The method above takes around 9 operations, and works for 32-bit words. It may be optimized to work just on bytes in 5 operations by removing the two lines immediately following "unsigned int v;". The method first shifts and XORs the eight nibbles of the 32-bit value together, leaving the result in the lowest nibble of v. Next, the binary number 0110 1001 1001 0110 (0x6996 in hex) is shifted to the right by the value represented in the lowest nibble of v. This number is like a miniature 16-bit parity-table indexed by the low four bits in v. The result has the parity of v in bit 1, which is masked and returned.<br />
Thanks to Mathew Hendry for pointing out the shift-lookup idea at the end on Dec. 15, 2002. That optimization shaves two operations off using only shifting and XORing to find the parity.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="SwappingValuesSubAdd">Swapping values with subtraction and addition</a></h3>
<pre>#define SWAP(a, b) ((&(a) == &(b)) || \
(((a) -= (b)), ((b) += (a)), ((a) = (b) - (a))))
</pre>
This swaps the values of a and b <em>without using a temporary variable.</em> The initial check for a and b being the same location in memory may be omitted when you know this can't happen. (The compiler may omit it anyway as an optimization.) If you enable overflows exceptions, then pass unsigned values so an exception isn't thrown. The XOR method that follows may be slightly faster on some machines. Don't use this with floating-point numbers (unless you operate on their raw integer representations).<br />
Sanjeev Sivasankaran suggested I add this on June 12, 2007. Vincent Lefèvre pointed out the potential for overflow exceptions on July 9, 2008<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="SwappingValuesXOR">Swapping values with XOR</a></h3>
<pre>#define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b)))
</pre>
This is an old trick to exchange the values of the variables a and b <em>without using extra space for a temporary variable</em>.<br />
On January 20, 2005, Iain A. Fleming pointed out that the macro above doesn't work when you swap with the same memory location, such as SWAP(a[i], a[j]) with i == j. So if that may occur, consider defining the macro as (((a) == (b)) || (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b)))). On July 14, 2009, Hallvard Furuseth suggested that on some machines, (((a) ^ (b)) && ((b) ^= (a) ^= (b), (a) ^= (b))) might be faster, since the (a) ^ (b) expression is reused.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="SwappingBitsXOR">Swapping individual bits with XOR</a></h3>
<pre>unsigned int i, j; // positions of bit sequences to swap
unsigned int n; // number of consecutive bits in each sequence
unsigned int b; // bits to swap reside in b
unsigned int r; // bit-swapped result goes here
unsigned int x = ((b >> i) ^ (b >> j)) & ((1U << n) - 1); // XOR temporary
r = b ^ ((x << i) | (x << j));
</pre>
As an example of swapping ranges of bits suppose we have have b = <b>001</b>0<b>111</b>1 (expressed in binary) and we want to swap the n = 3 consecutive bits starting at i = 1 (the second bit from the right) with the 3 consecutive bits starting at j = 5; the result would be r = <b>111</b>0<b>001</b>1 (binary).<br />
This method of swapping is similar to the general purpose XOR swap trick, but intended for operating on individual bits. The variable x stores the result of XORing the pairs of bit values we want to swap, and then the bits are set to the result of themselves XORed with x. Of course, the result is undefined if the sequences overlap.<br />
On July 14, 2009 Hallvard Furuseth suggested that I change the 1 << n to 1U << n because the value was being assigned to an unsigned and to avoid shifting into a sign bit.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="BitReverseObvious">Reverse bits the obvious way</a></h3>
<pre>unsigned int v; // input bits to be reversed
unsigned int r = v; // r will be reversed bits of v; first get LSB of v
int s = sizeof(v) * CHAR_BIT - 1; // extra shift needed at end
for (v >>= 1; v; v >>= 1)
{
r <<= 1;
r |= v & 1;
s--;
}
r <<= s; // shift when v's highest bits are zero
</pre>
On October 15, 2004, Michael Hoisie pointed out a bug in the original version. Randal E. Bryant suggested removing an extra operation on May 3, 2005. Behdad Esfabod suggested a slight change that eliminated one iteration of the loop on May 18, 2005. Then, on February 6, 2007, Liyong Zhou suggested a better version that loops while v is not 0, so rather than iterating over all bits it stops early.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="BitReverseTable">Reverse bits in word by lookup table</a></h3>
<pre>static const unsigned char BitReverseTable256[256] =
{
# define R2(n) n, n + 2*64, n + 1*64, n + 3*64
# define R4(n) R2(n), R2(n + 2*16), R2(n + 1*16), R2(n + 3*16)
# define R6(n) R4(n), R4(n + 2*4 ), R4(n + 1*4 ), R4(n + 3*4 )
R6(0), R6(2), R6(1), R6(3)
};
unsigned int v; // reverse 32-bit value, 8 bits at time
unsigned int c; // c will get v reversed
// Option 1:
c = (BitReverseTable256[v & 0xff] << 24) |
(BitReverseTable256[(v >> 8) & 0xff] << 16) |
(BitReverseTable256[(v >> 16) & 0xff] << 8) |
(BitReverseTable256[(v >> 24) & 0xff]);
// Option 2:
unsigned char * p = (unsigned char *) &v;
unsigned char * q = (unsigned char *) &c;
q[3] = BitReverseTable256[p[0]];
q[2] = BitReverseTable256[p[1]];
q[1] = BitReverseTable256[p[2]];
q[0] = BitReverseTable256[p[3]];
</pre>
The first method takes about 17 operations, and the second takes about 12, assuming your CPU can load and store bytes easily.<br />
On July 14, 2009 Hallvard Furuseth suggested the macro compacted table.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ReverseByteWith64BitsDiv">Reverse the bits in a byte with 3 operations (64-bit multiply and modulus division):</a></h3>
<pre>unsigned char b; // reverse this (8-bit) byte
b = (b * 0x0202020202ULL & 0x010884422010ULL) % 1023;
</pre>
The multiply operation creates five separate copies of the 8-bit byte pattern to fan-out into a 64-bit value. The AND operation selects the bits that are in the correct (reversed) positions, relative to each 10-bit groups of bits. The multiply and the AND operations copy the bits from the original byte so they each appear in only one of the 10-bit sets. The reversed positions of the bits from the original byte coincide with their relative positions within any 10-bit set. The last step, which involves modulus division by 2^10 - 1, has the effect of merging together each set of 10 bits (from positions 0-9, 10-19, 20-29, ...) in the 64-bit value. They do not overlap, so the addition steps underlying the modulus division behave like or operations.<br />
This method was attributed to Rich Schroeppel in the Programming Hacks section of <a href="http://www.inwap.com/pdp10/hbaker/hakmem/hakmem.html">Beeler, M., Gosper, R. W., and Schroeppel, R. HAKMEM. MIT AI Memo 239, Feb. 29, 1972.</a><br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ReverseByteWith64Bits">Reverse the bits in a byte with 4 operations (64-bit multiply, no division):</a></h3>
<pre>unsigned char b; // reverse this byte
b = ((b * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
</pre>
The following shows the flow of the bit values with the boolean variables <code>a, b, c, d, e, f, g,</code> and <code>h</code>, which comprise an 8-bit byte. Notice how the first multiply fans out the bit pattern to multiple copies, while the last multiply combines them in the fifth byte from the right.<span></span><br />
<pre> abcd efgh (-> hgfe dcba)
* 1000 0000 0010 0000 0000 1000 0000 0010 (0x80200802)
-------------------------------------------------------------------------------------------------
0abc defg h00a bcde fgh0 0abc defg h00a bcde fgh0
& 0000 1000 1000 0100 0100 0010 0010 0001 0001 0000 (0x0884422110)
-------------------------------------------------------------------------------------------------
0000 d000 h000 0c00 0g00 00b0 00f0 000a 000e 0000
* 0000 0001 0000 0001 0000 0001 0000 0001 0000 0001 (0x0101010101)
-------------------------------------------------------------------------------------------------
0000 d000 h000 0c00 0g00 00b0 00f0 000a 000e 0000
0000 d000 h000 0c00 0g00 00b0 00f0 000a 000e 0000
0000 d000 h000 0c00 0g00 00b0 00f0 000a 000e 0000
0000 d000 h000 0c00 0g00 00b0 00f0 000a 000e 0000
0000 d000 h000 0c00 0g00 00b0 00f0 000a 000e 0000
-------------------------------------------------------------------------------------------------
0000 d000 h000 dc00 hg00 dcb0 hgf0 dcba hgfe dcba hgfe 0cba 0gfe 00ba 00fe 000a 000e 0000
>> 32
-------------------------------------------------------------------------------------------------
0000 d000 h000 dc00 hg00 dcb0 hgf0 dcba hgfe dcba
& 1111 1111
-------------------------------------------------------------------------------------------------
hgfe dcba
</pre>
<span></span>Note that the last two steps can be combined on some processors because the registers can be accessed as bytes; just multiply so that a register stores the upper 32 bits of the result and the take the low byte. Thus, it may take only 6 operations.<br />
Devised by Sean Anderson, July 13, 2001.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ReverseByteWith32Bits">Reverse the bits in a byte with 7 operations (no 64-bit):</a></h3>
<pre>b = ((b * 0x0802LU & 0x22110LU) | (b * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
</pre>
Make sure you assign or cast the result to an unsigned char to remove garbage in the higher bits. Devised by Sean Anderson, July 13, 2001. Typo spotted and correction supplied by Mike Keith, January 3, 2002.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ReverseParallel">Reverse an N-bit quantity in parallel in 5 * lg(N) operations:</a></h3>
<pre>unsigned int v; // 32-bit word to reverse bit order
// swap odd and even bits
v = ((v >> 1) & 0x55555555) | ((v & 0x55555555) << 1);
// swap consecutive pairs
v = ((v >> 2) & 0x33333333) | ((v & 0x33333333) << 2);
// swap nibbles ...
v = ((v >> 4) & 0x0F0F0F0F) | ((v & 0x0F0F0F0F) << 4);
// swap bytes
v = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
// swap 2-byte long pairs
v = ( v >> 16 ) | ( v << 16);
</pre>
The following variation is also O(lg(N)), however it requires more operations to reverse v. Its virtue is in taking less slightly memory by computing the constants on the fly.<br />
<pre>unsigned int s = sizeof(v) * CHAR_BIT; // bit size; must be power of 2
unsigned int mask = ~0;
while ((s >>= 1) > 0)
{
mask ^= (mask << s);
v = ((v >> s) & mask) | ((v << s) & ~mask);
}
</pre>
These methods above are best suited to situations where N is large. If you use the above with 64-bit ints (or larger), then you need to add more lines (following the pattern); otherwise only the lower 32 bits will be reversed and the result will be in the lower 32 bits.<br />
See Dr. Dobb's Journal 1983, Edwin Freed's article on Binary Magic Numbers for more information. The second variation was suggested by Ken Raeburn on September 13, 2005. Veldmeijer mentioned that the first version could do without ANDS in the last line on March 19, 2006.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ModulusDivisionEasy">Compute modulus division by 1 << s without a division operator</a></h3>
<pre>const unsigned int n; // numerator
const unsigned int s;
const unsigned int d = 1U << s; // So d will be one of: 1, 2, 4, 8, 16, 32, ...
unsigned int m; // m will be n % d
m = n & (d - 1);
</pre>
Most programmers learn this trick early, but it was included for the sake of completeness.<br />
<br />
<hr />
<br />
<h3>
<a href="https://www.blogger.com/null" name="ModulusDivision">Compute modulus division by (1 << s) - 1 without a division operator</a></h3>
<pre>unsigned int n; // numerator
const unsigned int s; // s > 0
const unsigned int d = (1 << s) - 1; // so d is either 1, 3, 7, 15, 31, ...).
unsigned int m; // n % d goes here.
for (m = n; n > d; n = m)
{
for (m = 0; n; n >>= s)
{
m += n & d;
}
}
// Now m is a value from 0 to d, but since with modulus division
// we want m to be 0 when it is d.
m = m == d ? 0 : m;
</pre>
This method of modulus division by an integer that is one less than a power of 2 takes at most 5 + (4 + 5 * ceil(N / s)) * ceil(lg(N / s)) operations, where N is the number of bits in the numerator. In other words, it takes at most O(N * lg(N)) time.<br />
Devised by Sean Anderson, August 15, 2001. Before Sean A. Irvine corrected me on June 17, 2004, I mistakenly commented that we could alternatively assign <code>m = ((m + 1) & d) - 1;</code> at the end. Michael Miller spotted a typo in the code April 25, 2005.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ModulusDivisionParallel">Compute modulus division by (1 << s) - 1 in parallel without a division operator</a></h3>
<pre>// The following is for a word size of 32 bits!
static const unsigned int M[] =
{
0x00000000, 0x55555555, 0x33333333, 0xc71c71c7,
0x0f0f0f0f, 0xc1f07c1f, 0x3f03f03f, 0xf01fc07f,
0x00ff00ff, 0x07fc01ff, 0x3ff003ff, 0xffc007ff,
0xff000fff, 0xfc001fff, 0xf0003fff, 0xc0007fff,
0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff
};
static const unsigned int Q[][6] =
{
{ 0, 0, 0, 0, 0, 0}, {16, 8, 4, 2, 1, 1}, {16, 8, 4, 2, 2, 2},
{15, 6, 3, 3, 3, 3}, {16, 8, 4, 4, 4, 4}, {15, 5, 5, 5, 5, 5},
{12, 6, 6, 6 , 6, 6}, {14, 7, 7, 7, 7, 7}, {16, 8, 8, 8, 8, 8},
{ 9, 9, 9, 9, 9, 9}, {10, 10, 10, 10, 10, 10}, {11, 11, 11, 11, 11, 11},
{12, 12, 12, 12, 12, 12}, {13, 13, 13, 13, 13, 13}, {14, 14, 14, 14, 14, 14},
{15, 15, 15, 15, 15, 15}, {16, 16, 16, 16, 16, 16}, {17, 17, 17, 17, 17, 17},
{18, 18, 18, 18, 18, 18}, {19, 19, 19, 19, 19, 19}, {20, 20, 20, 20, 20, 20},
{21, 21, 21, 21, 21, 21}, {22, 22, 22, 22, 22, 22}, {23, 23, 23, 23, 23, 23},
{24, 24, 24, 24, 24, 24}, {25, 25, 25, 25, 25, 25}, {26, 26, 26, 26, 26, 26},
{27, 27, 27, 27, 27, 27}, {28, 28, 28, 28, 28, 28}, {29, 29, 29, 29, 29, 29},
{30, 30, 30, 30, 30, 30}, {31, 31, 31, 31, 31, 31}
};
static const unsigned int R[][6] =
{
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x0000ffff, 0x000000ff, 0x0000000f, 0x00000003, 0x00000001, 0x00000001},
{0x0000ffff, 0x000000ff, 0x0000000f, 0x00000003, 0x00000003, 0x00000003},
{0x00007fff, 0x0000003f, 0x00000007, 0x00000007, 0x00000007, 0x00000007},
{0x0000ffff, 0x000000ff, 0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f},
{0x00007fff, 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f},
{0x00000fff, 0x0000003f, 0x0000003f, 0x0000003f, 0x0000003f, 0x0000003f},
{0x00003fff, 0x0000007f, 0x0000007f, 0x0000007f, 0x0000007f, 0x0000007f},
{0x0000ffff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff},
{0x000001ff, 0x000001ff, 0x000001ff, 0x000001ff, 0x000001ff, 0x000001ff},
{0x000003ff, 0x000003ff, 0x000003ff, 0x000003ff, 0x000003ff, 0x000003ff},
{0x000007ff, 0x000007ff, 0x000007ff, 0x000007ff, 0x000007ff, 0x000007ff},
{0x00000fff, 0x00000fff, 0x00000fff, 0x00000fff, 0x00000fff, 0x00000fff},
{0x00001fff, 0x00001fff, 0x00001fff, 0x00001fff, 0x00001fff, 0x00001fff},
{0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff},
{0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff},
{0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff},
{0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff},
{0x0003ffff, 0x0003ffff, 0x0003ffff, 0x0003ffff, 0x0003ffff, 0x0003ffff},
{0x0007ffff, 0x0007ffff, 0x0007ffff, 0x0007ffff, 0x0007ffff, 0x0007ffff},
{0x000fffff, 0x000fffff, 0x000fffff, 0x000fffff, 0x000fffff, 0x000fffff},
{0x001fffff, 0x001fffff, 0x001fffff, 0x001fffff, 0x001fffff, 0x001fffff},
{0x003fffff, 0x003fffff, 0x003fffff, 0x003fffff, 0x003fffff, 0x003fffff},
{0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff},
{0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff},
{0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff},
{0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff},
{0x07ffffff, 0x07ffffff, 0x07ffffff, 0x07ffffff, 0x07ffffff, 0x07ffffff},
{0x0fffffff, 0x0fffffff, 0x0fffffff, 0x0fffffff, 0x0fffffff, 0x0fffffff},
{0x1fffffff, 0x1fffffff, 0x1fffffff, 0x1fffffff, 0x1fffffff, 0x1fffffff},
{0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff},
{0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}
};
unsigned int n; // numerator
const unsigned int s; // s > 0
const unsigned int d = (1 << s) - 1; // so d is either 1, 3, 7, 15, 31, ...).
unsigned int m; // n % d goes here.
m = (n & M[s]) + ((n >> s) & M[s]);
for (const unsigned int * q = &Q[s][0], * r = &R[s][0]; m > d; q++, r++)
{
m = (m >> *q) + (m & *r);
}
m = m == d ? 0 : m; // OR, less portably: m = m & -((signed)(m - d) >> s);
</pre>
This method of finding modulus division by an integer that is one less than a power of 2 takes at most O(lg(N)) time, where N is the number of bits in the numerator (32 bits, for the code above). The number of operations is at most 12 + 9 * ceil(lg(N)). The tables may be removed if you know the denominator at compile time; just extract the few relevent entries and unroll the loop. It may be easily extended to more bits.<br />
It finds the result by summing the values in base (1 << s) in parallel. First every other base (1 << s) value is added to the previous one. Imagine that the result is written on a piece of paper. Cut the paper in half, so that half the values are on each cut piece. Align the values and sum them onto a new piece of paper. Repeat by cutting this paper in half (which will be a quarter of the size of the previous one) and summing, until you cannot cut further. After performing lg(N/s/2) cuts, we cut no more; just continue to add the values and put the result onto a new piece of paper as before, while there are at least two s-bit values.<br />
Devised by Sean Anderson, August 20, 2001. A typo was spotted by Randy E. Bryant on May 3, 2005 (after pasting the code, I had later added "unsinged" to a variable declaration). As in the previous hack, I mistakenly commented that we could alternatively assign <code>m = ((m + 1) & d) - 1;</code> at the end, and Don Knuth corrected me on April 19, 2006 and suggested <code>m = m & -((signed)(m - d) >> s)</code>. On June 18, 2009 Sean Irvine proposed a change that used <code>((n >> s) & M[s])</code> instead of <code>((n & ~M[s]) >> s)</code>, which typically requires fewer operations because the M[s] constant is already loaded.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="IntegerLogObvious">Find the log base 2 of an integer with the MSB N set in O(N) operations (the obvious way)</a></h3>
<pre>unsigned int v; // 32-bit word to find the log base 2 of
unsigned int r = 0; // r will be lg(v)
while (v >>= 1) // unroll for more speed...
{
r++;
}
</pre>
The log base 2 of an integer is the same as the position of the highest bit set (or most significant bit set, MSB). The following log base 2 methods are faster than this one.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="IntegerLogIEEE64Float">Find the integer log base 2 of an integer with an 64-bit IEEE float</a></h3>
<pre>int v; // 32-bit integer to find the log base 2 of
int r; // result of log_2(v) goes here
union { unsigned int u[2]; double d; } t; // temp
t.u[__FLOAT_WORD_ORDER==LITTLE_ENDIAN] = 0x43300000;
t.u[__FLOAT_WORD_ORDER!=LITTLE_ENDIAN] = v;
t.d -= 4503599627370496.0;
r = (t.u[__FLOAT_WORD_ORDER==LITTLE_ENDIAN] >> 20) - 0x3FF;
</pre>
The code above loads a 64-bit (IEEE-754 floating-point) double with a 32-bit integer (with no paddding bits) by storing the integer in the mantissa while the exponent is set to 2<sup>52</sup>. From this newly minted double, 2<sup>52</sup> (expressed as a double) is subtracted, which sets the resulting exponent to the log base 2 of the input value, v. All that is left is shifting the exponent bits into position (20 bits right) and subtracting the bias, 0x3FF (which is 1023 decimal). This technique only takes 5 operations, but many CPUs are slow at manipulating doubles, and the endianess of the architecture must be accommodated.<br />
Eric Cole sent me this on January 15, 2006. Evan Felix pointed out a typo on April 4, 2006. Vincent Lefèvre told me on July 9, 2008 to change the endian check to use the float's endian, which could differ from the integer's endian.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="IntegerLogLookup">Find the log base 2 of an integer with a lookup table</a></h3>
<pre>static const char LogTable256[256] =
{
#define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n
-1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6),
LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7)
};
unsigned int v; // 32-bit word to find the log of
unsigned r; // r will be lg(v)
register unsigned int t, tt; // temporaries
if (tt = v >> 16)
{
r = (t = tt >> 8) ? 24 + LogTable256[t] : 16 + LogTable256[tt];
}
else
{
r = (t = v >> 8) ? 8 + LogTable256[t] : LogTable256[v];
}
</pre>
The lookup table method takes only about 7 operations to find the log of a 32-bit value. If extended for 64-bit quantities, it would take roughly 9 operations. Another operation can be trimmed off by using four tables, with the possible additions incorporated into each. Using int table elements may be faster, depending on your architecture.<br />
The code above is tuned to uniformly distributed <em>output</em> values. If your <em>inputs</em> are evenly distributed across all 32-bit values, then consider using the following:<br />
<pre>if (tt = v >> 24)
{
r = 24 + LogTable256[tt];
}
else if (tt = v >> 16)
{
r = 16 + LogTable256[tt];
}
else if (tt = v >> 8)
{
r = 8 + LogTable256[tt];
}
else
{
r = LogTable256[v];
}
</pre>
To initially generate the log table algorithmically:<br />
<pre>LogTable256[0] = LogTable256[1] = 0;
for (int i = 2; i < 256; i++)
{
LogTable256[i] = 1 + LogTable256[i / 2];
}
LogTable256[0] = -1; // if you want log(0) to return -1
</pre>
Behdad Esfahbod and I shaved off a fraction of an operation (on average) on May 18, 2005. Yet another fraction of an operation was removed on November 14, 2006 by Emanuel Hoogeveen. The variation that is tuned to evenly distributed input values was suggested by David A. Butterfield on September 19, 2008. Venkat Reddy told me on January 5, 2009 that log(0) should return -1 to indicate an error, so I changed the first entry in the table to that.<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="IntegerLog">Find the log base 2 of an N-bit integer in O(lg(N)) operations</a></h3>
<pre>unsigned int v; // 32-bit value to find the log2 of
const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
const unsigned int S[] = {1, 2, 4, 8, 16};
int i;
register unsigned int r = 0; // result of log2(v) will go here
for (i = 4; i >= 0; i--) // unroll for speed...
{
if (v & b[i])
{
v >>= S[i];
r |= S[i];
}
}
// OR (IF YOUR CPU BRANCHES SLOWLY):
unsigned int v; // 32-bit value to find the log2 of
register unsigned int r; // result of log2(v) will go here
register unsigned int shift;
r = (v > 0xFFFF) << 4; v >>= r;
shift = (v > 0xFF ) << 3; v >>= shift; r |= shift;
shift = (v > 0xF ) << 2; v >>= shift; r |= shift;
shift = (v > 0x3 ) << 1; v >>= shift; r |= shift;
r |= (v >> 1);
// OR (IF YOU KNOW v IS A POWER OF 2):
unsigned int v; // 32-bit value to find the log2 of
static const unsigned int b[] = {0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0,
0xFF00FF00, 0xFFFF0000};
register unsigned int r = (v & b[0]) != 0;
for (i = 4; i > 0; i--) // unroll for speed...
{
r |= ((v & b[i]) != 0) << i;
}
</pre>
Of course, to extend the code to find the log of a 33- to 64-bit number, we would append another element, 0xFFFFFFFF00000000, to b, append 32 to S, and loop from 5 to 0. This method is much slower than the earlier table-lookup version, but if you don't want big table or your architecture is slow to access memory, it's a good choice. The second variation involves slightly more operations, but it may be faster on machines with high branch costs (e.g. PowerPC).<br />
The second version was sent to me by <a href="http://www.balance-software.com/ec/">Eric Cole</a> on January 7, 2006. Andrew Shapira subsequently trimmed a few operations off of it and sent me his variation (above) on Sept. 1, 2007. The third variation was suggested to me by <a href="http://www.ece.ucdavis.edu/~jowens/">John Owens</a> on April 24, 2002; it's faster, but <em>it is only suitable when the input is known to be a power of 2</em>. On May 25, 2003, Ken Raeburn suggested improving the general case by using smaller numbers for b[], which load faster on some architectures (for instance if the word size is 16 bits, then only one load instruction may be needed). These values work for the general version, but not for the special-case version below it, where v is a power of 2; Glenn Slayden brought this oversight to my attention on December 12, 2003.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="IntegerLogDeBruijn">Find the log base 2 of an N-bit integer in O(lg(N)) operations with multiply and lookup</a></h3>
<pre>uint32_t v; // find the log base 2 of 32-bit v
int r; // result goes here
static const int MultiplyDeBruijnBitPosition[32] =
{
0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
};
v |= v >> 1; // first round down to one less than a power of 2
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
r = MultiplyDeBruijnBitPosition[(uint32_t)(v * 0x07C4ACDDU) >> 27];
</pre>
The code above computes the log base 2 of a 32-bit integer with a small table lookup and multiply. It requires only 13 operations, compared to (up to) 20 for the previous method. The purely table-based method requires the fewest operations, but this offers a reasonable compromise between table size and speed.<br />
If you know that v is a power of 2, then you only need the following:<br />
<pre>static const int MultiplyDeBruijnBitPosition2[32] =
{
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
};
r = MultiplyDeBruijnBitPosition2[(uint32_t)(v * 0x077CB531U) >> 27];
</pre>
Eric Cole devised this January 8, 2006 after reading about the entry below to <a href="http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2">round up to a power of 2</a> and the method below for <a href="http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup">computing the number of trailing bits with a multiply and lookup</a> using a DeBruijn sequence. On December 10, 2009, Mark Dickinson shaved off a couple operations by requiring v be rounded up to one less than the next power of 2 rather than the power of 2.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="IntegerLog10">Find integer log base 10 of an integer</a></h3>
<pre>unsigned int v; // non-zero 32-bit integer value to compute the log base 10 of
int r; // result goes here
int t; // temporary
static unsigned int const PowersOf10[] =
{1, 10, 100, 1000, 10000, 100000,
1000000, 10000000, 100000000, 1000000000};
t = (IntegerLogBase2(v) + 1) * 1233 >> 12; // (use a lg2 method from above)
r = t - (v < PowersOf10[t]);
</pre>
The integer log base 10 is computed by first using one of the techniques above for finding the log base 2. By the relationship log<sub>10</sub>(v) = log<sub>2</sub>(v) / log<sub>2</sub>(10), we need to multiply it by 1/log<sub>2</sub>(10), which is approximately 1233/4096, or 1233 followed by a right shift of 12. Adding one is needed because the IntegerLogBase2 rounds down. Finally, since the value t is only an approximation that may be off by one, the exact value is found by subtracting the result of v < PowersOf10[t].<br />
This method takes 6 more operations than IntegerLogBase2. It may be sped up (on machines with fast memory access) by modifying the log base 2 table-lookup method above so that the entries hold what is computed for t (that is, pre-add, -mulitply, and -shift). Doing so would require a total of only 9 operations to find the log base 10, assuming 4 tables were used (one for each byte of v).<br />
Eric Cole suggested I add a version of this on January 7, 2006.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="IntegerLog10Obvious">Find integer log base 10 of an integer the obvious way</a></h3>
<pre>unsigned int v; // non-zero 32-bit integer value to compute the log base 10 of
int r; // result goes here
r = (v >= 1000000000) ? 9 : (v >= 100000000) ? 8 : (v >= 10000000) ? 7 :
(v >= 1000000) ? 6 : (v >= 100000) ? 5 : (v >= 10000) ? 4 :
(v >= 1000) ? 3 : (v >= 100) ? 2 : (v >= 10) ? 1 : 0;
</pre>
This method works well when the input is uniformly distributed over 32-bit values because 76% of the inputs are caught by the first compare, 21% are caught by the second compare, 2% are caught by the third, and so on (chopping the remaining down by 90% with each comparision). As a result, less than 2.6 operations are needed on average.<br />
On April 18, 2007, Emanuel Hoogeveen suggested a variation on this where the conditions used divisions, which were not as fast as simple comparisons.<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="IntegerLogFloat">Find integer log base 2 of a 32-bit IEEE float</a></h3>
<pre>const float v; // find int(log2(v)), where v > 0.0 && finite(v) && isnormal(v)
int c; // 32-bit int c gets the result;
c = *(const int *) &v; // OR, for portability: memcpy(&c, &v, sizeof c);
c = (c >> 23) - 127;
</pre>
The above is fast, but IEEE 754-compliant architectures utilize <em>subnormal</em> (also called <em>denormal</em>) floating point numbers. These have the exponent bits set to zero (signifying pow(2,-127)), and the mantissa is not normalized, so it contains leading zeros and thus the log2 must be computed from the mantissa. To accomodate for subnormal numbers, use the following:<br />
<pre>const float v; // find int(log2(v)), where v > 0.0 && finite(v)
int c; // 32-bit int c gets the result;
int x = *(const int *) &v; // OR, for portability: memcpy(&x, &v, sizeof x);
c = x >> 23;
if (c)
{
c -= 127;
}
else
{ // subnormal, so recompute using mantissa: c = intlog2(x) - 149;
register unsigned int t; // temporary
// Note that LogTable256 was defined <a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup">earlier</a>
if (t = x >> 16)
{
c = LogTable256[t] - 133;
}
else
{
c = (t = x >> 8) ? LogTable256[t] - 141 : LogTable256[x] - 149;
}
}
</pre>
On June 20, 2004, Sean A. Irvine suggested that I include code to handle subnormal numbers. On June 11, 2005, Falk Hüffner pointed out that ISO C99 6.5/7 specified undefined behavior for the common type punning idiom *(int *)&, though it has worked on 99.9% of C compilers. He proposed using memcpy for maximum portability or a union with a float and an int for better code generation than memcpy on some compilers.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="IntegerLogRootFloat">Find integer log base 2 of the pow(2, r)-root of a 32-bit IEEE float (for unsigned integer r)</a></h3>
<pre>const int r;
const float v; // find int(log2(pow((double) v, 1. / pow(2, r)))),
// where isnormal(v) and v > 0
int c; // 32-bit int c gets the result;
c = *(const int *) &v; // OR, for portability: memcpy(&c, &v, sizeof c);
c = ((((c - 0x3f800000) >> r) + 0x3f800000) >> 23) - 127;
</pre>
So, if r is 0, for example, we have c = int(log2((double) v)). If r is 1, then we have c = int(log2(sqrt((double) v))). If r is 2, then we have c = int(log2(pow((double) v, 1./4))).<br />
On June 11, 2005, Falk Hüffner pointed out that ISO C99 6.5/7 left the type punning idiom *(int *)& undefined, and he suggested using memcpy.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ZerosOnRightLinear">Count the consecutive zero bits (trailing) on the right linearly</a></h3>
<pre>unsigned int v; // input to count trailing zero bits
int c; // output: c will count v's trailing zero bits,
// so if v is 1101000 (base 2), then c will be 3
if (v)
{
v = (v ^ (v - 1)) >> 1; // Set v's trailing 0s to 1s and zero rest
for (c = 0; v; c++)
{
v >>= 1;
}
}
else
{
c = CHAR_BIT * sizeof(v);
}
</pre>
The average number of trailing zero bits in a (uniformly distributed) random binary number is one, so this O(trailing zeros) solution isn't that bad compared to the faster methods below.<br />
Jim Cole suggested I add a linear-time method for counting the trailing zeros on August 15, 2007. On October 22, 2007, Jason Cunningham pointed out that I had neglected to paste the unsigned modifier for v.<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ZerosOnRightParallel">Count the consecutive zero bits (trailing) on the right in parallel</a></h3>
<pre>unsigned int v; // 32-bit word input to count zero bits on right
unsigned int c = 32; // c will be the number of zero bits on the right
v &= -signed(v);
if (v) c--;
if (v & 0x0000FFFF) c -= 16;
if (v & 0x00FF00FF) c -= 8;
if (v & 0x0F0F0F0F) c -= 4;
if (v & 0x33333333) c -= 2;
if (v & 0x55555555) c -= 1;
</pre>
Here, we are basically doing the same operations as finding the log base 2 in parallel, but we first isolate the lowest 1 bit, and then proceed with c starting at the maximum and decreasing. The number of operations is at most 3 * lg(N) + 4, roughly, for N bit words.<br />
Bill Burdick suggested an optimization, reducing the time from 4 * lg(N) on February 4, 2011.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ZerosOnRightBinSearch">Count the consecutive zero bits (trailing) on the right by binary search</a></h3>
<pre>unsigned int v; // 32-bit word input to count zero bits on right
unsigned int c; // c will be the number of zero bits on the right,
// so if v is 1101000 (base 2), then c will be 3
// NOTE: if 0 == v, then c = 31.
if (v & 0x1)
{
// special case for odd v (assumed to happen half of the time)
c = 0;
}
else
{
c = 1;
if ((v & 0xffff) == 0)
{
v >>= 16;
c += 16;
}
if ((v & 0xff) == 0)
{
v >>= 8;
c += 8;
}
if ((v & 0xf) == 0)
{
v >>= 4;
c += 4;
}
if ((v & 0x3) == 0)
{
v >>= 2;
c += 2;
}
c -= v & 0x1;
}
</pre>
The code above is similar to the previous method, but it computes the number of trailing zeros by accumulating c in a manner akin to binary search. In the first step, it checks if the bottom 16 bits of v are zeros, and if so, shifts v right 16 bits and adds 16 to c, which reduces the number of bits in v to consider by half. Each of the subsequent conditional steps likewise halves the number of bits until there is only 1. This method is faster than the last one (by about 33%) because the bodies of the if statements are executed less often.<br />
Matt Whitlock suggested this on January 25, 2006. Andrew Shapira shaved a couple operations off on Sept. 5, 2007 (by setting c=1 and unconditionally subtracting at the end).<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ZerosOnRightFloatCast">Count the consecutive zero bits (trailing) on the right by casting to a float</a></h3>
<pre>unsigned int v; // find the number of trailing zeros in v
int r; // the result goes here
float f = (float)(v & -v); // cast the least significant bit in v to a float
r = (*(uint32_t *)&f >> 23) - 0x7f;
</pre>
Although this only takes about 6 operations, the time to convert an integer to a float can be high on some machines. The exponent of the 32-bit IEEE floating point representation is shifted down, and the bias is subtracted to give the position of the least significant 1 bit set in v. If v is zero, then the result is -127.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ZerosOnRightModLookup">Count the consecutive zero bits (trailing) on the right with modulus division and lookup</a></h3>
<pre>unsigned int v; // find the number of trailing zeros in v
int r; // put the result in r
static const int Mod37BitPosition[] = // map a bit value mod 37 to its position
{
32, 0, 1, 26, 2, 23, 27, 0, 3, 16, 24, 30, 28, 11, 0, 13, 4,
7, 17, 0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9, 5,
20, 8, 19, 18
};
r = Mod37BitPosition[(-v & v) % 37];
</pre>
The code above finds the number of zeros that are trailing on the right, so binary 0100 would produce 2. It makes use of the fact that the first 32 bit position values are relatively prime with 37, so performing a modulus division with 37 gives a unique number from 0 to 36 for each. These numbers may then be mapped to the number of zeros using a small lookup table. It uses only 4 operations, however indexing into a table and performing modulus division may make it unsuitable for some situations. I came up with this independently and then searched for a subsequence of the table values, and found it was invented earlier by Reiser, according to <a href="http://www.hackersdelight.org/HDcode/ntz.c.txt">Hacker's Delight</a>.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ZerosOnRightMultLookup">Count the consecutive zero bits (trailing) on the right with multiply and lookup</a></h3>
<pre>unsigned int v; // find the number of trailing zeros in 32-bit v
int r; // result goes here
static const int MultiplyDeBruijnBitPosition[32] =
{
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
};
r = MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >> 27];
</pre>
Converting bit vectors to indices of set bits is an example use for this. It requires one more operation than the earlier one involving modulus division, but the multiply may be faster. The expression (v & -v) extracts the least significant 1 bit from v. The constant 0x077CB531UL is a de Bruijn sequence, which produces a unique pattern of bits into the high 5 bits for each possible bit position that it is multiplied against. When there are no bits set, it returns 0. More information can be found by reading the paper <a href="http://citeseer.ist.psu.edu/leiserson98using.html">Using de Bruijn Sequences to Index 1 in a Computer Word</a> by Charles E. Leiserson, Harald Prokof, and Keith H. Randall.<br />
On October 8, 2005 <a href="http://onezero.org/">Andrew Shapira</a> suggested I add this. Dustin Spicuzza asked me on April 14, 2009 to cast the result of the multiply to a 32-bit type so it would work when compiled with 64-bit ints.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="RoundUpPowerOf2Float">Round up to the next highest power of 2 by float casting</a></h3>
<pre>unsigned int const v; // Round this 32-bit value to the next highest power of 2
unsigned int r; // Put the result here. (So v=3 -> r=4; v=8 -> r=8)
if (v > 1)
{
float f = (float)v;
unsigned int const t = 1U << ((*(unsigned int *)&f >> 23) - 0x7f);
r = t << (t < v);
}
else
{
r = 1;
}
</pre>
The code above uses 8 operations, but works on all v <= (1<<31 p="">Quick and dirty version, for domain of 1 < v < (1<<25 p=""><pre>float f = (float)(v - 1);
r = 1U << ((*(unsigned int*)(&f) >> 23) - 126);
</pre>
Although the quick and dirty version only uses around 6 operations, it is roughly three times slower than the <a href="http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2">technique below</a> (which involves 12 operations) when benchmarked on an Athlon™ XP 2100+ CPU. Some CPUs will fare better with it, though.<br />
On September 27, 2005 Andi Smithers suggested I include a technique for casting to floats to find the lg of a number for rounding up to a power of 2. Similar to the quick and dirty version here, his version worked with values less than (1<<25 but="" due="" it="" mantissa="" more="" one="" operation.="" p="" rounding="" to="" used=""><br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="RoundUpPowerOf2">Round up to the next highest power of 2</a></h3>
<pre>unsigned int v; // compute the next highest power of 2 of 32-bit v
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
</pre>
In 12 operations, this code computes the next highest power of 2 for a 32-bit integer. The result may be expressed by the formula 1U << (lg(v - 1) + 1). Note that in the edge case where v is 0, it returns 0, which isn't a power of 2; you might append the expression v += (v == 0) to remedy this if it matters. It would be faster by 2 operations to use the formula and the log base 2 method that uses a lookup table, but in some situations, lookup tables are not suitable, so the above code may be best. (On a Athlon™ XP 2100+ I've found the above shift-left and then OR code is as fast as using a single BSR assembly language instruction, which scans in reverse to find the highest set bit.) It works by copying the highest set bit to all of the lower bits, and then adding one, which results in carries that set all of the lower bits to 0 and one bit beyond the highest set bit to 1. If the original number was a power of 2, then the decrement will reduce it to one less, so that we round up to the same original value.<br />
You might alternatively compute the next higher power of 2 in only 8 or 9 operations using a lookup table for floor(lg(v)) and then evaluating 1<<(1+floor(lg(v))); Atul Divekar suggested I mention this on September 5, 2010.<br />
Devised by Sean Anderson, Sepember 14, 2001. Pete Hart pointed me to <a href="http://groups.google.com/group/comp.lang.python/browse_thread/thread/c4d3aae0df917df5/6fdae3872f9de79d?lnk=st&q=comp.lang.python+zeddy&rnum=6#6fdae3872f9de79d">a couple newsgroup posts</a> by him and William Lewis in February of 1997, where they arrive at the same algorithm.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="InterleaveTableObvious">Interleave bits the obvious way</a></h3>
<pre>unsigned short x; // Interleave bits of x and y, so that all of the
unsigned short y; // bits of x are in the even positions and y in the odd;
unsigned int z = 0; // z gets the resulting Morton Number.
for (int i = 0; i < sizeof(x) * CHAR_BIT; i++) // unroll for more speed...
{
z |= (x & 1U << i) << i | (y & 1U << i) << (i + 1);
}
</pre>
Interleaved bits (aka Morton numbers) are useful for linearizing 2D integer coordinates, so x and y are combined into a single number that can be compared easily and has the property that a number is usually close to another if their x and y values are close.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="InterleaveTableLookup">Interleave bits by table lookup</a></h3>
<pre>static const unsigned short MortonTable256[256] =
{
0x0000, 0x0001, 0x0004, 0x0005, 0x0010, 0x0011, 0x0014, 0x0015,
0x0040, 0x0041, 0x0044, 0x0045, 0x0050, 0x0051, 0x0054, 0x0055,
0x0100, 0x0101, 0x0104, 0x0105, 0x0110, 0x0111, 0x0114, 0x0115,
0x0140, 0x0141, 0x0144, 0x0145, 0x0150, 0x0151, 0x0154, 0x0155,
0x0400, 0x0401, 0x0404, 0x0405, 0x0410, 0x0411, 0x0414, 0x0415,
0x0440, 0x0441, 0x0444, 0x0445, 0x0450, 0x0451, 0x0454, 0x0455,
0x0500, 0x0501, 0x0504, 0x0505, 0x0510, 0x0511, 0x0514, 0x0515,
0x0540, 0x0541, 0x0544, 0x0545, 0x0550, 0x0551, 0x0554, 0x0555,
0x1000, 0x1001, 0x1004, 0x1005, 0x1010, 0x1011, 0x1014, 0x1015,
0x1040, 0x1041, 0x1044, 0x1045, 0x1050, 0x1051, 0x1054, 0x1055,
0x1100, 0x1101, 0x1104, 0x1105, 0x1110, 0x1111, 0x1114, 0x1115,
0x1140, 0x1141, 0x1144, 0x1145, 0x1150, 0x1151, 0x1154, 0x1155,
0x1400, 0x1401, 0x1404, 0x1405, 0x1410, 0x1411, 0x1414, 0x1415,
0x1440, 0x1441, 0x1444, 0x1445, 0x1450, 0x1451, 0x1454, 0x1455,
0x1500, 0x1501, 0x1504, 0x1505, 0x1510, 0x1511, 0x1514, 0x1515,
0x1540, 0x1541, 0x1544, 0x1545, 0x1550, 0x1551, 0x1554, 0x1555,
0x4000, 0x4001, 0x4004, 0x4005, 0x4010, 0x4011, 0x4014, 0x4015,
0x4040, 0x4041, 0x4044, 0x4045, 0x4050, 0x4051, 0x4054, 0x4055,
0x4100, 0x4101, 0x4104, 0x4105, 0x4110, 0x4111, 0x4114, 0x4115,
0x4140, 0x4141, 0x4144, 0x4145, 0x4150, 0x4151, 0x4154, 0x4155,
0x4400, 0x4401, 0x4404, 0x4405, 0x4410, 0x4411, 0x4414, 0x4415,
0x4440, 0x4441, 0x4444, 0x4445, 0x4450, 0x4451, 0x4454, 0x4455,
0x4500, 0x4501, 0x4504, 0x4505, 0x4510, 0x4511, 0x4514, 0x4515,
0x4540, 0x4541, 0x4544, 0x4545, 0x4550, 0x4551, 0x4554, 0x4555,
0x5000, 0x5001, 0x5004, 0x5005, 0x5010, 0x5011, 0x5014, 0x5015,
0x5040, 0x5041, 0x5044, 0x5045, 0x5050, 0x5051, 0x5054, 0x5055,
0x5100, 0x5101, 0x5104, 0x5105, 0x5110, 0x5111, 0x5114, 0x5115,
0x5140, 0x5141, 0x5144, 0x5145, 0x5150, 0x5151, 0x5154, 0x5155,
0x5400, 0x5401, 0x5404, 0x5405, 0x5410, 0x5411, 0x5414, 0x5415,
0x5440, 0x5441, 0x5444, 0x5445, 0x5450, 0x5451, 0x5454, 0x5455,
0x5500, 0x5501, 0x5504, 0x5505, 0x5510, 0x5511, 0x5514, 0x5515,
0x5540, 0x5541, 0x5544, 0x5545, 0x5550, 0x5551, 0x5554, 0x5555
};
unsigned short x; // Interleave bits of x and y, so that all of the
unsigned short y; // bits of x are in the even positions and y in the odd;
unsigned int z; // z gets the resulting 32-bit Morton Number.
z = MortonTable256[y >> 8] << 17 |
MortonTable256[x >> 8] << 16 |
MortonTable256[y & 0xFF] << 1 |
MortonTable256[x & 0xFF];
</pre>
For more speed, use an additional table with values that are MortonTable256 pre-shifted one bit to the left. This second table could then be used for the y lookups, thus reducing the operations by two, but almost doubling the memory required. Extending this same idea, four tables could be used, with two of them pre-shifted by 16 to the left of the previous two, so that we would only need 11 operations total.<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="Interleave64bitOps">Interleave bits with 64-bit multiply</a></h3>
In 11 operations, this version interleaves bits of two bytes (rather than shorts, as in the other versions), but many of the operations are 64-bit multiplies so it isn't appropriate for all machines. The input parameters, x and y, should be less than 256.<br />
<pre>unsigned char x; // Interleave bits of (8-bit) x and y, so that all of the
unsigned char y; // bits of x are in the even positions and y in the odd;
unsigned short z; // z gets the resulting 16-bit Morton Number.
z = ((x * 0x0101010101010101ULL & 0x8040201008040201ULL) *
0x0102040810204081ULL >> 49) & 0x5555 |
((y * 0x0101010101010101ULL & 0x8040201008040201ULL) *
0x0102040810204081ULL >> 48) & 0xAAAA;
</pre>
Holger Bettag was inspired to suggest this technique on October 10, 2004 after reading the multiply-based bit reversals here.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="InterleaveBMN">Interleave bits by Binary Magic Numbers</a></h3>
<pre>static const unsigned int B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF};
static const unsigned int S[] = {1, 2, 4, 8};
unsigned int x; // Interleave lower 16 bits of x and y, so the bits of x
unsigned int y; // are in the even positions and bits from y in the odd;
unsigned int z; // z gets the resulting 32-bit Morton Number.
// x and y must initially be less than 65536.
x = (x | (x << S[3])) & B[3];
x = (x | (x << S[2])) & B[2];
x = (x | (x << S[1])) & B[1];
x = (x | (x << S[0])) & B[0];
y = (y | (y << S[3])) & B[3];
y = (y | (y << S[2])) & B[2];
y = (y | (y << S[1])) & B[1];
y = (y | (y << S[0])) & B[0];
z = x | (y << 1);
</pre>
<hr />
<h3>
<a href="https://www.blogger.com/null" name="ZeroInWord">Determine if a word has a zero byte</a></h3>
<pre>// Fewer operations:
unsigned int v; // 32-bit word to check if any 8-bit byte in it is 0
bool hasZeroByte = ~((((v & 0x7F7F7F7F) + 0x7F7F7F7F) | v) | 0x7F7F7F7F);
</pre>
The code above may be useful when doing a fast string copy in which a word is copied at a time; it uses 5 operations. On the other hand, testing for a null byte in the obvious ways (which follow) have at least 7 operations (when counted in the most sparing way), and at most 12.<br />
<pre>// More operations:
bool hasNoZeroByte = ((v & 0xff) && (v & 0xff00) && (v & 0xff0000) && (v & 0xff000000))
// OR:
unsigned char * p = (unsigned char *) &v;
bool hasNoZeroByte = *p && *(p + 1) && *(p + 2) && *(p + 3);
</pre>
The code at the beginning of this section (labeled "Fewer operations") works by first zeroing the high bits of the 4 bytes in the word. Subsequently, it adds a number that will result in an overflow to the high bit of a byte if any of the low bits were initialy set. Next the high bits of the original word are ORed with these values; thus, the high bit of a byte is set iff any bit in the byte was set. Finally, we determine if any of these high bits are zero by ORing with ones everywhere except the high bits and inverting the result. Extending to 64 bits is trivial; simply increase the constants to be 0x7F7F7F7F7F7F7F7F.<br />
For an additional improvement, a fast pretest that requires only 4 operations may be performed to determine if the word <em>may</em> have a zero byte. The test also returns true if the high byte is 0x80, so there are occasional false positives, but the slower and more reliable version above may then be used on candidates for an overall increase in speed with correct output.<br />
<br />
<pre>bool hasZeroByte = ((v + 0x7efefeff) ^ ~v) & 0x81010100;
if (hasZeroByte) // or may just have 0x80 in the high byte
{
hasZeroByte = ~((((v & 0x7F7F7F7F) + 0x7F7F7F7F) | v) | 0x7F7F7F7F);
}
</pre>
There is yet a faster method — use <a href="http://graphics.stanford.edu/~seander/bithacks.html#HasLessInWord"><code>hasless</code></a>(v, 1), which is defined below; it works in 4 operations and requires no subsquent verification. It simplifies to<br />
<pre>#define haszero(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)</pre>
The subexpression (v - 0x01010101UL), evaluates to a high bit set in any byte whenever the corresponding byte in v is zero or greater than 0x80. The sub-expression ~v & 0x80808080UL evaluates to high bits set in bytes where the byte of v doesn't have its high bit set (so the byte was less than 0x80). Finally, by ANDing these two sub-expressions the result is the high bits set where the bytes in v were zero, since the high bits set due to a value greater than 0x80 in the first sub-expression are masked off by the second.<br />
Paul Messmer suggested the fast pretest improvement on October 2, 2004. Juha Järvi later suggested <code>hasless(v, 1)</code> on April 6, 2005, which he found on <a href="http://www.azillionmonkeys.com/qed/asmexample.html">Paul Hsieh's Assembly Lab</a>; previously it was written in a newsgroup post on April 27, 1987 by Alan Mycroft.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="#ValueInWord">Determine if a word has a byte equal to n</a></h3>
We may want to know if any byte in a word has a specific value. To do so, we can XOR the value to test with a word that has been filled with the byte values in which we're interested. Because XORing a value with itself results in a zero byte and nonzero otherwise, we can pass the result to <code>haszero</code>.<br />
<pre>#define hasvalue(x,n) \
(haszero((x) ^ (~0UL/255 * (n))))
</pre>
Stephen M Bennet suggested this on December 13, 2009 after reading the entry for <code>haszero</code>.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="HasLessInWord">Determine if a word has a byte less than n</a></h3>
Test if a word x contains an unsigned byte with value < n. Specifically for n=1, it can be used to find a 0-byte by examining one long at a time, or any byte by XORing x with a mask first. Uses 4 arithmetic/logical operations when n is constant.<br />
Requirements: x>=0; 0<=n<=128<br />
<pre>#define hasless(x,n) (((x)-~0UL/255*(n))&~(x)&~0UL/255*128)
</pre>
To count the number of bytes in x that are less than n in 7 operations, use<br />
<pre>#define countless(x,n) \
(((~0UL/255*(127+(n))-((x)&~0UL/255*127))&~(x)&~0UL/255*128)/128%255)
</pre>
Juha Järvi sent this clever technique to me on April 6, 2005. The <code>countless</code> macro was added by Sean Anderson on April 10, 2005, inspired by Juha's <code>countmore</code>, below.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="HasMoreInWord">Determine if a word has a byte greater than n</a></h3>
Test if a word x contains an unsigned byte with value > n. Uses 3 arithmetic/logical operations when n is constant.<br />
Requirements: x>=0; 0<=n<=127<br />
<pre>#define hasmore(x,n) (((x)+~0UL/255*(127-(n))|(x))&~0UL/255*128)
</pre>
To count the number of bytes in x that are more than n in 6 operations, use:<br />
<pre>#define countmore(x,n) \
(((((x)&~0UL/255*127)+~0UL/255*(127-(n))|(x))&~0UL/255*128)/128%255)
</pre>
The macro <code>hasmore</code> was suggested by Juha Järvi on April 6, 2005, and he added <code>countmore</code> on April 8, 2005.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="HasBetweenInWord">Determine if a word has a byte between m and n</a></h3>
When m < n, this technique tests if a word x contains an unsigned byte value, such that m < value < n. It uses 7 arithmetic/logical operations when n and m are constant.<br />
Note: Bytes that equal n can be reported by <code>likelyhasbetween</code> as false positives, so this should be checked by character if a certain result is needed.<br />
Requirements: x>=0; 0<=m<=127; 0<=n<=128<br />
<br />
<pre>#define likelyhasbetween(x,m,n) \
((((x)-~0UL/255*(n))&~(x)&((x)&~0UL/255*127)+~0UL/255*(127-(m)))&~0UL/255*128)
</pre>
This technique would be suitable for a fast pretest. A variation that takes one more operation (8 total for constant m and n) but provides the exact answer is:<br />
<pre>#define hasbetween(x,m,n) \
((~0UL/255*(127+(n))-((x)&~0UL/255*127)&~(x)&((x)&~0UL/255*127)+~0UL/255*(127-(m)))&~0UL/255*128)
</pre>
To count the number of bytes in x that are between m and n (exclusive) in 10 operations, use:<br />
<pre>#define countbetween(x,m,n) (hasbetween(x,m,n)/128%255)
</pre>
Juha Järvi suggested <code>likelyhasbetween</code> on April 6, 2005. From there, Sean Anderson created <code>hasbetween</code> and <code>countbetween</code> on April 10, 2005.<br />
<br />
<hr />
<h3>
<a href="https://www.blogger.com/null" name="NextBitPermutation">Compute the lexicographically next bit permutation</a></h3>
Suppose we have a pattern of N bits set to 1 in an integer and we want the next permutation of N 1 bits in a lexicographical sense. For example, if N is 3 and the bit pattern is 00010011, the next patterns would be 00010101, 00010110, 00011001,00011010, 00011100, 00100011, and so forth. The following is a fast way to compute the next permutation.<br />
<pre>unsigned int v; // current permutation of bits
unsigned int w; // next permutation of bits
unsigned int t = v | (v - 1); // t gets v's least significant 0 bits set to 1
// Next set to 1 the most significant bit to change,
// set to 0 the least significant ones, and add the necessary 1 bits.
w = (t + 1) | (((~t & -~t) - 1) >> (__builtin_ctz(v) + 1));
</pre>
The __builtin_ctz(v) GNU C compiler intrinsic for x86 CPUs returns the number of trailing zeros. If you are using Microsoft compilers for x86, the intrinsic is _BitScanForward. These both emit a bsf instruction, but equivalents may be available for other architectures. If not, then consider using one of the methods for counting the consecutive zero bits mentioned earlier.<br />
Here is another version that tends to be slower because of its division operator, but it does not require counting the trailing zeros.<br />
<pre>unsigned int t = (v | (v - 1)) + 1;
w = t | ((((t & -t) / (v & -v)) >> 1) - 1);
</pre>
Thanks to Dario Sneidermanis of Argentina, who provided this on November 28, 2009.<br />
<a href="http://webhostingrating.com/libs/bithacks-be">A Belorussian translation</a> (provided by <a href="http://webhostingrating.com/">Webhostingrating</a>) is available.</25></25></31>Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-12117291876381201422015-07-11T18:29:00.001+08:002015-07-11T18:29:33.515+08:00A really good step by step tutorial to setup odoo on ubuntu<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
A really good step by step tutorial to setup odoo on ubuntu. </h3>
<div>
<br /></div>
<div>
http://www.theopensourcerer.com/2014/09/how-to-install-openerp-odoo-8-on-ubuntu-server-14-04-lts/</div>
<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
Introduction</h3>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Welcome to the latest of our very popular <del datetime="2014-06-26T14:00:08+00:00" style="margin: 0px; padding: 0px;">OpenERP</del> Odoo installation “How Tos”.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
The new release of Odoo 8.0 is a major upgrade introducing a great many new features and a new name.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Odoo 8.0 is not only better looking and easier to use, it also brings many improvements to the existing feature-set and adds a number of brand new features which extend the scope of the business needs covered by Odoo. Ecommerce, CMS, Integrated BI…</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Rather than me blathering on about what’s new, you can simply just go and <a href="https://www.odoo.com/blog/odoo-news-5/post/odoo-8-release-notes-186" style="color: #d7c1a6; margin: 0px; padding: 0px;" target="_blank" title="Odoo 8 Release Notes">read the release notes here</a>.</div>
<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
The How To</h3>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Following that introduction, I bet you can’t wait to get your hands dirty…</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Just one thing before we start: You can simply <a href="https://www.odoo.com/page/download" style="color: #d7c1a6; margin: 0px; padding: 0px;" target="_blank" title="Odoo Download Page">download</a> a .deb (for Debian/Ubuntu type systems) or a. rpm (Redhat/CentOS) package of OpenERP and install that. Unfortunately that approach doesn’t provide us (<a href="http://www.libertus.co.uk/" style="color: #d7c1a6; margin: 0px; padding: 0px;" title="Libertus Solutions">Libertus Solutions</a>) with enough fine-grained control over where things get installed, and it restricts our flexibility to modify & customise, hence I prefer to do it a slightly more manual way (this install process below should only take about 10-15 minutes once the host machine has been built).</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
This time, rather than using a source tarball as the basis for installation we are going to take the code straight from the <a href="https://github.com/odoo/odoo/tree/8.0" style="color: #d7c1a6; margin: 0px; padding: 0px;" target="_blank" title="Odoo 8 Branch on Github">Odoo 8.0 branch on Github</a>. This should help when it comes to installing updates and bug fixes in the future by being able to issue a <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">git pull</code> command to update the code. <em style="margin: 0px; padding: 0px;">Bear in mind before doing a pull request you should always have backups and you may need to update your Odoo database(s) as well.</em></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
So without further ado here we go:</div>
<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
Step 1. Build your server</h3>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
I install just the bare minimum from the install routine (you may want to install the <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">openssh-server</code> during the install procedure or install subsequently depending on your needs).</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
After the server has restarted for the first time I install the <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">openssh-server</code> package (so we can connect to it remotely) and <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;"><del datetime="2014-09-25T07:52:36+00:00" style="margin: 0px; padding: 0px;">denyhosts</del></code> to add a degree of brute-force attack protection. There are other protection applications available: I’m not saying this one is the best, but it’s one that works and is easy to configure and manage. If you don’t already, it’s also worth looking at setting up key-based ssh access, rather than relying on passwords. This can also help to limit the potential of brute-force attacks. [NB: This isn’t a How To on securing your server…]</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo apt-get install openssh-server <del datetime="2014-09-25T07:52:36+00:00" style="margin: 0px; padding: 0px;">denyhosts</del></code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
UPDATE: Note that it seems <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">denyhosts</code> is no longer being maintained and is not in the main Ubuntu repository any more. I’m aware of a possibly suitable alternative called <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">fail2ban</code> but have not used it yet; do you own research. Thanks to Rami for the cluebat!</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
UPDATE2: Thanks to Paul for the pointer. I have added <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">python-unicodecsv</code> to the list of dependencies. Apparently this is required to correctly restore backups.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Now make sure your server has all the latest versions & patches by doing an update:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo apt-get update</code><br style="margin: 0px; padding: 0px;" /><code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo apt-get dist-upgrade</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Although not always essential it’s probably a good idea to reboot your server now and make sure it all comes back up and you can login via ssh.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Now we’re ready to start the Odoo install.</div>
<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
Step 2. Create the Odoo user that will own and run the application</h3>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo adduser --system --home=/opt/odoo --group odoo</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
This is a “system” user. It is there to own and run the application, it isn’t supposed to be a person type user with a login etc. In Ubuntu, a system user gets a UID below 1000, has no shell (it’s actually <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">/bin/false</code>) and has logins disabled. Note that I’ve specified a “home” of<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">/opt/odoo</code>, this is where the OpenERP server code will reside and is created automatically by the command above. The location of the server code is your choice of course, but be aware that some of the instructions and configuration files below may need to be altered if you decide to install to a different location.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<em style="margin: 0px; padding: 0px;">[Note: If you want to run multiple versions of Odoo/OpenERP on the same server, the way I do it is to create multiple users with the correct version number as part of the name, e.g. openerp70, openerp61 etc. If you also use this when creating the Postgres users too, you can have full separation of systems on the same server. I also use similarly named home directories, e.g. /opt/odoo80, /opt/openerp70, /opt/openerp61 and config and start-up/shutdown files. You will also need to configure different ports for each instance or else only the first will start.]</em></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
A question I have been asked a few times is how to run the Odoo server as the odoo system user from the command line if it has no shell. This can be done quite easily:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo su - odoo -s /bin/bash</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
This will <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">su</code> your current terminal login to the odoo user (the “<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">-</code>” between <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">su</code> and <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">odoo</code> is correct) and use the shell <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">/bin/bash</code>. When this command is run you will be in odoo’s home directory: <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">/opt/odoo</code>.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
When you have done what you need you can leave the odoo user’s shell by typing <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">exit</code>.</div>
<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
Step 3. Install and configure the database server, PostgreSQL</h3>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo apt-get install postgresql</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Then configure the Odoo user on postgres:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
First change to the postgres user so we have the necessary privileges to configure the database.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo su - postgres</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Now create a new database user. This is so Odoo has access rights to connect to PostgreSQL and to create and drop databases. Remember what your choice of password is here; you will need it later on:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt odoo</code><br style="margin: 0px; padding: 0px;" /><code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">Enter password for new role: ********</code><br style="margin: 0px; padding: 0px;" /><code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">Enter it again: ********</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Finally exit from the postgres user account:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">exit</code></div>
<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
Step 4. Install the necessary Python libraries for the server</h3>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo apt-get install python-cups python-dateutil python-decorator python-docutils python-feedparser \<br style="margin: 0px; padding: 0px;" />python-gdata python-geoip python-gevent python-imaging python-jinja2 python-ldap python-libxslt1<br style="margin: 0px; padding: 0px;" />python-lxml python-mako python-mock python-openid python-passlib python-psutil python-psycopg2<br style="margin: 0px; padding: 0px;" />python-pybabel python-pychart python-pydot python-pyparsing python-pypdf python-reportlab python-requests \<br style="margin: 0px; padding: 0px;" />python-simplejson python-tz python-unicodecsv python-unittest2 python-vatnumber python-vobject \<br style="margin: 0px; padding: 0px;" />python-werkzeug python-xlwt python-yaml wkhtmltopdf</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
With that done, all the dependencies for installing Odoo 8.0 are now satisfied (note that there are some changes between this and the packages required for OpenERP 7.0).</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<strong style="margin: 0px; padding: 0px;">UPDATE & NOTE: </strong>It has been pointed out to me that the Qweb templating engine in Odoo 8 is warning that the version of wkhtmltopdf is too old. It turns out that Ubuntu 14.04 packages version 0.9.9 of this library even though this is rather old. To update your Ubuntu server please follow the instructions on <a href="https://gist.github.com/slickplaid/5557321" style="color: #d7c1a6; margin: 0px; padding: 0px;" target="_blank" title="Upgrading wkhtmltopdf on Ubuntu">this page</a>. Many thanks to Ruben Kannan for pointing this out :-).</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<strong style="margin: 0px; padding: 0px;">UPDATE & NOTE II: </strong>Zak suggests an alternative method to get and install the most recent version of wkhtmltopdf in <a href="http://www.theopensourcerer.com/2014/09/how-to-install-openerp-odoo-8-on-ubuntu-server-14-04-lts/comment-page-1/#comment-351536" style="color: #d7c1a6; margin: 0px; padding: 0px;" title="Get & install wkhtmltopdf from a deb">this comment below</a>. Thanks Zak.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<strong style="margin: 0px; padding: 0px;">UPDATE & NOTE III: </strong>David suggested adding python-cups and python-geoip to the list of modules to install in <a href="http://www.theopensourcerer.com/2014/09/how-to-install-openerp-odoo-8-on-ubuntu-server-14-04-lts/comment-page-3/#comment-580511" style="color: #d7c1a6; margin: 0px; padding: 0px;">this comment below</a>. Thanks David.</div>
<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
Step 5. Install the Odoo server</h3>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Install Git.<br style="margin: 0px; padding: 0px;" /><code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo apt-get install git</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Switch to the Odoo user:<br style="margin: 0px; padding: 0px;" /><code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo su - odoo -s /bin/bash</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Grab a copy of the most current Odoo 8 branch <em style="margin: 0px; padding: 0px;">(Note the “.” at the end of this command!)</em>:<br style="margin: 0px; padding: 0px;" /><code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">git clone https://www.github.com/odoo/odoo --depth 1 --branch 8.0 --single-branch .</code><br style="margin: 0px; padding: 0px;" />(This might take a little while depending on the speed of your Internet connection.)</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<strong style="margin: 0px; padding: 0px;">Note:</strong> Thanks to <a href="http://www.theopensourcerer.com/2014/09/how-to-install-openerp-odoo-8-on-ubuntu-server-14-04-lts/comment-page-1/#comment-345197" style="color: #d7c1a6; margin: 0px; padding: 0px;">Ian Beardslee</a> for the cluebat. Have now added <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">--depth 1</code> to the command so it only retrieves the latest version without all the history. The download is now quite a bit quicker.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Once it’s finished exit from the odoo user: <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">exit</code>.</div>
<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
Step 6. Configuring the OpenERP application</h3>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
The default configuration file for the server (<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">/opt/odoo/debian/openerp-server.conf</code>) is actually very minimal and will, with only a small change work fine so we’ll copy that file to where we need it and change it’s ownership and permissions:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo cp /opt/odoo/debian/openerp-server.conf /etc/odoo-server.conf<br style="margin: 0px; padding: 0px;" />sudo chown odoo: /etc/odoo-server.conf<br style="margin: 0px; padding: 0px;" />sudo chmod 640 /etc/odoo-server.conf</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
The above commands make the file owned and writeable only by the odoo user and group and only readable by odoo and root.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
To allow the odoo server to run initially, you should only need to change two lines in this file. Toward to the top of the file change the line<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">db_password = False</code> to the same password you used back in step 3. Then modify the line <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">addons_path = /usr/lib/python2.7/dist-packages/openerp/addons</code> so that it reads <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">addons_path = /opt/odoo/addons</code> instead.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
One other line we might as well add to the configuration file now, is to tell Odoo where to write its log file. To complement my suggested location below add the following line to the <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">odoo-server.conf</code> file:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">logfile = /var/log/odoo/odoo-server.log</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Use your favourite text editor here. I tend to use nano, e.g.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo nano /etc/odoo-server.conf</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Once the configuration file is edited and saved, you can start the server just to check if it actually runs.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo su - odoo -s /bin/bash</code><br style="margin: 0px; padding: 0px;" /><code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">/opt/odoo/openerp-server</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
If you end up with a few lines eventually saying OpenERP (Yes. The log still says OpenERP and not Odoo) is running and waiting for connections then you are all set.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
If there are errors, you’ll need to go back and find out where the problem is.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Otherwise simply enter <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">CTL+C</code> to stop the server and then <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">exit</code> to leave the openerp user account and go back to your own shell.</div>
<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
Step 7. Installing the boot script</h3>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
For the final step we need to install a script which will be used to start-up and shut down the server automatically and also run the application as the correct user. There is a script you can use in <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">/opt/odoo/debian/init</code> but this will need a few small modifications to work with the system installed the way I have described above. <a href="http://www.theopensourcerer.com/wp-content/uploads/2014/09/odoo-server" style="color: #d7c1a6; margin: 0px; padding: 0px;">Here’s a link</a> to the one I’ve already modified for Odoo version 8.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Similar to the configuration file, you need to either copy it or paste the contents of this script to a file in <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">/etc/init.d/</code> and call it <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">odoo-server</code>. Once it is in the right place you will need to make it executable and owned by root:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo chmod 755 /etc/init.d/odoo-server</code><br style="margin: 0px; padding: 0px;" /><code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo chown root: /etc/init.d/odoo-server</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
In the configuration file there’s an entry for the server’s log file. We need to create that directory first so that the server has somewhere to log to and also we must make it writeable by the openerp user:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo mkdir /var/log/odoo</code><br style="margin: 0px; padding: 0px;" /><code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo chown odoo:root /var/log/odoo</code></div>
<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
Step 8. Testing the server</h3>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
To start the Odoo server type:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo /etc/init.d/odoo-server start</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
You should now be able to view the logfile and see that the server has started.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">less /var/log/odoo/odoo-server.log</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
If there are any problems starting the server you need to go back and check. There’s really no point ploughing on if the server doesn’t start…</div>
<div class="wp-caption alignright" id="attachment_3708" style="background-color: #dcdad5; border-radius: 3px; border: 1px solid rgb(220, 218, 213); color: #dcdad5; float: right; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin: 10px; padding: 4px 0px 0px; text-align: center; width: 310px;">
<a href="http://www.theopensourcerer.com/wp-content/uploads/2014/09/odoo-8-new-database.png" style="color: #d7c1a6; margin: 0px; padding: 0px;"><img alt="Odoo 8 New Database" class="size-medium wp-image-3708" height="166" scale="0" src="http://www.theopensourcerer.com/wp-content/uploads/2014/09/odoo-8-new-database-300x166.png" style="border: 0px none; margin: 0px; padding: 0px;" width="300" /></a><div class="wp-caption-text" style="color: #0f0c0b; font-size: 11px; line-height: 17px; padding: 3px 0px 5px;">
Odoo 8 New Database</div>
</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
If the log file looks OK, now point your web browser at the domain or IP address of your Odoo server (or localhost if you are on the same machine) and use port 8069. The url will look something like this:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">http://IP_or_domain.com:8069</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
What you should see is a screen like this one (it is the Database Management Screen because you have no Odoo databases yet):</div>
<div class="clear" style="background-color: #1e1816; clear: both; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin: 0px; padding: 0px;">
</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
What I do recommend you do at this point is to change the super admin password to something nice and strong (Click the “Password” menu). By default this password is just “admin” and knowing that, a user can create, backup, restore and <strong style="margin: 0px; padding: 0px;">drop</strong> databases! This password is stored in <em style="margin: 0px; padding: 0px;">plain text</em> in the <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">/etc/odoo-server.conf</code> file; <em style="margin: 0px; padding: 0px;">hence why we restricted access to just odoo and root</em>. When you change and save the new password the <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">/etc/odoo-server.conf</code> file will be re-written and will have a lot more options in it.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Now it’s time to make sure the server stops properly too:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo /etc/init.d/odoo-server stop</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Check the log file again to make sure it has stopped and/or look at your server’s process list.</div>
<h3 style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; line-height: 18.9696006774902px; margin: 0.5em 0px; padding: 0px;">
Step 9. Automating Odoo startup and shutdown</h3>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
If everything above seems to be working OK, the final step is make the script start and stop automatically with the Ubuntu Server. To do this type:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">sudo update-rc.d odoo-server defaults</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
You can now try rebooting you server if you like. Odoo should be running by the time you log back in.</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
If you type <code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">ps aux | grep odoo</code> you should see a line similar to this:</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
<code style="color: #d7c1a6; font-family: 'Liberation Mono', Courier, Mono; font-size: 1em; margin: 0px; padding: 0px;">odoo 1491 0.1 10.6 207132 53596 ? Sl 22:23 0:02 python /opt/odoo/openerp-server -c /etc/odoo-server.conf</code></div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
Which shows that the server is running. And of course you can check the logfile or visit the server from your web browser too.</div>
<div class="wp-caption alignright" id="attachment_3710" style="background-color: #dcdad5; border-radius: 3px; border: 1px solid rgb(220, 218, 213); color: #dcdad5; float: right; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin: 10px; padding: 4px 0px 0px; text-align: center; width: 310px;">
<a href="http://www.theopensourcerer.com/wp-content/uploads/2014/09/odoo-8-opening-screen.png" style="color: #d7c1a6; margin: 0px; padding: 0px;"><img alt="Odoo 8 Opening Screen" class="size-medium wp-image-3710" height="174" scale="0" src="http://www.theopensourcerer.com/wp-content/uploads/2014/09/odoo-8-opening-screen-300x174.png" style="border: 0px none; margin: 0px; padding: 0px;" width="300" /></a><div class="wp-caption-text" style="color: #0f0c0b; font-size: 11px; line-height: 17px; padding: 3px 0px 5px;">
Odoo 8 Opening Screen</div>
</div>
<div style="background-color: #1e1816; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin-bottom: 1em; margin-top: 0.5em; padding: 0px;">
That’s it! Next I would suggest you create a new database filling in the fields as desired. Once the database is initialised, you will be directed straight to the new main configuration screen which gives you a feel for the new User Interface in Odoo 8 and shows you how easy it is to set up a basic system.</div>
<div class="clear" style="background-color: #1e1816; clear: both; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin: 0px; padding: 0px;">
</div>
<div class="sharedaddy sd-sharing-enabled" style="background-color: #1e1816; clear: both; color: #dcdad5; font-family: 'Liberation Sans', Arial, Helvetica, sans-serif; font-size: 14.5920000076294px; line-height: 18.9696006774902px; margin: 0px; padding: 0px;">
<div class="robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing" style="margin: 0px; padding: 0px;">
<h3 class="sd-title" style="display: inline-block; font-size: 9pt; line-height: 1.2; margin: 0px 0px 1em; padding: 0px;">
Share:</h3>
</div>
</div>
Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-51833285657103719012014-07-23T22:05:00.001+08:002014-07-23T22:05:42.282+08:00a workaround for wordpress blank line issue<div dir="ltr"><p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif">Yoast wordpress SEO </p><p style="margin:0px 0px 20px;word-wrap:break-word"> <font color="#333333" face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3"><span style="line-height:21.81818199157715px">wordpress error on line 2 at column 6: XML declaration allowed only at the start of the document</span></font><br> </p><p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif"><span style="font-size:16px;line-height:1.5">There is a simple solution for this. It doesn’t require some crazy plugin. It doesn’t require hiring a super hacker geek to fix it AND it won’t require hours upon hours of Google’ing for the solution.</span><br> </p><p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif">Now, if you want to try there are a few possible solutions. You can try:</p> <ol style="padding:0px;margin:0px 0px 20px 45px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif"><li style="line-height:1.5;word-wrap:break-word"> Reading this helpful article on the RSS Validator site:<a href="http://feedvalidator.org/docs/error/WPBlankLine.html" style="color:rgb(77,139,151);text-decoration:none;word-wrap:break-word">http://feedvalidator.org/docs/error/WPBlankLine.html</a></li> <li style="line-height:1.5;word-wrap:break-word">Try the <a href="http://wordpress.org/extend/plugins/fix-rss-feed/" style="color:rgb(77,139,151);text-decoration:none;word-wrap:break-word">FIX RSS FEED</a> plugin for WordPress (didn’t work for my clients site at all)</li> <li style="line-height:1.5;word-wrap:break-word">Paying someone lots of money [like me <img src="http://www.piotrkrzyzek.com/wp-includes/images/smilies/icon_smile.gif" alt="Wordpress Remove Blank Line From RSS Feed wordpress error on line 2 at column 6: XML declaration allowed only at the start of the document" class="" title="Wordpress Remove Blank Line From RSS Feed wordpress error on line 2 at column 6: XML declaration allowed only at the start of the document" style="height: auto; max-width: 100%; vertical-align: middle; border: 0px; word-wrap: break-word;"> ] to do it for you.</li> </ol><p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif">Or you can simply do this yourself. It’s REALLY really simply and only require one file upload and one line of code. I’ll guide you through the whole process.</p> <p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif"><strong style="word-wrap:break-word">1) FIRST. Download the following file</strong>. <a href="http://wejn.org/stuff/wejnswpwhitespacefix.php" style="color:rgb(77,139,151);text-decoration:none;word-wrap:break-word">http://wejn.org/stuff/wejnswpwhitespacefix.php</a>.</p> <p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif">If you’re a geek you can check it for yourself, but I (Piotr Krzyzek) assure you this file is Virus free. If you don’t trust that file, you can download the exact same file from my server which I won’t change at all. So you can 100% rest assure that this file is safe from my server. You can get it <a href="http://www.piotrkrzyzek.com/wejnswpwhitespacefix.ph" style="color:rgb(77,139,151);text-decoration:none;word-wrap:break-word">HERE</a> from my server. <strong style="word-wrap:break-word">But if you download it from my server, rename the file from the “.ph” extension to “.php” so that it will work on your server too.</strong></p> <p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif"><strong style="word-wrap:break-word">2) After downloading, upload the .PHP file into your WordPress site ROOT directory.</strong> This means wherever the wp-config.php file is. Do NOT upload it into the themes folder, NOR the plugins folder. Only the root directory.</p> <p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif">If you don’t understand that, it’s ok. Leave a comment or poke me a twitter and I’ll explain it better.</p> <p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif"><strong style="word-wrap:break-word">3) EDIT your index.php file and add the following right after the first line</strong>:</p> <p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif"><code style="padding:2px 4px;font-family:Monaco,Menlo,Consolas,'Courier New',monospace;font-size:12px;color:rgb(221,17,68);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;white-space:nowrap;background-color:rgb(247,247,249);border:1px solid rgb(225,225,232);word-wrap:break-word">include("wejnswpwhitespacefix.php");</code></p> <p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif">So at the end, your index.php should look something like this:</p> <p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif"><code style="padding:2px 4px;font-family:Monaco,Menlo,Consolas,'Courier New',monospace;font-size:12px;color:rgb(221,17,68);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;white-space:nowrap;background-color:rgb(247,247,249);border:1px solid rgb(225,225,232);word-wrap:break-word"><br style="word-wrap:break-word"> <?php<br style="word-wrap:break-word">include("wejnswpwhitespacefix.php");<br style="word-wrap:break-word">define('WP_USE_THEMES', true);<br style="word-wrap:break-word">require('./wp-blog-header.php');<br style="word-wrap:break-word"> ?><br style="word-wrap:break-word"></code></p><p style="margin:0px 0px 20px;word-wrap:break-word;font-size:16px;line-height:1.5;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif">That’s of course a condensed version of the index.php file and your’s will probably have lots of comments and stuff in it. But the important thing is to add the include code right at the top.</p> </div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com3tag:blogger.com,1999:blog-7586695.post-10387055355699076482014-07-05T12:04:00.001+08:002014-07-05T12:04:43.523+08:00Create swap page on Amazon AWS EC2 instance<div dir="ltr"><div><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">AWS EC2 instance doesn't come with swap partition. In some cases we have to create one. But need to mention <span style="background-color:rgb(250,250,250);color:rgb(68,68,68);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;font-size:13px;line-height:17.280000686645508px">monthly EBS IO costs probably</span><span style="background-color:rgb(250,250,250);color:rgb(68,68,68);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;font-size:13px;line-height:17.280000686645508px"> high.</span> </div> <div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><a href="http://stackoverflow.com/questions/17173972/how-do-you-add-swap-to-an-ec2-instance" target="_blank">http://stackoverflow.com/questions/17173972/how-do-you-add-swap-to-an-ec2-instance</a><br> </div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px"> A fix for this problem is to add <code style="margin:0px;padding:1px 5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;white-space:pre-wrap">swap</code> or <code style="margin:0px;padding:1px 5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;white-space:pre-wrap">paging</code> space to the instance.</p> <p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px"> Paging works by creating an area on your hard drive and using it for extra memory, this memory is much slower than normal memory however this is much more of it available.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px"> To add this extra space to your instance you type:</p><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;word-wrap:normal;color:rgb(0,0,0);line-height:17.804800033569336px"> <code style="margin:0px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;white-space:inherit">sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 sudo /sbin/mkswap /var/swap.1 sudo /sbin/swapon /var/swap.1 </code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px"> If you need more than 1024 then change that to something higher.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px"> To enable it by default after reboot, add this line to /etc/fstab:</p><pre style="white-space:pre-wrap;margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;word-wrap:normal;color:rgb(0,0,0);line-height:17.804800033569336px"> <code style="margin:0px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;white-space:inherit">/var/swap.1 swap swap defaults 0 0</code></pre> </div></div></div> </div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-44639393590993691072013-08-02T00:41:00.001+08:002013-08-02T00:42:39.877+08:00The Skywoods (D23) (Pending Approval for Sale)Singapore new launch condo.<br />
<a href="http://www.harrylau.com/property/the-skywoods-d23/">The Skywoods (D23) (Pending Approval for Sale)</a><br />
Please refer to <a href="http://www.skywoodslaunch.com/">http://www.skywoodslaunch.com</a> for more details.Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-35610325429725835332013-08-01T09:05:00.001+08:002013-08-01T09:05:48.423+08:0015 Mins SEO<div dir="ltr"><table class="" cellpadding="2" cellspacing="0" width="100%"><tbody><tr class="" valign="TOP"><th width="7%"><p align="LEFT"><br></p> </th> <th colspan="3" width="93%"> <p align="LEFT"><font size="4"><b>Keywords</b></font></p> </th> </tr> <tr class="" valign="TOP"> <td height="63" width="7%"> <p align="LEFT">1</p> </td> <td class="" width="24%"> <p align="LEFT">Keywords in <title> tag </p> </td> <td width="62%"> <p>This is one of the most important places to have a keyword because what is written inside the <title> tag shows in search results as your page title. The title tag must be short (6 or 7 words at most) and the the keyword must be near the beginning. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">2</p> </td> <td width="24%"> <p align="LEFT">Keywords in URL</p> </td> <td width="62%"> <p align="LEFT">Keywords in URLs help a lot - e.g. - <a href="http://domainname.com/seo-services.html">http://domainname.com/seo-services.html</a>, where "SEO services" is the keyword phrase you attempt to rank well for. But if you don't have the keywords in other parts of the document, don't rely on having them in the URL.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">3</p> </td> <td width="24%"> <p align="LEFT">Keyword density in document text</p> </td> <td width="62%"> <p align="LEFT">Another very important factor you need to <a href="http://www.webconfs.com/keyword-density-checker.php">check</a>. 3-7 % for major keywords is best, 1-2 for minor. Keyword density of over 10% is suspicious and looks more like keyword stuffing, than a naturally written text.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT"><font face="Georgia, serif"><font>4</font></font></p> </td> <td width="24%"> <p align="LEFT"><font face="Georgia, serif"><font>Keywords in anchor text</font></font></p> </td> <td width="62%"> <p align="LEFT">Also very important, especially for <a href="http://www.webconfs.com/anchor-text-analysis.php">the anchor text of inbound links</a>, because if you have the keyword in the anchor text in a link from another site, this is regarded as getting a vote from this site not only about your site in general, but about the keyword in particular. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">5</p> </td> <td width="24%"> <p align="LEFT">Keywords in headings (<H1>, <H2>, etc. tags)</p> </td> <td width="62%"> <p align="LEFT">One more place where keywords count a lot. But beware that your page has actual text about the particular keyword.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">6</p> </td> <td width="24%"> <p align="LEFT">Keywords in the beginning of a document</p> </td> <td width="62%"> <p align="LEFT">Also counts, though not as much as anchor text, title tag or headings. However, have in mind that the beginning of a document does not necessarily mean the first paragraph – for instance if you use tables, the first paragraph of text might be in the second half of the table.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">7</p> </td> <td width="24%"> <p align="LEFT">Keywords in <alt> tags</p> </td> <td width="62%"> <p align="LEFT">Spiders don't read images but they do read their textual descriptions in the <alt> tag, so if you have images on your page, fill in the <alt> tag with some keywords about them. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">8</p> </td> <td width="24%"> <p align="LEFT">Keywords in metatags</p> </td> <td width="62%"> <p align="LEFT">Less and less important, especially for Google. Yahoo! and Bing still rely on them, so if you are optimizing for Yahoo! or Bing, fill these tags properly. In any case, filling these tags properly will not hurt, so do it.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">9</p> </td> <td width="24%"> <p align="LEFT">Keyword proximity</p> </td> <td width="62%"> <p align="LEFT">Keyword proximity measures how close in the text the keywords are. It is best if they are immediately one after the other (e.g. "dog food"), with no other words between them. For instance, if you have "dog" in the first paragraph and "food" in the third paragraph, this also counts but not as much as having the phrase "dog food" without any other words in between. Keyword proximity is applicable for keyword phrases that consist of 2 or more words.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">10</p> </td> <td width="24%"> <p align="LEFT">Keyword phrases</p> </td> <td width="62%"> <p align="LEFT">In addition to keywords, you can optimize for keyword phrases that consist of several words – e.g. "SEO services". It is best when the keyword phrases you optimize for are popular ones, so you can get a lot of exact matches of the search string but sometimes it makes sense to optimize for 2 or 3 separate keywords ("SEO" and "services") than for one phrase that might occasionally get an exact match.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">11</p> </td> <td width="24%"> <p align="LEFT">Secondary keywords</p> </td> <td width="62%"> <p align="LEFT">Optimizing for secondary keywords can be a golden mine because when everybody else is optimizing for the most popular keywords, there will be less competition (and probably more hits) for pages that are optimized for the minor words. For instance, "real estate new jersey" might have thousand times less hits than "real estate" only but if you are operating in New Jersey, you will get less but considerably better targeted traffic. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">12</p> </td> <td width="24%"> <p align="LEFT">Keyword stemming</p> </td> <td width="62%"> <p align="LEFT">For English this is not so much of a factor because words that stem from the same root (e.g. dog, dogs, doggy, etc.) are considered related and if you have "dog" on your page, you will get hits for "dogs" and "doggy" as well, but for other languages keywords stemming could be an issue because different words that stem from the same root are considered as not related and you might need to optimize for all of them. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">13</p> </td> <td width="24%"> <p align="LEFT">Synonyms</p> </td> <td width="62%"> <p align="LEFT">Optimizing for synonyms of the target keywords, in addition to the main keywords. This is good for sites in English, for which search engines are smart enough to use synonyms as well, when ranking sites but for many other languages synonyms are not taken into account, when calculating rankings and relevancy. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">14</p> </td> <td width="24%"> <p align="LEFT">Keyword Mistypes</p> </td> <td width="62%"> <p align="LEFT">Spelling errors are very frequent and if you know that your target keywords have popular misspellings or alternative spellings (i.e. Christmas and Xmas), you might be tempted to optimize for them. Yes, this might get you some more traffic but having spelling mistakes on your site does not make a good impression, so you'd better don't do it, or do it only in the metatags.</p> </td> <td width="6%"> <p align="CENTER"><font class="">0</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">15</p> </td> <td width="24%"> <p align="LEFT">Keyword dilution </p> </td> <td width="62%"> <p align="LEFT">When you are optimizing for an excessive amount of keywords, especially unrelated ones, this will affect the performance of all your keywords and even the major ones will be lost (diluted) in the text.</p> </td> <td width="6%"> <p align="CENTER"><font class="">-2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">16</p> </td> <td width="24%"> <p align="LEFT">Keyword stuffing</p> </td> <td width="62%"> <p align="LEFT">Any artificially inflated keyword density (10% and over) is keyword stuffing and you risk getting banned from search engines. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT"><br> </p> </td> <td colspan="3" width="93%"> <p align="LEFT"><font size="4"><b>Links - internal, inbound, outbound </b></font> </p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT"><font face="Georgia, serif"><font>17</font></font></p> </td> <td width="24%"> <p align="LEFT">Anchor text of inbound links</p> </td> <td width="62%"> <p align="LEFT"> As discussed in the Keywords section, this is one of the most important factors for good rankings. It is best if you have a keyword in the anchor text but even if you don't, it is still OK. However, don't use the same anchor text all the time because this is also penalized by Google. Try to use synonyms, keyword stemming, or simply the name of your site instead</p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT"><font face="Georgia, serif"><font>18</font></font></p> </td> <td width="24%"> <p align="LEFT">Origin of inbound links</p> </td> <td width="62%"> <p align="LEFT"> Besides the anchor text, it is important if the site that links to you is a reputable one or not. Generally sites with greater Google PR are considered reputable. Links from poor sites and link farms can do real harm to you, so avoid them at all costs. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT"><font face="Georgia, serif"><font>19</font></font></p> </td> <td width="24%"> <p align="LEFT">Links from similar sites</p> </td> <td width="62%"> <p align="LEFT"> Generally the more, the better. But the reputation of the sites that link to you is more important than their number. Also important is their anchor text (and its diversity), the lack/presence of keyword(s) in it, the link age, etc. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT"><font face="Georgia, serif"><font>20</font></font></p> </td> <td width="24%"> <p align="LEFT">Links from .edu and .gov sites</p> </td> <td width="62%"> <p align="LEFT">These links are precious because .edu and .gov sites are more reputable than .com. .biz, .info, etc. domains. Additionally, such links are hard to obtain. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT"><font face="Georgia, serif"><font>21</font></font></p> </td> <td width="24%"> <p align="LEFT">Number of <a href="http://www.webconfs.com/importance-of-backlinks-article-5.php">backlinks</a></p> </td> <td width="62%"> <p align="LEFT">Generally the more, the better. But the reputation of the sites that link to you is more important than their number. Also important is their anchor text, is there a keyword in it, how old are they, etc.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">22</p> </td> <td width="24%"> <p align="LEFT">Anchor text of internal links</p> </td> <td width="62%"> <p align="LEFT">This also matters, though not as much as the anchor text of inbound links.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">23</p> </td> <td width="24%"> <p align="LEFT">Around-the-anchor text</p> </td> <td width="62%"> <p align="LEFT">The text that is immediately before and after the anchor text also matters because it further indicates the relevance of the link – i.e. if the link is artificial or it naturally flows in the text. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">24</p> </td> <td width="24%"> <p align="LEFT">Age of inbound links</p> </td> <td width="62%"> <p align="LEFT">The older, the better. Getting many new links in a short time suggests buying them. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">25</p> </td> <td width="24%"> <p align="LEFT">Links from directories</p> </td> <td width="62%"> <p align="LEFT"> Could work, though it strongly depends on which directories. Being listed in DMOZ, Yahoo Directory and similar directories is a great boost for your ranking but having tons of links from PR0 directories is useless or even harmful because it can even be regarded as link spamming, if you have hundreds or thousands of such links. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">26</p> </td> <td width="24%"> <p align="LEFT">Number of outgoing links on the page that links to you</p> </td> <td width="62%"> <p align="LEFT">The fewer, the better for you because this way your link looks more important. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">27</p> </td> <td width="24%"> <p align="LEFT">Named anchors</p> </td> <td width="62%"> <p align="LEFT">Named anchors (the target place of internal links) are useful for internal navigation but are also useful for SEO because you stress additionally that a particular page, paragraph or text is important. In the code, named anchors look like this: <A href= "#dogs">Read about dogs</A> and "#dogs" is the named anchor. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">28</p> </td> <td width="24%"> <p align="LEFT">IP address of inbound link</p> </td> <td width="62%"> <p align="LEFT"><a href="http://www.mattcutts.com/blog/myth-busting-virtual-hosts-vs-dedicated-ip-addresses/">Google denies</a> that they discriminate against links that come from the same IP address or C class of addresses, so for Google the IP address can be considered neutral to the weight of inbound links. However, Bing and Yahoo! may discard links from the same IPs or IP classes, so it is always better to get links from different IPs.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">29</p> </td> <td width="24%"> <p align="LEFT">Inbound links from link farms and other suspicious sites </p> </td> <td width="62%"> <p align="LEFT"> Presumably, this does not affect you, provided the links are not reciprocal. The idea is that it is beyond your control to define what a link farm links to, so you don't get penalized when such sites link to you because this is not your fault. However, some recent changes to the Google algorithm suggest the opposite. This is why, you must always stay away from link farms and other suspicious sites or if you see they link to you, contact their webmaster and ask the link to be removed. </p> </td> <td width="6%"> <p align="CENTER"><font class="">0</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">30</p> </td> <td width="24%"> <p align="LEFT">Many outgoing links</p> </td> <td width="62%"> <p align="LEFT">Google does not like pages that consists mainly of links, so you'd better keep them under 100 per page. Having many outgoing links does not get you any benefits in terms of ranking and could even make your situation worse.</p> </td> <td width="6%"> <p align="CENTER"><font class="">-1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">31</p> </td> <td width="24%"> <p align="LEFT">Excessive linking, link spamming</p> </td> <td width="62%"> <p align="LEFT">It is bad for your rankings, when you have many links to/from the same sites (even if it is not a cross- linking scheme or links to bad neighbors) because it suggests link buying or at least spamming. In the best case only some of the links are taken into account for SEO rankings.</p> </td> <td width="6%"> <p align="CENTER"><font class="">-1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">32</p> </td> <td width="24%"> <p align="LEFT">Outbound links to link farms and other suspicious sites</p> </td> <td width="62%"> <p align="LEFT">Unlike inbound links from link farms and other suspicious sites, outbound links to <a href="http://www.webconfs.com/bad-neighborhood-article-13.php">bad neighbors</a> can drown you. You need periodically to check the status of the sites you link to because sometimes good sites become bad neighbors and vice versa. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-3</font></p> </td> </tr> <tr valign="TOP"> <td width="7%"> <p align="LEFT">33</p> </td> <td width="24%"> <p align="LEFT">Cross-linking</p> </td> <td width="62%"> <p align="LEFT">Cross-linking occurs when site A links to site B, site B links to site C and site C links back to site A. This is the simplest example but more complex schemes are possible. Cross-linking looks like disguised reciprocal link trading and is penalized. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">34</p> </td> <td width="24%"> <p align="LEFT">Single pixel links</p> </td> <td width="62%"> <p align="LEFT">when you have a link that is a pixel or so wide it is invisible for humans, so nobody will click on it and it is obvious that this link is an attempt to manipulate search engines. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT"><br> </p> </td> <td colspan="3" width="93%"> <p align="LEFT"><font size="4"><b>Metatags </b></font> </p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">35</p> </td> <td width="24%"> <p align="LEFT"><Description> metatag</p> </td> <td width="62%"> <p align="LEFT">Metatags are becoming less and less important but if there are metatags that still matter, these are the <description> and <keywords> ones. Use the <Description> metatag to write the description of your site. Besides the fact that metatags still rock on Bing and Yahoo!, the <Description> metatag has one more advantage – it sometimes pops in the description of your site in search results. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">36</p> </td> <td width="24%"> <p align="LEFT"><Keywords> metatag</p> </td> <td width="62%"> <p align="LEFT">The <Keywords> metatag also matters, though as all metatags it gets almost no attention from Google and some attention from Bing and Yahoo! Keep the metatag reasonably long – 10 to 20 keywords at most. Don't stuff the <Keywords> tag with keywords that you don't have on the page, this is bad for your rankings. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">37</p> </td> <td width="24%"> <p align="LEFT"><Language> metatag</p> </td> <td width="62%"> <p align="LEFT">If your site is language-specific, don't leave this tag empty. Search engines have more sophisticated ways of determining the language of a page than relying on the <language>metatag but they still consider it. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">38</p> </td> <td width="24%"> <p align="LEFT"><Refresh> metatag</p> </td> <td width="62%"> <p align="LEFT">The <Refresh> metatag is one way to redirect visitors from your site to another. Only do it if you have recently migrated your site to a new domain and you need to temporarily redirect visitors. When used for a long time, the <refresh> metatag is regarded as unethical practice and this can hurt your ratings. In any case, redirecting through 301 is much better. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT"><br> </p> </td> <td colspan="3" width="93%"> <p align="LEFT"><font size="4"><b>Content </b></font> </p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">39</p> </td> <td width="24%"> <p align="LEFT">Unique content</p> </td> <td width="62%"> <p align="LEFT">Having more content (relevant content, which is different from the content on other sites both in wording and topics) is a real boost for your site's rankings. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">40</p> </td> <td width="24%"> <p align="LEFT">Frequency of content change</p> </td> <td width="62%"> <p align="LEFT">Frequent changes are favored. It is great when you constantly add new content but it is not so great when you only make small updates to existing content. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">41</p> </td> <td width="24%"> <p align="LEFT">Keywords font size</p> </td> <td width="62%"> <p align="LEFT">When a keyword in the document text is in a larger font size in comparison to other on-page text, this makes it more noticeable, so therefore it is more important than the rest of the text. The same applies to headings (<h1>, <h2>, etc.), which generally are in larger font size than the rest of the text. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">42</p> </td> <td width="24%"> <p align="LEFT">Keywords formatting</p> </td> <td width="62%"> <p align="LEFT">Bold and italic are another way to emphasize important words and phrases. However, use bold, italic and larger font sizes within reason because otherwise you might achieve just the opposite effect. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">43</p> </td> <td width="24%"> <p align="LEFT">Age of document </p> </td> <td width="62%"> <p align="LEFT">Recent documents (or at least regularly updated ones) are favored.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">44</p> </td> <td width="24%"> <p align="LEFT">File size</p> </td> <td width="62%"> <p align="LEFT"> Generally long pages (i.e. 1,500-2,000 words or more) are not favored, or at least you can achieve better rankings if you have 3 short (500-1,000 words) rather than 1 long page on a given topic, so split long pages into multiple smaller ones. On the other hand, pages with 100-200 words of text or less are also disliked by Google. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">45</p> </td> <td width="24%"> <p align="LEFT">Content separation</p> </td> <td width="62%"> <p align="LEFT">From a marketing point of view content separation (based on IP, browser type, etc.) might be great but for SEO it is bad because when you have one URL and differing content, search engines get confused what the actual content of the page is. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">46</p> </td> <td width="24%"> <p align="LEFT">Poor coding and design</p> </td> <td width="62%"> <p align="LEFT">Search engines say that they do not want poorly designed and coded sites, though there are hardly sites that are banned because of messy code or ugly images but when the design and/or coding of a site is poor, the site might not be indexable at all, so in this sense poor code and design can harm you a lot.</p> </td> <td width="6%"> <p align="CENTER"><font class="">-2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">47</p> </td> <td width="24%"> <p align="LEFT">Illegal Content</p> </td> <td width="62%"> <p align="LEFT">Using other people's copyrighted content without their permission or using content that promotes legal violations can get you kicked out of search engines.</p> </td> <td width="6%"> <p align="CENTER"><font class="">-3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">48</p> </td> <td width="24%"> <p align="LEFT">Invisible text</p> </td> <td width="62%"> <p align="LEFT">This is a black hat SEO practice and when spiders discover that you have text specially for them but not for humans, don't be surprised by the penalty. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">49</p> </td> <td width="24%"> <p align="LEFT">Cloaking</p> </td> <td width="62%"> <p align="LEFT">Cloaking is another illegal technique, which partially involves content separation because spiders see one page (highly-optimized, of course), and everybody else is presented with another version of the same page.</p> </td> <td width="6%"> <p align="CENTER"><font class="">-3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">50</p> </td> <td width="24%"> <p align="LEFT">Doorway pages</p> </td> <td width="62%"> <p align="LEFT">Creating pages that aim to trick spiders that your site is a highly-relevant one when it is not, is another way to get the kick from search engines.</p> </td> <td width="6%"> <p align="CENTER"><font class="">-3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">51</p> </td> <td width="24%"> <p align="LEFT">Duplicate content </p> </td> <td width="62%"> <p align="LEFT">When you have the same content on several pages on the site, this will not make your site look larger because the <a href="http://www.webconfs.com/duplicate-content-filter-article-1.php">duplicate content</a> penalty kicks in. To a lesser degree duplicate content applies to pages that reside on other sites but obviously these cases are not always banned – i.e. article directories or mirror sites do exist and prosper.</p> </td> <td width="6%"> <p align="CENTER"><font class="">-3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT"><br> </p> </td> <td colspan="3" width="93%"> <p align="LEFT"><b><font size="4">Visual Extras and SEO</font></b> </p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">52</p> </td> <td width="24%"> <p align="LEFT">JavaScript</p> </td> <td width="62%"> <p align="LEFT">If used wisely, it will not hurt. But if your main content is displayed through JavaScript, this makes it more difficult for spiders to follow and if JavaScript code is a mess and spiders can't follow it, this will definitely hurt your ratings.</p> </td> <td width="6%"> <p align="CENTER"><font class="">0</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">53</p> </td> <td width="24%"> <p align="LEFT">Images in text</p> </td> <td width="62%"> <p align="LEFT">Having a text-only site is so boring but having many images and no text is a SEO sin. Always provide in the <alt> tag a meaningful description of an image but don't stuff it with keywords or irrelevant information.</p> </td> <td width="6%"> <p align="CENTER"><font class="">0</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">54</p> </td> <td width="24%"> <p align="LEFT">Podcasts and videos </p> </td> <td width="62%"> <p align="LEFT">Podcasts and videos are becoming more and more popular but as with all non-textual goodies, search engines can't read them, so if you don't have the tapescript of the podcast or the video, it is as if the podcast or movie is not there because it will not be indexed by search engines. </p> </td> <td width="6%"> <p align="CENTER"><font class="">0</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">55</p> </td> <td width="24%"> <p align="LEFT">Images instead of text links</p> </td> <td width="62%"> <p align="LEFT">Using images instead of text links is bad, especially when you don't fill in the <alt> tag. But even if you fill in the <alt> tag, it is not the same as having a bold, underlined, 16-pt. link, so use images for navigation only if this is really vital for the graphic layout of your site.</p> </td> <td width="6%"> <p align="CENTER"><font class="">-1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">56</p> </td> <td width="24%"> <p align="LEFT">Frames</p> </td> <td width="62%"> <p align="LEFT">Frames are very, very bad for SEO. Avoid using them unless really necessary. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">57</p> </td> <td width="24%"> <p align="LEFT">Flash</p> </td> <td width="62%"> <p align="LEFT">Spiders don't index the content of Flash movies, so if you use Flash on your site, don't forget to give it an alternative textual description. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">58</p> </td> <td width="24%"> <p align="LEFT">A Flash home page </p> </td> <td width="62%"> <p align="LEFT">Fortunately this epidemic disease seems to have come to an end. Having a Flash home page (and sometimes whole sections of your site) and no HTML version, is a SEO suicide.</p> </td> <td width="6%"> <p align="CENTER"><font class="">-3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT"><br> </p> </td> <td colspan="3" width="93%"> <p align="LEFT"><font size="4"><b>Domains, URLs, Web Mastery </b></font> </p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">59</p> </td> <td width="24%"> <p align="LEFT"><a href="http://www.webconfs.com/keyword-rich-domain-suggestions.php">Keyword-rich URLs and filenames</a> </p> </td> <td width="62%"> <p align="LEFT">A very important factor, especially for Yahoo! and Bing.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">60</p> </td> <td width="24%"> <p align="LEFT">Site Accessibility</p> </td> <td width="62%"> <p align="LEFT">Another fundamental issue, which that is often neglected. If the site (or separate pages) is unaccessible because of broken links, 404 errors, password-protected areas and other similar reasons, then the site simply can't be indexed. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+3</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">61</p> </td> <td width="24%"> <p align="LEFT">Sitemap</p> </td> <td width="62%"> <p align="LEFT">It is great to have a complete and up-to-date <a href="http://www.webconfs.com/importance-of-sitemaps-article-17.php">sitemap</a>, spiders love it, no matter if it is a plain old HTML sitemap or the special Google sitemap format. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">62</p> </td> <td width="24%"> <p align="LEFT">Site size</p> </td> <td width="62%"> <p align="LEFT">Spiders love large sites, so generally it is the bigger, the better. However, big sites become user-unfriendly and difficult to navigate, so sometimes it makes sense to separate a big site into a couple of smaller ones. On the other hand, there are hardly sites that are penalized because they are 10,000+ pages, so don't split your size in pieces only because it is getting larger and larger.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">63</p> </td> <td width="24%"> <p align="LEFT">Site age</p> </td> <td width="62%"> <p align="LEFT">Similarly to wine, <a href="http://www.webconfs.com/age-of-domain-and-serps-article-6.php">older sites are respected more</a>. The idea is that an old, established site is more trustworthy (they have been around and are here to stay) than a new site that has just poped up and might soon disappear. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">64</p> </td> <td width="24%"> <p align="LEFT">Site theme</p> </td> <td width="62%"> <p align="LEFT">It is not only keywords in URLs and on page that matter. The site theme is even more important for good ranking because when the site fits into one theme, this boosts the rankings of all its pages that are related to this theme.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">65</p> </td> <td width="24%"> <p align="LEFT">File Location on Site</p> </td> <td width="62%"> <p align="LEFT">File location is important and files that are located in the root directory or near it tend to rank better than files that are buried 5 or more levels below. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">66</p> </td> <td width="24%"> <p align="LEFT">Domains versus subdomains, separate domains</p> </td> <td width="62%"> <p align="LEFT">Having a separate domain is better – i.e. instead of having <a href="http://blablabla.blogspot.com">blablabla.blogspot.com</a>, register a separate <a href="http://blablabla.com">blablabla.com</a> domain. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">67</p> </td> <td width="24%"> <p align="LEFT">Top-level domains (TLDs)</p> </td> <td width="62%"> <p align="LEFT">Not all TLDs are equal. There are TLDs that are better than others. For instance, the most popular TLD – .com – is much better than .ws, .biz, or .info domains but (all equal) nothing beats an old .edu or .org domain. </p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">68</p> </td> <td width="24%"> <p align="LEFT">Hyphens in URLs</p> </td> <td width="62%"> <p align="LEFT">Hyphens between the words in an URL increase readability and help with SEO rankings. This applies both to hyphens in domain names and in the rest of the URL.</p> </td> <td width="6%"> <p align="CENTER"><font class="">+1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">69</p> </td> <td width="24%"> <p align="LEFT">URL length</p> </td> <td width="62%"> <p align="LEFT">Generally doesn't matter but if it is a very long URL-s, this starts to look spammy, so avoid having more than 10 words in the URL (3 or 4 for the domain name itself and 6 or 7 for the rest of address is acceptable).</p> </td> <td width="6%"> <p align="CENTER"><font class="">0</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">70</p> </td> <td width="24%"> <p align="LEFT">IP address</p> </td> <td width="62%"> <p align="LEFT">Could matter only for shared hosting or when a site is hosted with a free hosting provider, when the IP or the whole C-class of IP addresses is blacklisted due to spamming or other illegal practices. </p> </td> <td width="6%"> <p align="CENTER"><font class="">0</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">71</p> </td> <td width="24%"> <p align="LEFT">Adsense will boost your ranking</p> </td> <td width="62%"> <p align="LEFT">Adsense is not related in any way to SEO ranking. Google will definitely not give you a ranking bonus because of hosting Adsense ads. Adsense might boost your income but this has nothing to do with your search rankings. </p> </td> <td width="6%"> <p align="CENTER"><font class="">0</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">72</p> </td> <td width="24%"> <p align="LEFT">Adwords will boost your ranking</p> </td> <td width="62%"> <p align="LEFT">Similarly to Adsense, Adwords has nothing to do with your search rankings. Adwords will bring more traffic to your site but this will not affect your rankings in whatsoever way.</p> </td> <td width="6%"> <p align="CENTER"><font class="">0</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">73</p> </td> <td width="24%"> <p align="LEFT">Hosting downtime</p> </td> <td width="62%"> <p align="LEFT"><a href="http://www.webconfs.com/web-hosting.php">Hosting downtime</a> is directly related to accessibility because if a site is frequently down, it can't be indexed. But in practice this is a factor only if your hosting provider is really unreliable and has less than 97-98% uptime. Try using a reputed hosting provider such as <a href="http://secure.hostgator.com/%7Eaffiliat/cgi-bin/affiliates/clickthru.cgi?id=amitbhawnani" target="_blank" rel="nofollow">Hostgator</a> for hosting. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">74</p> </td> <td width="24%"> <p align="LEFT">Dynamic URLs </p> </td> <td width="62%"> <p align="LEFT">Spiders prefer static URLs, though you will see many dynamic pages on top positions. Long dynamic URLs (over 100 characters) are really bad and in any case you'd better use a tool to <a href="http://www.webconfs.com/url-rewriting-tool.php">rewrite dynamic URLs</a> in something more human- and SEO-friendly. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-1</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">75</p> </td> <td width="24%"> <p align="LEFT">Session IDs</p> </td> <td width="62%"> <p align="LEFT">This is even worse than dynamic URLs. Don't use session IDs for information that you'd like to be indexed by spiders. </p> </td> <td width="6%"> <p align="CENTER"><font class="">-2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">76</p> </td> <td width="24%"> <p align="LEFT">Bans in robots.txt</p> </td> <td width="62%"> <p align="LEFT">If indexing of a considerable portion of the site is banned, this is likely to affect the nonbanned part as well because spiders will come less frequently to a "noindex" site.</p> </td> <td width="6%"> <p align="CENTER"><font class="">-2</font></p> </td> </tr> <tr class="" valign="TOP"> <td width="7%"> <p align="LEFT">77</p> </td> <td width="24%"> <p align="LEFT">Redirects (301 and 302)</p> </td> <td width="62%"> <p align="LEFT">When not applied properly, <a href="http://www.webconfs.com/how-to-redirect-a-webpage.php">redirects</a> can hurt a lot – the target page might not open, or worse – a redirect can be regarded as a black hat technique, when the visitor is immediately taken to a different page.</p><p align="LEFT"><br></p><p align="LEFT">From: <a href="http://www.webconfs.com/15-minute-seo.php">http://www.webconfs.com/15-minute-seo.php</a><br></p><p align="LEFT"> <br></p> </td> <td width="6%"> <p align="CENTER"><font class="">-3</font></p> </td> </tr> </tbody> </table> </div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com1tag:blogger.com,1999:blog-7586695.post-70551578585430795802013-04-07T21:02:00.001+08:002013-04-07T21:02:43.248+08:00Multi-Lingual Wordpress<div dir="ltr">This article is very informative for deciding which plugin should be used for multi-lingual wordpress site. <div><a href="http://codex.wordpress.org/Multilingual_WordPress">http://codex.wordpress.org/Multilingual_WordPress</a><br> </div></div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-78325105284438761112013-03-28T11:12:00.001+08:002013-03-28T11:12:05.374+08:00Set proxy in command line.<div dir="ltr"><span class="">$</span> export http_proxy="http://username:password@foo.bar:8080"<br clear="all"><br> </div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-37653551258423724882013-03-28T10:52:00.001+08:002013-03-28T10:52:45.819+08:00Share folder on Virtualbox<div dir="ltr">How comes I need to check help file each time I want to use it? -_-!<br><div><br><div><ul type="disc"><li><p>In a Linux guest, use the following command:</p><pre class="">mount -t vboxsf [-o OPTIONS] sharename mountpoint</pre> <p>To mount a <font style="background-color:rgb(10,36,106)" color="#ffffff">shared</font> folder during boot, add the following entry to /etc/fstab:</p><pre class="">sharename mountpoint vboxsf defaults 0 0</pre></li></ul><br clear="all"><br></div></div></div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-40220887502431934962013-03-13T08:29:00.001+08:002013-03-13T08:29:47.674+08:00Reply from HM<p dir="ltr">We have currently been experiencing some issues with server slowdown related to a Joomla hack which has recently hit a number of accounts on our servers, which may be related to the issues you are seeing with your website. We are in the process of both deactivating the hacked accounts, and finding a way to block this hack across the board, so I would suggest that you wait some time and check back on the website. If you are still experiencing problems after that point, please reply back to this ticket and we will troubleshoot further.</p> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-72016158329600204342013-01-21T11:58:00.001+08:002013-01-21T11:58:18.415+08:00Revert a change in CVS<div dir="ltr"><a href="http://stackoverflow.com/questions/435368/how-do-i-revert-a-big-change-in-cvs">http://stackoverflow.com/questions/435368/how-do-i-revert-a-big-change-in-cvs</a><br clear="all"><br><pre><code>mkdir code_base1 && cd code_base1 cvs co -D "2008-12-30" modulename cvs tag code_base_2008_12_30 </code></pre> <p>Now do the join tag-based, subtracting all changes between now and 2008-12-30:</p> <pre><code>cd .. && mkdir code_base2 && cd code_base2 cvs co modulename cvs update -d -j HEAD -j code_base_2008_12_30 # use -d to resurrect deleted directories </code></pre> <p>Compare the contents of code_base1 and code_base2. They should be identical except for the CVS meta information. Finally commit the code as it was on 2008-12-30 as new HEAD:</p> <pre><code>cvs commit -m "Revert all changes this year" </code></pre> <hr> <p>Note that tagging the code you wish to join like this will not work, because rtag also does not handle removed files and directories correctly, when using -D:</p> </div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-13362864172248870692013-01-20T15:46:00.001+08:002013-01-20T15:46:07.865+08:00Adding www to WordPress 3.0+ Multisite/MU Root Domain<div dir="ltr"><br clear="all"><div><br></div>Here is original post:<div><a href="http://www.geekhelpguide.com/wordpress/adding-www-to-wordpress-3-0-multisitemu-root-domain/">http://www.geekhelpguide.com/wordpress/adding-www-to-wordpress-3-0-multisitemu-root-domain/</a><br> </div><div><br></div><div style>Generally, need to manually edit db table to change root domain back.</div><div style><br></div><div style>Still verifying if this caused any side effect.</div><div style><br></div></div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com1tag:blogger.com,1999:blog-7586695.post-38758882801626700412012-12-21T08:45:00.001+08:002012-12-21T08:45:51.444+08:00Foxconn postpones US$10B Indonesian plant investment due to regulatory requirements, labor concerns<p><a href="http://feedproxy.google.com/~r/e27/Kabk/~3/F-isiM5hjw8/">http://feedproxy.google.com/~r/e27/Kabk/~3/F-isiM5hjw8/</a></p> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-45453684028473958872012-12-21T08:42:00.001+08:002012-12-21T08:42:17.214+08:00Ericsson Will Take A $1.2B Hit On Decline Of ST-Ericsson Chip JV; Confirms It Won’t Buy STMicro’s Stake<p><a href="http://feedproxy.google.com/~r/Techcrunch/~3/XHXnTYj_jQI/">http://feedproxy.google.com/~r/Techcrunch/~3/XHXnTYj_jQI/</a></p> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-31877728277293732462012-12-21T08:36:00.001+08:002012-12-21T08:36:06.501+08:001M User Strong, PlanetSoho Makes it Easy for Small Businesses to ‘Get Paid’ On-the-Go<p><a href="http://feedproxy.google.com/~r/Techcrunch/~3/9qxKJJpi4o4/">http://feedproxy.google.com/~r/Techcrunch/~3/9qxKJJpi4o4/</a></p> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-62621345591438759172012-12-08T10:47:00.001+08:002012-12-08T10:47:14.283+08:00The 30 Best Web 2.0 Tools For Teachers (2012 Edition)<div><a href="http://edudemic.com/2012/10/best-web-tools-2012/">http://edudemic.com/2012/10/best-web-tools-2012/</a><br></div><div><br></div><div><br></div><h2 style="border:0px;margin:6px 0px;padding:0px;outline:0px;font-size:2.1em;line-height:1.2em;color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif"> Edudemic's Recommendations</h2><p style="margin:0px 0px 12px;color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif;font-size:15px;line-height:22.5px">If you're looking to try out some of these tools, here are the top 5 tools we recommend you try out (if you haven't already).</p> <p style="margin:0px 0px 12px;color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif;font-size:15px;line-height:22.5px"><strong style="border:0px;margin:0px;padding:0px;outline:0px">Slideshare -</strong> Get the credit and audience you deserve for your presentations! They may be embedded in a website just like this one or even on a fancier site like the NYTimes, etc.</p> <p style="margin:0px 0px 12px;color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif;font-size:15px;line-height:22.5px"><strong style="border:0px;margin:0px;padding:0px;outline:0px">Scoop.it -</strong> A stellar social bookmarking service that is being used by a ton of teachers right now. We try our best to keep <a href="http://www.scoop.it/u/edudemic" target="_blank" style="border:0px;margin:0px;padding:0px;outline:0px;text-decoration:initial;color:rgb(0,96,154)">the Edudemic Scoop.it feed</a> updated!</p> <p style="margin:0px 0px 12px;color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif;font-size:15px;line-height:22.5px"><strong style="border:0px;margin:0px;padding:0px;outline:0px">PlanBoard -</strong> It's an online lesson planner made for teachers. Create, share, and manage lesson plans with simple and easy to use lesson plan templates.</p> <p style="margin:0px 0px 12px;color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif;font-size:15px;line-height:22.5px"><strong style="border:0px;margin:0px;padding:0px;outline:0px">Evernote -</strong> Featured in <a href="http://itunes.apple.com/us/app/edudemic-magazine/id495202697?mt=8" target="_blank" style="border:0px;margin:0px;padding:0px;outline:0px;text-decoration:initial;color:rgb(0,96,154)">Edudemic Magazine</a> numerous times, we love all things Evernote. It's insanely popular in education and useful for teachers, students, parents, and just about anyone who wants to remember what they've done.</p> <p style="margin:0px 0px 12px;color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif;font-size:15px;line-height:22.5px"><strong style="border:0px;margin:0px;padding:0px;outline:0px">Dropbox -</strong> I use Dropbox every day. I had to up to the 100GB size and feel like I'll never fill it up. Great for backing up everything, accessing files remotely (even from your smartphone and tablet) and sharing things. I've seen it used for handing in homework on a regular basis. Also, <a href="http://edudemic.com/2012/10/dropbox-giving-away-3gb-free-to-anyone-with-edu-address/" target="_blank" style="border:0px;margin:0px;padding:0px;outline:0px;text-decoration:initial;color:rgb(0,96,154)">you can get an extra 3GB free if you have a .edu address</a>!</p> <h2 style="border:0px;margin:6px 0px;padding:0px;outline:0px;font-size:2.1em;line-height:1.2em;color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif">The Best Web 2.0 Tools For Teachers</h2><ol style="border:0px;margin:0px;padding:0px 0px 0px 40px;outline:0px;color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif;font-size:15px;line-height:22.5px"> <li style="border:0px;margin:0px;padding:0px;outline:0px">Google Drive</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Dropbox</li><li style="border:0px;margin:0px;padding:0px;outline:0px">CloudMagic</li><li style="border:0px;margin:0px;padding:0px;outline:0px"> Jumpshare</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Weebly</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Issuu</li><li style="border:0px;margin:0px;padding:0px;outline:0px">ePubBud</li> <li style="border:0px;margin:0px;padding:0px;outline:0px">Infogr.am</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Text2MindMap</li><li style="border:0px;margin:0px;padding:0px;outline:0px">EdCanvas</li><li style="border:0px;margin:0px;padding:0px;outline:0px"> KeepVid</li><li style="border:0px;margin:0px;padding:0px;outline:0px">TubeChop</li><li style="border:0px;margin:0px;padding:0px;outline:0px">GoAnimate</li><li style="border:0px;margin:0px;padding:0px;outline:0px">TodaysMeet</li> <li style="border:0px;margin:0px;padding:0px;outline:0px">Slideshare</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Voki</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Prezi</li><li style="border:0px;margin:0px;padding:0px;outline:0px"> Record MP3</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Delicious</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Jing</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Pixlr</li> <li style="border:0px;margin:0px;padding:0px;outline:0px">Loopster</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Evernote</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Scoop.it</li><li style="border:0px;margin:0px;padding:0px;outline:0px"> Paper.li</li><li style="border:0px;margin:0px;padding:0px;outline:0px">LiveBinders</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Join.me</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Zamzar</li> <li style="border:0px;margin:0px;padding:0px;outline:0px">Poll Everywhere</li><li style="border:0px;margin:0px;padding:0px;outline:0px">VoiceThread</li><li style="border:0px;margin:0px;padding:0px;outline:0px">PlanBoard</li> <li style="border:0px;margin:0px;padding:0px;outline:0px">TeachersPayTeachers (TPT)</li><li style="border:0px;margin:0px;padding:0px;outline:0px">Gnowledge</li></ol> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-79684326337681554492012-12-02T02:08:00.001+08:002012-12-02T02:08:34.659+08:00Tutor tutor<div>Finally, got this tutor website.</div><div><br></div><a href="http://www.tutorchen.com/web/">http://www.tutorchen.com/web/</a><br> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-63879930459843986952012-11-03T01:09:00.001+08:002012-11-03T01:09:56.823+08:00Local Time Differencewordpress WP-o-Matic plugin <div>wp set to UTC+8</div><div>server time is MDT (UTC-6)</div><div>So server time is 14 hours later.</div><div>So is the cron job.</div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com1tag:blogger.com,1999:blog-7586695.post-44970246995209674482012-10-27T19:03:00.001+08:002012-10-27T19:03:27.916+08:00VC<div><br></div><div>Break into VC</div><a href="http://www.mergersandinquisitions.com/break-into-venture-capital/">http://www.mergersandinquisitions.com/break-into-venture-capital/</a> <div><br></div><div>What do you do as a Venture Capitalist ?</div><div><a href="http://www.mergersandinquisitions.com/venture-capital-on-the-job/">http://www.mergersandinquisitions.com/venture-capital-on-the-job/</a></div> <div><br></div><div>VC vs PE</div><div>in summary :</div><div><p style="margin:0px;padding:0px 0px 15px;color:rgb(68,68,68);font-family:Tahoma,Arial,Verdana,sans-serif;font-size:15px;line-height:18px;background-color:rgb(255,255,255)"> It depends on your goals – if you're trying to make the most amount of money in the shortest amount of time possible, PE is better.</p><p style="margin:0px;padding:0px 0px 15px;color:rgb(68,68,68);font-family:Tahoma,Arial,Verdana,sans-serif;font-size:15px;line-height:18px;background-color:rgb(255,255,255)"> If you're from a pure finance background and you like the work and transaction experience you get in banking, PE is better.</p><p style="margin:0px;padding:0px 0px 15px;color:rgb(68,68,68);font-family:Tahoma,Arial,Verdana,sans-serif;font-size:15px;line-height:18px;background-color:rgb(255,255,255)"> If you're more interested in starting your own company one day, you prefer relationships to analysis, or you want a better work-life balance, VC is better.</p></div><div><a href="http://www.mergersandinquisitions.com/private-equity-vs-venture-capital/">http://www.mergersandinquisitions.com/private-equity-vs-venture-capital/</a></div> <div><br></div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0tag:blogger.com,1999:blog-7586695.post-34171653451922589272012-10-26T23:31:00.001+08:002012-10-26T23:31:45.059+08:00Why companies Hire Consultants<p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)"><a href="http://managementconsulted.com/consulting-skills/6-reasons-why-companies-hire-management-consultants-that-charge-2-million-for-3-months-of-work/#">http://managementconsulted.com/consulting-skills/6-reasons-why-companies-hire-management-consultants-that-charge-2-million-for-3-months-of-work/#</a></p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)">Today's post departs from its usual <a href="http://managementconsulted.com/2009/02/18/how-to-get-a-consulting-job-in-a-tough-economy-notes-from-recruiting-talks/" style="padding:0px;margin:0px;text-decoration:none;color:rgb(35,97,161)">focus on recruiting</a> to take a <a href="http://managementconsulted.com/dictionary/" style="padding:0px;margin:0px;text-decoration:none;color:rgb(35,97,161)">5,000 mile view</a> of the consulting industry and its purpose.</p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)">Consultants can have a negative reputation – <strong style="padding:0px;margin:0px">charging $2 million for 12 week's work</strong><br style="padding:0px;margin:0px"> that results in stacks of PowerPoint slides, all of which are archived into a dusty closet (digital or otherwise) soon after<em style="padding:0px;margin:0px">McKBain Group</em> leaves the premises.</p><p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)"> When consultants' recommendations are implemented, employees often argue that the actions are not beneficial and <strong style="padding:0px;margin:0px">don't reflect day-to-day business realities</strong>.</p><p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)"> That's one side of the story.</p><p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)">Below, I'll paint a more positive (and personally held) view on the <strong style="padding:0px;margin:0px">6 reasons why companies hire consultants</strong>. Through it, you'll have a better view on <a href="http://managementconsulted.com/2008/12/11/management-consulting-and-the-consulting-industry-101/" style="padding:0px;margin:0px;text-decoration:none;color:rgb(35,97,161)">business consulting and the consulting industry</a> as a potential career.</p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)">1) <strong style="padding:0px;margin:0px">Staff augmentation</strong> – the least impactful role that consultants can play and self-explanatory. Companies often have <strong style="padding:0px;margin:0px">short to medium-term staffing needs</strong> (in the case of government work, this can extend for several years) due to a variety of factors (eg, recent downsizings, sudden expansion). Consultants in this situation "plug a hole" for the company <strong style="padding:0px;margin:0px">by filling the role of full-time employees</strong>. While expensive, it's <strong style="padding:0px;margin:0px">common work for operational consultancies</strong> (eg, <a href="http://www.deloitte.com/" style="padding:0px;margin:0px;text-decoration:none;color:rgb(35,97,161)">Deloitte</a> and<a href="http://www.accenture.com/" style="padding:0px;margin:0px;text-decoration:none;color:rgb(35,97,161)">Accenture</a>) and, to a lesser extent, for <a href="http://managementconsulted.com/2009/01/13/life-as-a-consultant-an-interview-with-a-consultant-from-booz-allen/" style="padding:0px;margin:0px;text-decoration:none;color:rgb(35,97,161)">government consultancies</a> (eg, Booz Allen)</p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)"><em style="padding:0px;margin:0px">Further reading:</em> <a href="http://managementconsulted.com/consulting-interviews/life-as-a-consultant-an-interview-with-a-consultant-from-booz-allen/" style="padding:0px;margin:0px;text-decoration:none;color:rgb(35,97,161)">Interview with a Booz Allen consultant</a></p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)"><span id="more-1127" style="padding:0px;margin:0px"></span></p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)">2) <strong style="padding:0px;margin:0px">External change force aka "political cover"</strong>. It can be hard for companies to do what's right (<a href="http://en.wiktionary.org/wiki/sacred_cow" style="padding:0px;margin:0px;text-decoration:none;color:rgb(35,97,161)">sacred cows</a> and all that jazz) – particularly when it comes to <strong style="padding:0px;margin:0px">job layoffs, salary and benefit changes/reduction, major operational and strategic shifts</strong>. Hiring consultants can be a way to reach the desired conclusions <strong style="padding:0px;margin:0px">with sufficient political cover in case certain parties are unhappy</strong> (eg, a displeased Board or disgruntled employees) or things go wrong ("Despite the significant cost uptick, <em style="padding:0px;margin:0px">we implemented BCG's recommendations to the letter</em> – I'm not sure what we could have done better")</p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)">3) <strong style="padding:0px;margin:0px">Best practices across industries and functions</strong> (eg, organization, supply chain) – consultants have the rare privilege of:</p> <ul style="padding:0px;margin:0px 0px 1.538em 1.538em;list-style:square;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)"><li style="padding:0px;margin:0px"> Serving multiple clients in the same sector (eg, Beverages, Enterprise Software)</li><li style="padding:0px;margin:0px">Serving multiple clients facing similar problems across different sectors (eg, Latin American expansion, Southeast Asia outsourcing)</li> </ul><p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)">This enables them to <strong style="padding:0px;margin:0px">recognize common attributes of effective solutions</strong>, applying lessons learned in applicable situations. This knowledge is partially institutionalized at each consulting firm (in the form of white papers, databases, post-project reviews, etc); however, much of the information exists in <strong style="padding:0px;margin:0px">the collective heads of partners and to a lesser extent, senior consultants</strong>.</p> <p class="alert" style="padding:0.538em 0.769em;margin:0px 0px 1.538em;background-color:rgb(255,255,160);border:1px solid rgb(229,229,151);color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px"> A former McKinsey partner put it best when he called business consultants "masters at reinventing the wheel"</p><p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)"> 4) <strong style="padding:0px;margin:0px">Analytical horsepower</strong></p><p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)"> A corollary to staff augmentation, companies may need help solving issues and executing strategies where their skillsets and knowledge are insufficient. Consultants can be of great value given their training and capabilities. A note here on <a href="http://managementconsulted.com/2008/12/12/recruiting-decisions-what-is-the-difference-between-global-management-consulting-firms-and-boutique-consulting-firms/" style="padding:0px;margin:0px;text-decoration:none;color:rgb(35,97,161)">big vs boutique</a>: big consultancies have a<strong style="padding:0px;margin:0px">breadth of resources</strong> that they can bring to bear on problems (eg, data mining and analytics, primary market research). Boutiques may have <strong style="padding:0px;margin:0px">specialized expertise on specific dimensions</strong> (eg, retail pricing best practices, financial industry benchmarks).</p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)"><em style="padding:0px;margin:0px">Further reading:</em> <a href="http://managementconsulted.com/2008/12/12/recruiting-decisions-what-is-the-difference-between-global-management-consulting-firms-and-boutique-consulting-firms/" style="padding:0px;margin:0px;text-decoration:none;color:rgb(35,97,161)">Global consulting firms versus boutiques</a></p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)">5) <strong style="padding:0px;margin:0px">Fresh perspective</strong></p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)">Companies often need <strong style="padding:0px;margin:0px">a fresh set of eyes</strong> – you'd be amazed at the amount of value consultants can add based on the <strong style="padding:0px;margin:0px">most mundane observations and insights</strong>. Critics contend that this is an example of consultants selling "glorified common sense", but for front-line client employees, it can be easy to fall into daily routines without a critical eye towards measurement, analysis, and improvement.</p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)">6) <strong style="padding:0px;margin:0px">Training and skillset augmentation</strong></p> <p style="padding:0px;margin:0px 0px 1.538em;color:rgb(17,17,17);font-family:Verdana,sans-serif;font-size:13px;line-height:19.983333587646484px;background-color:rgb(255,255,255)">I'd argue that every consulting project – particularly ones with <a href="http://managementconsulted.com/2008/12/15/day-in-the-life-of-a-management-consultant-client-version/" style="padding:0px;margin:0px;text-decoration:none;color:rgb(35,97,161)">heavy client interaction</a> – incorporates client training as a major ingredient. The best recommendations are worthless if clients can't implement and maintain suggested changes. Thus, a large part of what consultants do is educate client employees on necessary knowledge, skills, and mindsets.</p> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com1tag:blogger.com,1999:blog-7586695.post-2702456364879385512012-10-20T00:10:00.001+08:002012-10-20T00:10:12.239+08:00Projects1. Soundbar - Renasas R8C MCU + Intersil DAE-4p<div> a. remote control</div><div> b. LED / LCD indicator</div><div> c. 2.0/2.1 channle</div><div> d. 4 buildin sound effect</div><div> e. different EQ settings</div> <div> f. Wired/wireless subwoofer</div><div><br><div>2. 2.4G remote control - Nordic solution LE1 + LU1 </div><div> a. PWM output</div><div> b. buttons to report page up/down</div><div> c. working mode indicating</div> <div><br></div><div>3. NEC IR protocol - MSP430 implementation</div><div><br></div><div>4. UPS Control - Freescale JS16</div><div> USB HID Power class</div><div><br></div><div>5. Remote Keyboard - Nordic solution</div> <div>6. FTK touch pad for windows 8 - ST solution, absolute value, support windows 8 multitouch gestures.</div><div> a. convert I2C data to USB and report to windows 8</div><div> b. ST MCU to convert touch panel data to standard USB HID data</div> <div> c. support mult-touch and gestures defined in windows 8</div><div> d. need more to enable track pad.</div><div><br></div><div>7. Remote Keyboard + touch pad - nordic + elan</div><div> a. remote key board CAP led</div> <div> b. paring scheme</div><div> c. switch touch pad running mode</div><div> </div><div>8. DALI lighting slave MCU - freescal SH8</div><div> a. IEC 60386 - 101/102/107 standard</div><div> b. extra input to smooth PWM output</div> <div> c. over heat protect</div><div> d. analog signal to adjust output</div><div><br></div></div> Easonhttp://www.blogger.com/profile/07464723858152664519noreply@blogger.com0