Skip to Content
  • +31 653-919-302
Cafayate.Net
  • 0
  • 0
  • Sign in
  • Nederlands English (US) Español (AR)
  • Contact Us
  • Home
  • Blog
  • Jobs
  • Contact us
Cafayate.Net
  • 0
  • 0
    • Home
    • Blog
    • Jobs
    • Contact us
  • +31 653-919-302
  • Nederlands English (US) Español (AR)
  • Sign in
  • Contact Us

Hosting WordPress Site in LXC

  • All Blogs
  • Tech Blog
  • Hosting WordPress Site in LXC
  • March 5, 2021 by
    Administrator

     

    LXC (LinuX Containers) is an operating system–level virtualization method for running multiple isolated Linux systems (containers) on a single control host. In this blog, we will explain, how to host a WordPress site in LXC & migrate it to another server

    Installing LXC

    To downloads the package lists from the repositories and “updates” them to get information on the newest versions of packages and their dependencies,

    apt-get update
    

    To install LXC ,

    apt-get install lxc -y
    

    To create a container name application,

    lxc-create -n application -t ubuntu
    

    -n : Name of Container
    -t : LXC template. In our case, we’re using ubuntu template

    It will take a while to create a container, once it has been created, it will give you username and password to login into your container.

    To list running status of containers,

    lxc-ls –fancy
    
    root@ip-172-31-34-48:~# lxc-ls --fancy
    NAME         STATE    IPV4  IPV6  AUTOSTART
    -------------------------------------------
    application  STOPPED  -     -     NO
    root@ip-172-31-34-48:~# 
    
    

    To start a container,

    lxc-start -n application -d
    

    It will give you a login prompt, login with the user credentials that you’ve got above.

    Installing WordPress Site

    Install all the necessary packages,

    apt-get install mysql-server php5-mysql nginx php5-fpm php5-gd libssh2-php -y
    

    Create a Database,

    mysql -u root -p
    CREATE DATABASE wordpress;
    CREATE USER user@localhost IDENTIFIED BY 'user123';
    GRANT ALL PRIVILEGES ON wordpress.* TO user@localhost;
    

    Download and untar wordpress

    cd /tmp/
    wget http://wordpress.org/latest.tar.gz
    tar xzvf latest.tar.gz
    

    Configure wordpress

    cd /tmp/wordpress
    mv wp-config-sample.php wp-config.php
    

    Make below changes in wp-config.php

    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define('DB_NAME', 'wordpress');
    
    /** MySQL database username */
    define('DB_USER', 'user');
    
    /** MySQL database password */
    define('DB_PASSWORD', 'user123');
    
    

    copy files to document root

    sudo rsync -avP /tmp/wordpress/ /usr/share/nginx/html
    

    Add an iptables rule to the prerouting table of host machine, to forward packets on port 80 to our nginx container’s port 80.

    iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 10.0.3.245:80
    

    Now you can access your site, by
    http://your-public-ipaddress ( host machine )

    Migrating Your lxc container to another host

    Install LXC on destination host and stop LXC on your source host

    rsync -va /var/lib/lxc/container-name destination-host-ip:/var/lib/lxc/
    

    start container on your destination host.

    Once you’re done with your containers, you can stop it

    lxc-stop -n application
    

    or if you want to terminate your container, you can destroy it

    lxc-destroy -n application
    
    
    
    
    
    in Tech Blog
    Tyler WordPress Theme

    Designed for companies

    We are a team of passionate people whose goal is to improve everyone's life through disruptive products. We build great products to solve your business problems. Our products are designed for small to medium size companies willing to optimize their performance.

    Get in touch

    Plantexel
    Pedernera
    Salta Capital 
    Argenina

    • +31 653-919-302
    • [email protected]
    Follow us
    Copyright © Plantexel
    Nederlands | English (US) | Español (AR)