Uncategorized Archives - Vincent Verloop https://www.vincentverloop.nl/category/uncategorized/ IT Professional Thu, 15 Feb 2024 12:06:31 +0000 nl-NL hourly 1 88936650 How to Install Nginx with Fast_CGI + Varnish Cache on AlmaLinux OS https://www.vincentverloop.nl/uncategorized/how-to-install-varnish-cache-with-nginx-on-almalinux-os/ https://www.vincentverloop.nl/uncategorized/how-to-install-varnish-cache-with-nginx-on-almalinux-os/#respond Sun, 23 Oct 2022 19:22:34 +0000 https://www.vincentverloop.nl/?p=3123 Varnish Cache is an HTTP accelerator and reverse proxy specially designed for heavily loaded dynamic web sites as well as APIs. It acts as a middleman between your client and server. Varnish works by handling requests before they make it to your backend. If Varnish doesn’t have a request cached, it will forward the request […]

The post How to Install Nginx with Fast_CGI + Varnish Cache on AlmaLinux OS appeared first on Vincent Verloop.

]]>
Varnish Cache is an HTTP accelerator and reverse proxy specially designed for heavily loaded dynamic web sites as well as APIs. It acts as a middleman between your client and server. Varnish works by handling requests before they make it to your backend. If Varnish doesn’t have a request cached, it will forward the request to your backend and then cache its output.

This process dramatically increases the performance of your web server. Varnish is famously useful and is employed by many companies such as Wired, Urban Dictionary, Zappos, Technorati, DynDNS, OpenDNS, and many more. One of the key features of Varnish is the flexibility of its configuration language (VCL) which allows you to write policies on how incoming requests should be handled.

In this tutorial, we will learn how to set up Varnish caching with Nginx on CentOS 8. We will set up Nginx to listen on port 8080 and work as a backend server, then configure Varnish to listen on default HTTP port 80.

Prerequisites

  • A fresh AlmaLinux OS VPS
  • A root password configured on your server

 

Create a new, choosing CentOS 8 as the operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Step 1 – Update OS & Install Required Packages

First, log in to your AlmaLinux Server with SSH. 

Once you are logged in to your CentOS 8 server, run the following command to update your base system with the latest available packages.

dnf update -y

Step 2 – Install Varnish Cache

By default, the Varnish package is available in the CentOS 8 system. You can install it by just running the following command:

dnf install varnish -y

After installing Varnish, start the Varnish service and enable it to start after system reboot with the following command:

systemctl start varnish
systemctl enable varnish

Next, verify the status of Varnish with the following command:

systemctl status varnish

You should get the following output:

By default, Varnish listens on port 6081. You can verify it using the following command:

netstat -ltnp | grep 6081

You should get the following output:

tcp        0      0 0.0.0.0:6081            0.0.0.0:*               LISTEN      1508/varnishd      
tcp6       0      0 :::6081                 :::*                    LISTEN      1508/varnishd      


Step 3 – Install and Configure Nginx

Next, you will need to install the Nginx web server and configure it to work with the Varnish cache.

First, install the Nginx server with the following command:

dnf install nginx -y

After installing the Nginx web server, you will need to change the Nginx web server listening port from 80 to 8080.

You can do it by editing the file /etc/nginx/nginx.conf.

nano /etc/nginx/nginx.conf

Find the following line:

listen       80 default_server;
listen       [::]:80 default_server;

And replace it with the following line:

listen       8080 default_server;
listen       [::]:8080 default_server;

Save and close the file, then start the Nginx service and enable it to start after system reboot:

systemctl start nginx
systemctl enable nginx

Note: If you are using virtual hosting, then configure the relevant configuration file.

Step 4 – Configure Varnish to Work with Nginx

By default, Varnish is configured to listen on port 6081, so you will need to configure it to listen on port 80. You can configure it by editing varnish.service configuration file:

nano /usr/lib/systemd/system/varnish.service

Find the following line:

ExecStart=/usr/sbin/varnishd -a :6081 -f /etc/varnish/default.vcl -s malloc,256m

And replace it with the following line:

ExecStart=/usr/sbin/varnishd -a :80 -f/etc/varnish/default.vcl -s malloc,256m

Save and close the file, then reload the systemd daemon with the following command:

systemctl daemon-reload

Next, restart the Varnish service to apply the changes:

systemctl restart varnish

Step 5 – Configure Nginx as a Backend Server for Varnish

Next, you will need to configure Nginx as a backend server for the Varnish proxy.

You can configure it by editing the file /etc/varnish/default.vcl:

nano /etc/varnish/default.vcl

Check to ensure the following lines are uncommented:

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

Save and close the file when you are finished.

Note: Change the line 127.0.0.1 with your Nginx server IP address if your Nginx server resides on the other host. Change the port 8080 with the port number of your Nginx server.

Step 6 – Verify Varnish Cache

At this point, the Varnish cache is configured to work with the Nginx webserver. It’s time to test whether caching is working or not.

You can test it using the curl command:

curl -I http://your-server-ip

You should get the HTTP header information in the following output:

Next, run this command again:

curl -I http://your-server-ip

You should get the Varnish cached response in Age header (X-Varnish):

You can also test the Varnish cache using varnishlog command with curl command to view Varnish activity as it happens:

varnishlog

You should get the following output:

Conclusion

Congratulations! You have successfully installed and configured Varnish Cache with an Nginx web server on CentOS 8. Now your Nginx web server has a Varnish Cache server in front of it. You will need to add additional configuration to get the full benefit from it.

The post How to Install Nginx with Fast_CGI + Varnish Cache on AlmaLinux OS appeared first on Vincent Verloop.

]]>
https://www.vincentverloop.nl/uncategorized/how-to-install-varnish-cache-with-nginx-on-almalinux-os/feed/ 0 3123
How to fix drag and drop / copy and paste in Vmware Fusion https://www.vincentverloop.nl/uncategorized/how-to-fix-drag-and-drop-copy-and-paste-vmware-fusion/ https://www.vincentverloop.nl/uncategorized/how-to-fix-drag-and-drop-copy-and-paste-vmware-fusion/#respond Tue, 13 Feb 2018 14:05:32 +0000 https://www.vincentverloop.nl/?p=1459 Remove Open Vmware Tools. Install Vmware Tools. To enable advanced X features (e.g., guest resolution fit, drag and drop, and file and text copy/paste), you will need to do one (or more) of the following: 1. Manually start /usr/bin/vmware-user 2. Log out and log back into your desktop session 3. Restart your X session.

The post How to fix drag and drop / copy and paste in Vmware Fusion appeared first on Vincent Verloop.

]]>
Remove Open Vmware Tools. Install Vmware Tools.

To enable advanced X features (e.g., guest resolution fit, drag and drop, and
file and text copy/paste), you will need to do one (or more) of the following:
1. Manually start /usr/bin/vmware-user
2. Log out and log back into your desktop session
3. Restart your X session.

The post How to fix drag and drop / copy and paste in Vmware Fusion appeared first on Vincent Verloop.

]]>
https://www.vincentverloop.nl/uncategorized/how-to-fix-drag-and-drop-copy-and-paste-vmware-fusion/feed/ 0 1459
How to use AWUS036ACH (rtl8812au) with Kali Linux https://www.vincentverloop.nl/uncategorized/how-to-use-awus036ach-rtl8812au-with-kali-linux/ https://www.vincentverloop.nl/uncategorized/how-to-use-awus036ach-rtl8812au-with-kali-linux/#comments Sat, 29 Apr 2017 13:30:00 +0000 https://www.vincentverloop.nl/?p=1342 Kali Linux 2017.1 release now supports RTL8812AU Wireless Card Injection. These drivers are not part of the standard Linux kernel, and have been modified to allow for injection. This chipset supports 802.11 AC, making this one of the first drivers to bring injection-related wireless attacks to this standard, and with companies such as ALFA making […]

The post How to use AWUS036ACH (rtl8812au) with Kali Linux appeared first on Vincent Verloop.

]]>
Kali Linux 2017.1 release now supports RTL8812AU Wireless Card Injection. These drivers are not part of the standard Linux kernel, and have been modified to allow for injection. This chipset supports 802.11 AC, making this one of the first drivers to bring injection-related wireless attacks to this standard, and with companies such as ALFA making the AWUS036ACH wireless cards, it’s expected that this card will be an arsenal favourite.

The driver can be installed using the following commands:

apt-get update
apt-get install realtek-rtl88xxau-dkms

Start monitor mode:
ip dev
ip link set wlan0 down
iwconfig wlan0 mode monitor
ip link set wlan0 up

Start managed mode:
ip dev
ip link set wlan0 down
iwconfig wlan0 mode managed
ip link set wlan0 up

The driver is default in high performance mode: 18 dbm instead of 12 dbm.

IMPORTANT: When using Kali VM in Vmware: Change USB setting in Vmware from USB 2.0 to USB 3.0.
This will give the card full power, from 12dbm to 18dbm.

Troubeshooting
modprobe rfkill
rfkill list
rfkill unblock wifi

The post How to use AWUS036ACH (rtl8812au) with Kali Linux appeared first on Vincent Verloop.

]]>
https://www.vincentverloop.nl/uncategorized/how-to-use-awus036ach-rtl8812au-with-kali-linux/feed/ 10 1342
Django CMS + NPM + Webpack + Babel + Uikit + React https://www.vincentverloop.nl/uncategorized/django-cms-npm-webpack-babel-uikit-react/ https://www.vincentverloop.nl/uncategorized/django-cms-npm-webpack-babel-uikit-react/#respond Sat, 21 Jan 2017 14:43:46 +0000 https://www.vincentverloop.nl/?p=1326 mkvirtualenv mysite workon mysite pip install djangocms-installer djangocms mysite cd mysite python manage.py migrate python manage.py createsuperuser python manage.py runserver npm install uikit Using ES6 and ES7 in the Browser, with Babel 6 and Webpack Initialize with npm npm init Accept the default for all the prompts Installing and Configuring Webpack Webpack is a module […]

The post Django CMS + NPM + Webpack + Babel + Uikit + React appeared first on Vincent Verloop.

]]>
mkvirtualenv mysite
workon mysite
pip install djangocms-installer
djangocms mysite
cd mysite
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
npm install uikit

Using ES6 and ES7 in the Browser, with Babel 6 and Webpack

Initialize with npm

npm init

Accept the default for all the prompts

Installing and Configuring Webpack

Webpack is a module bundler which takes modules with dependencies and generates static assets by bundling them together based on some configuration.

Let’s start with installing webpack using npm

npm i webpack -S

Webpack requires some configuration settings to carry out its work and the best practice is doing it via a config file called webpack.config.js.

touch webpack.config.js

Update the config file as follows:


var webpack = require('webpack');
var path = require('path');

var BUILD_DIR = path.resolve(__dirname, 'src/client/public');
var APP_DIR = path.resolve(__dirname, 'src/client/app');

var config = {
  entry: APP_DIR + '/index.jsx',
  output: {
    path: BUILD_DIR,
    filename: 'bundle.js'
  }
};

module.exports = config;

Now in the terminal run the following command

./node_modules/.bin/webpack -d

The above command runs the webpack in the development mode and generates the bundle.js file and its associated map file bundle.js.map in the src/client/public directory.

Babel installation

Start by installing the babel-core and babel-loader packages:

npm install --save-dev babel-loader babel-core

Next, you’ll need to install any presets and plugins you need. Start with babel-preset-es2015 – Babel’s collection of ES6 transforms. If you’re using JSX, you’ll also want babel-preset-react. And if you want to play with fire, you can add babel-preset-stage-0 for access to ES7 decorators, async/await, etc.


# For ES6/ES2015 support
npm install babel-preset-es2015 --save-dev

# If you want to use JSX
npm install babel-preset-react --save-dev

# If you want to use experimental ES7 features
npm install babel-preset-stage-0 --save-dev

Install all packages at ones:

npm install babel-loader babel-core babel-preset-es2015 webpack --save-dev

Runtime support

Babel can’t support all of ES6 with compilation alone — it also requires some runtime support. In particular, the new ES6 built-ins like Set, Map and Promise must be polyfilled, and Babel’s generator implementation also uses a number of runtime helpers. Given your app doesn’t have to share a JavaScript environment with other apps, you’ll be ok to use babel-polyfill to handle this:

<

pre><npm install babel-polyfill –save

Babel also bakes a number of smaller helpers directly into your compiled code. This is OK for single files, but when bundling with Webpack, repeated code will result in a heavier file size. It is possible to replace these helpers with calls to the babel-runtime package by adding the transform-runtime plugin:

npm install babel-runtime –save
npm install babel-plugin-transform-runtime –save-dev

Usage

Via config


module: {
  loaders: [
    { test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" }
  ]
}

Create .babelrc configuration file

You’ve configured Babel but you haven’t made it actually do anything. Create a .babelrc config in your project root and enable some plugins.

To start, you can use the env preset, which enables transforms for ES2015+

npm install babel-preset-env --save-dev

In order to enable the preset you have to define it in your .babelrc file, like this:

touch .babelrc

{
  "presets": ["env"]
}

React installation

npm i babel-loader babel-preset-es2015 babel-preset-react -S

The babel-preset-es2015 and babel-preset-react are plugins being used by the babel-loader to translate ES6 and JSX syntax respectively.

As we did for Webpack, babel-loader also requires some configuration. Here we need to tell it to use the ES6 and JSX plugins.

Create a .babelrc file and update it as below:

touch .babelrc

 {
  "presets" : ["es2015", "react"]
}

The post Django CMS + NPM + Webpack + Babel + Uikit + React appeared first on Vincent Verloop.

]]>
https://www.vincentverloop.nl/uncategorized/django-cms-npm-webpack-babel-uikit-react/feed/ 0 1326
How to install Git https://www.vincentverloop.nl/uncategorized/how-to-install-git/ https://www.vincentverloop.nl/uncategorized/how-to-install-git/#respond Mon, 07 Nov 2016 13:13:52 +0000 https://www.vincentverloop.nl/?p=1167 There are several ways to install Git on a Mac. In fact, if you’ve installed XCode (or it’s Command Line Tools), Git may already be installed. To find out, open a terminal and enter git –version. $ git --version git version 2.7.0 (Apple Git-66) Apple actually maintain and ship their own fork of Git, but […]

The post How to install Git appeared first on Vincent Verloop.

]]>
There are several ways to install Git on a Mac. In fact, if you’ve installed XCode (or it’s Command Line Tools), Git may already be installed. To find out, open a terminal and enter git –version.

$ git --version
git version 2.7.0 (Apple Git-66)

Apple actually maintain and ship their own fork of Git, but it tends to lag behind mainstream Git by several major versions. You may want to install a newer version of Git using one of the methods below:

Git for Mac Installer

The easiest way to install Git on a Mac is via the stand-alone installer:

Download the latest Git for Mac installer.
Follow the prompts to install Git.
Open a terminal and verify the installation was successful by typing git –version:


$ git --version
git version 2.9.2

Configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create:


$ git config --global user.name "Your Name"
$ git config --global user.email "name@email.com"

(Optional) To make Git remember your username and password when working with HTTPS repositories, configure the git-credential-osxkeychain helper.

Install Git with Homebrew

If you have installed Homebrew to manage packages on OS X, you can follow these instructions to install Git:

  1. Open your terminal and install Git using Homebrew:

    $ brew install git
  2. Verify the installation was successful by typing which git --version:

    $ git --version
    git version 2.9.2
  3. Configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create:

    $ git config --global user.name "Your Name"
    $ git config --global user.email "name@email.com"
  4. (Optional) To make Git remember your username and password when working with HTTPS repositories, install the git-credential-osxkeychain helper.

Git for Windows stand-alone installer

  1. Download the latest Git for Windows installer.
  2. When you’ve successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finishprompts to complete the installation. The default options are pretty sensible for most users.
  3. Open a Command Prompt (or Git Bash if during installation you elected not to use Git from the Windows Command Prompt).
  4. Run the following commands to configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create:

    $ git config --global user.name "Your Name"
    $ git config --global user.email "yourname@email.com"
  5. Optional: Install the Git credential helper on Windows
    Bitbucket supports pushing and pulling over HTTP to your remote Git repositories on Bitbucket. Every time you interact with the remote repository, you must supply a username/password combination. You can store these credentials, instead of supplying the combination every time, with the Git Credential Manager for Windows.

Install Git on Linux

Debian / Ubuntu (apt-get)

Git packages are available via apt:

  1. From your shell, install Git using apt-get:

    $ sudo apt-get update
    $ sudo apt-get install git
  2. Verify the installation was successful by typing git --version:

    $ git --version
    git version 2.9.2
  3. Configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create:

    $ git config --global user.name "Your Name"
    $ git config --global user.email "name@email.com"

Fedora (dnf/yum)

Git packages are available via both yum and dnf:

  1. From your shell, install Git using dnf (or yum, on older versions of Fedora):

    $ sudo dnf install git

    or

    $ sudo yum install git
  2. Verify the installation was successful by typing git --version:

    $ git --version
    git version 2.9.2
  3. Configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create

    $ git config --global user.name "Your Name"
    $ git config --global user.email "name@email.com"

[:en]

There are several ways to install Git on a Mac. In fact, if you’ve installed XCode (or it’s Command Line Tools), Git may already be installed. To find out, open a terminal and enter git –version.

$ git --version
git version 2.7.0 (Apple Git-66)

Apple actually maintain and ship their own fork of Git, but it tends to lag behind mainstream Git by several major versions. You may want to install a newer version of Git using one of the methods below:

Git for Mac Installer

The easiest way to install Git on a Mac is via the stand-alone installer:

Download the latest Git for Mac installer.
Follow the prompts to install Git.
Open a terminal and verify the installation was successful by typing git –version:


$ git --version
git version 2.9.2

Configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create:


$ git config --global user.name "Your Name"
$ git config --global user.email "name@email.com"

(Optional) To make Git remember your username and password when working with HTTPS repositories, configure the git-credential-osxkeychain helper.

Install Git with Homebrew

If you have installed Homebrew to manage packages on OS X, you can follow these instructions to install Git:

  1. Open your terminal and install Git using Homebrew:

    $ brew install git
  2. Verify the installation was successful by typing which git --version:

    $ git --version
    git version 2.9.2
  3. Configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create:

    $ git config --global user.name "Your Name"
    $ git config --global user.email "name@email.com"
  4. (Optional) To make Git remember your username and password when working with HTTPS repositories, install the git-credential-osxkeychain helper.

Git for Windows stand-alone installer

  1. Download the latest Git for Windows installer.
  2. When you’ve successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finishprompts to complete the installation. The default options are pretty sensible for most users.
  3. Open a Command Prompt (or Git Bash if during installation you elected not to use Git from the Windows Command Prompt).
  4. Run the following commands to configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create:

    $ git config --global user.name "Your Name"
    $ git config --global user.email "yourname@email.com"
  5. Optional: Install the Git credential helper on Windows
    Bitbucket supports pushing and pulling over HTTP to your remote Git repositories on Bitbucket. Every time you interact with the remote repository, you must supply a username/password combination. You can store these credentials, instead of supplying the combination every time, with the Git Credential Manager for Windows.

Install Git on Linux

Debian / Ubuntu (apt-get)

Git packages are available via apt:

  1. From your shell, install Git using apt-get:

    $ sudo apt-get update
    $ sudo apt-get install git
  2. Verify the installation was successful by typing git --version:

    $ git --version
    git version 2.9.2
  3. Configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create:

    $ git config --global user.name "Your Name"
    $ git config --global user.email "name@email.com"

Fedora (dnf/yum)

Git packages are available via both yum and dnf:

  1. From your shell, install Git using dnf (or yum, on older versions of Fedora):

    $ sudo dnf install git

    or

    $ sudo yum install git
  2. Verify the installation was successful by typing git --version:

    $ git --version
    git version 2.9.2
  3. Configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create

    $ git config --global user.name "Your Name"
    $ git config --global user.email "name@email.com"

The post How to install Git appeared first on Vincent Verloop.

]]>
https://www.vincentverloop.nl/uncategorized/how-to-install-git/feed/ 0 1167
How to install Django https://www.vincentverloop.nl/uncategorized/how-to-install-django/ https://www.vincentverloop.nl/uncategorized/how-to-install-django/#respond Mon, 07 Nov 2016 12:21:37 +0000 https://www.vincentverloop.nl/?p=1154 Setup What you need for a basic dev environment: Python 2.7.x or 3.4.x easy_install and Pip Git virtualenv Django Database (SQLite, MySQL, PostgreSQL, MongoDB, etc.) Text editor (Sublime, vim, Komodo, gedit, Pycharm) Note: This tutorial utilizes Python version 2.7.8. Installation instructions are slightly different depending on whether you’re installing a distribution-specific package, downloading the latest […]

The post How to install Django appeared first on Vincent Verloop.

]]>
Setup

What you need for a basic dev environment:

Note: This tutorial utilizes Python version 2.7.8.

Installation instructions are slightly different depending on whether you’re installing a distribution-specific package,
downloading the latest official release, or fetching the latest development version.

It’s easy, no matter which way you choose.

Installing an official release with pip

This is the recommended way to install Django.

Install pip. The easiest is to use the standalone pip installer. If your distribution already has pip installed, you might need to update it if it’s outdated. If it’s outdated, you’ll know because installation won’t work.

Take a look at virtualenv and virtualenvwrapper. These tools provide isolated Python environments, which are more practical than installing packages systemwide. They also allow installing packages without administrator privileges. The contributing tutorial walks through how to create a virtualenv on Python 3.

mkvirtualenv mysite
workon mysite
pip install --upgrade pip

After you’ve created and activated a virtual environment, enter the command pip install django at the shell prompt.

django-admin startproject mysite
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
http://127.0.0.1:8000/admin/

[:en]

Setup

What you need for a basic dev environment:

Note: This tutorial utilizes Python version 2.7.8.

Installation instructions are slightly different depending on whether you’re installing a distribution-specific package,
downloading the latest official release, or fetching the latest development version.

It’s easy, no matter which way you choose.

Installing an official release with pip

This is the recommended way to install Django.

Install pip. The easiest is to use the standalone pip installer. If your distribution already has pip installed, you might need to update it if it’s outdated. If it’s outdated, you’ll know because installation won’t work.

Take a look at virtualenv and virtualenvwrapper. These tools provide isolated Python environments, which are more practical than installing packages systemwide. They also allow installing packages without administrator privileges. The contributing tutorial walks through how to create a virtualenv on Python 3.

After you’ve created and activated a virtual environment, enter the command pip install Django at the shell prompt.

The post How to install Django appeared first on Vincent Verloop.

]]>
https://www.vincentverloop.nl/uncategorized/how-to-install-django/feed/ 0 1154
How to install Virtualenv & Virtualenvwrapper https://www.vincentverloop.nl/uncategorized/hoe-moet-virtualenv-virtualenvwrapper-installeren/ https://www.vincentverloop.nl/uncategorized/hoe-moet-virtualenv-virtualenvwrapper-installeren/#respond Mon, 07 Nov 2016 12:19:30 +0000 https://www.vincentverloop.nl/?p=1152 A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable. For example, you can work on a […]

The post How to install Virtualenv & Virtualenvwrapper appeared first on Vincent Verloop.

]]>
A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.

For example, you can work on a project which requires Django 1.10 while also maintaining a project which requires Django 1.8.

Virtualenv

Virtualenv is a tool to create isolated Python environments. Virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need.

Install Virtualenv via pip:

$ pip install virtualenv

Basic Usage

  1. Create a virtual environment for a project:
$ cd my_project_folder
$ virtualenv venv

virtualenv venv will create a folder in the current directory which will contain the Python executable files, and a copy of the pip library which you can use to install other packages. The name of the virtual environment (in this case, it was venv) can be anything; omitting the name will place the files in the current directory instead.

This creates a copy of Python in whichever directory you ran the command in, placing it in a folder named venv.

You can also use a Python interpreter of your choice.

$ virtualenv -p /usr/bin/python2.7 venv

This will use the Python interpreter in /usr/bin/python2.7

  1. To begin using the virtual environment, it needs to be activated:
$ source venv/bin/activate

The name of the current virtual environment will now appear on the left of the prompt (e.g. (venv)Your-Computer:your_project UserName$) to let you know that it’s active. From now on, any package that you install using pip will be placed in the venv folder, isolated from the global Python installation.

Install packages as usual, for example:

$ pip install requests
  1. If you are done working in the virtual environment for the moment, you can deactivate it:
$ deactivate

This puts you back to the system’s default Python interpreter with all its installed libraries.

To delete a virtual environment, just delete its folder. (In this case, it would be rm -rf venv.)

After a while, though, you might end up with a lot of virtual environments littered across your system, and its possible you’ll forget their names or where they were placed.

Other Notes

Running virtualenv with the option --no-site-packages will not include the packages that are installed globally. This can be useful for keeping the package list clean in case it needs to be accessed later. [This is the default behavior for virtualenv 1.7 and later.]

In order to keep your environment consistent, it’s a good idea to “freeze” the current state of the environment packages. To do this, run

$ pip freeze > requirements.txt

This will create a requirements.txt file, which contains a simple list of all the packages in the current environment, and their respective versions. You can see the list of installed packages without the requirements format using “pip list”. Later it will be easier for a different developer (or you, if you need to re-create the environment) to install the same packages using the same versions:

$ pip install -r requirements.txt

This can help ensure consistency across installations, across deployments, and across developers.

Lastly, remember to exclude the virtual environment folder from source control by adding it to the ignore list.

Virtualenvwrapper

virtualenvwrapper provides a set of commands which makes working with virtual environments much more pleasant. It also places all your virtual environments in one place.

To install (make sure virtualenv is already installed):

$ pip install virtualenvwrapper
$ export WORKON_HOME=~/Envs
$ source /usr/local/bin/virtualenvwrapper.sh

(Full virtualenvwrapper install instructions.)

For Windows, you can use the virtualenvwrapper-win.

To install (make sure virtualenv is already installed):

$ pip install virtualenvwrapper-win

In Windows, the default path for WORKON_HOME is %USERPROFILE%Envs

Basic Usage

  1. Create a virtual environment:
$ mkvirtualenv venv

This creates the venv folder inside ~/Envs.

  1. Work on a virtual environment:
$ workon venv

Alternatively, you can make a project, which creates the virtual environment, and also a project directory inside $PROJECT_HOME, which is cd -ed into when you workon myproject.

$ mkproject myproject

virtualenvwrapper provides tab-completion on environment names. It really helps when you have a lot of environments and have trouble remembering their names.

workon also deactivates whatever environment you are currently in, so you can quickly switch between environments.

  1. Deactivating is still the same:
$ deactivate
  1. To delete:
$ rmvirtualenv venv

Other useful commands

lsvirtualenv
List all of the environments.
cdvirtualenv
Navigate into the directory of the currently activated virtual environment, so you can browse its site-packages, for example.
cdsitepackages
Like the above, but directly into site-packages directory.
lssitepackages
Shows contents of site-packages directory.

Full list of virtualenvwrapper commands.

virtualenv-burrito

With virtualenv-burrito, you can have a working virtualenv + virtualenvwrapper environment in a single command.

autoenv

When you cd into a directory containing a .env, autoenv automagically activates the environment.

Install it on Mac OS X using brew:

$ brew install autoenv

And on Linux:

$ git clone git://github.com/kennethreitz/autoenv.git ~/.autoenv
$ echo 'source ~/.autoenv/activate.sh' >> ~/.bashrc

The post How to install Virtualenv & Virtualenvwrapper appeared first on Vincent Verloop.

]]>
https://www.vincentverloop.nl/uncategorized/hoe-moet-virtualenv-virtualenvwrapper-installeren/feed/ 0 1152
How to install Python https://www.vincentverloop.nl/uncategorized/hoe-moet-python-installeren/ https://www.vincentverloop.nl/uncategorized/hoe-moet-python-installeren/#respond Mon, 07 Nov 2016 12:16:16 +0000 https://www.vincentverloop.nl/?p=1148 These guides go over the proper installation of Python 2.7 for development purposes, as well as setuptools, pip, and virtualenv setup. Installing Python on Mac OS X Before installing Python, you’ll need to install a C compiler. You can download the full version of Xcode from the Mac App Store which include a C compiler. […]

The post How to install Python appeared first on Vincent Verloop.

]]>
These guides go over the proper installation of Python 2.7 for development purposes, as well as setuptools, pip, and virtualenv setup.

Installing Python on Mac OS X

Before installing Python, you’ll need to install a C compiler.

You can download the full version of Xcode from the Mac App Store which include a C compiler.

While OS X comes with a large number of UNIX utilities, those familiar with Linux systems will notice one key component missing: a decent package manager. Homebrew fills this void.

To install Homebrew, open Terminal or your favorite OSX terminal emulator and run:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

The script will explain what changes it will make and prompt you before the installation begins. Once you’ve installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file.

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

Now, we can install Python 2.7:

$ brew install python

or Python 3:

$ brew install python3

This will take a minute or two.

Setuptools & Pip

Setuptools enables you to download and install any compliant Python software over a network (usually the Internet) with a single command (easy_install). It also enables you to add this network installation capability to your own Python software with very little work.

pip is a tool for easily installing and managing Python packages, that is recommended over easy_install. It is superior to easy_install in several ways, and is actively maintained.

Virtual Environments

A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.

For example, you can work on a project which requires Django 1.10 while also maintaining a project which requires Django 1.8.

To start using this and see more information: Virtual Environments

[:en]

These guides go over the proper installation of Python 2.7 for development purposes, as well as setuptools, pip, and virtualenv setup.

Installing Python on Mac OS X

Before installing Python, you’ll need to install a C compiler.

You can download the full version of Xcode from the Mac App Store which include a C compiler.

While OS X comes with a large number of UNIX utilities, those familiar with Linux systems will notice one key component missing: a decent package manager. Homebrew fills this void.

To install Homebrew, open Terminal or your favorite OSX terminal emulator and run:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

The script will explain what changes it will make and prompt you before the installation begins. Once you’ve installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file.

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

Now, we can install Python 2.7:

$ brew install python

or Python 3:

$ brew install python3

This will take a minute or two.

Setuptools & Pip

Setuptools enables you to download and install any compliant Python software over a network (usually the Internet) with a single command (easy_install). It also enables you to add this network installation capability to your own Python software with very little work.

pip is a tool for easily installing and managing Python packages, that is recommended over easy_install. It is superior to easy_install in several ways, and is actively maintained.

Virtual Environments

A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.

For example, you can work on a project which requires Django 1.10 while also maintaining a project which requires Django 1.8.

To start using this and see more information: Virtual Environments

The post How to install Python appeared first on Vincent Verloop.

]]>
https://www.vincentverloop.nl/uncategorized/hoe-moet-python-installeren/feed/ 0 1148
How to Restore the Windows 7 MBR (Master Boot Record) https://www.vincentverloop.nl/uncategorized/restore-windows-7-mbr-master-boot-record/ https://www.vincentverloop.nl/uncategorized/restore-windows-7-mbr-master-boot-record/#respond Sun, 25 Jan 2015 22:33:10 +0000 http://new.vincentverloop.nl/?p=975 Boot your computer to the Windows 7 DVD (or to a “Repair CD”). Click the button for “Use recovery tools”. Then select “Command Prompt”. The command we will use, bootsect.exe, is in a folder (named boot) on the DVD. We need to know what drive letter has been assigned the DVD drive to access the […]

The post How to Restore the Windows 7 MBR (Master Boot Record) appeared first on Vincent Verloop.

]]>
  • Boot your computer to the Windows 7 DVD (or to a “Repair CD”).
  • Click the button for “Use recovery tools”.
  • Then select “Command Prompt”.
  • The command we will use, bootsect.exe, is in a folder (named boot) on the DVD.
  • We need to know what drive letter has been assigned the DVD drive to access the folder.
    Type: diskpart
    and press Enter
     
    Type: select disk 0 (zero)
    and press Enter
     
    type: list volume
    and press Enter

  • Use your DVD drive letter and:
    Type: exit
    and press Enter
     
    to close Diskpart
     
    Type: G: (use the letter of your DVD drive)
    and press Enter
     
    Type: cd boot
    and press Enter
     
    Type: dir
    and press Enter

     to verify that bootcect.exe is there (if you really need to)

  • To restore the “bootsector code”:
    TYPE: bootsect /nt60 SYS /mbr
    and press Enter

  • Type: exit
    and press Enter

  • Now select Shut Down or Restart. Then you can reboot your computer into Windows.
  • The post How to Restore the Windows 7 MBR (Master Boot Record) appeared first on Vincent Verloop.

    ]]>
    https://www.vincentverloop.nl/uncategorized/restore-windows-7-mbr-master-boot-record/feed/ 0 975