{"id":15943,"date":"2014-10-31T13:32:43","date_gmt":"2014-10-31T08:02:43","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=15943"},"modified":"2014-10-31T13:35:07","modified_gmt":"2014-10-31T08:05:07","slug":"hosting-wordpress-site-in-lxc","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/hosting-wordpress-site-in-lxc\/","title":{"rendered":"Hosting WordPress Site in LXC"},"content":{"rendered":"<p>LXC (LinuX Containers) is an operating system\u2013level 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 &amp; migrate it to another server<\/p>\n<p>Installing LXC<\/p>\n<p>To downloads the package lists from the repositories and &#8220;updates&#8221; them to get information on the newest versions of packages and their dependencies,<\/p>\n<p>[js]<br \/>\napt-get update<br \/>\n[\/js]<\/p>\n<p>To install LXC ,<\/p>\n<p>[js]<br \/>\napt-get install lxc -y<br \/>\n[\/js]<\/p>\n<p>To create a container name application,<\/p>\n<p>[js]<br \/>\nlxc-create -n application -t ubuntu<br \/>\n[\/js]<\/p>\n<p>-n : Name of Container<br \/>\n-t : LXC template. In our case, we&#8217;re using ubuntu template<\/p>\n<p>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.<\/p>\n<p>To list running status of containers,<\/p>\n<p>[js]<br \/>\nlxc-ls \u2013fancy<br \/>\n[\/js]<\/p>\n<p>[js]<\/p>\n<p>root@ip-172-31-34-48:~# lxc-ls &#8211;fancy<br \/>\nNAME         STATE    IPV4  IPV6  AUTOSTART<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\napplication  STOPPED  &#8211;     &#8211;     NO<br \/>\nroot@ip-172-31-34-48:~# <\/p>\n<p>[\/js]<\/p>\n<p>To start a container,<\/p>\n<p>[js]<br \/>\nlxc-start -n application -d<br \/>\n[\/js]<\/p>\n<p>It will give you a login prompt, login with the user credentials that you&#8217;ve got above.<\/p>\n<p>Installing WordPress Site<\/p>\n<p>Install all the necessary packages,<\/p>\n<p>[js]<br \/>\napt-get install mysql-server php5-mysql nginx php5-fpm php5-gd libssh2-php -y<br \/>\n[\/js]<\/p>\n<p>Create a Database,<\/p>\n<p>[js]<br \/>\nmysql -u root -p<br \/>\nCREATE DATABASE wordpress;<br \/>\nCREATE USER user@localhost IDENTIFIED BY &#8216;user123&#8217;;<br \/>\nGRANT ALL PRIVILEGES ON wordpress.* TO user@localhost;<br \/>\n[\/js]<\/p>\n<p>Download and untar wordpress<\/p>\n<p>[js]<br \/>\ncd \/tmp\/<br \/>\nwget http:\/\/wordpress.org\/latest.tar.gz<br \/>\ntar xzvf latest.tar.gz<br \/>\n[\/js]<\/p>\n<p>Configure wordpress<\/p>\n<p>[js]<br \/>\ncd \/tmp\/wordpress<br \/>\nmv wp-config-sample.php wp-config.php<br \/>\n[\/js]<\/p>\n<p>Make below changes in wp-config.php<\/p>\n<p>[js]<\/p>\n<p>\/\/ ** MySQL settings &#8211; You can get this info from your web host ** \/\/<br \/>\n\/** The name of the database for WordPress *\/<br \/>\ndefine(&#8216;DB_NAME&#8217;, &#8216;wordpress&#8217;);<\/p>\n<p>\/** MySQL database username *\/<br \/>\ndefine(&#8216;DB_USER&#8217;, &#8216;user&#8217;);<\/p>\n<p>\/** MySQL database password *\/<br \/>\ndefine(&#8216;DB_PASSWORD&#8217;, &#8216;user123&#8217;);<\/p>\n<p>[\/js]<\/p>\n<p>copy files to document root<\/p>\n<p>[js]<br \/>\nsudo rsync -avP \/tmp\/wordpress\/ \/usr\/share\/nginx\/html<br \/>\n[\/js]<\/p>\n<p>Add an iptables rule to the prerouting table of host machine, to forward packets on port 80 to our nginx container&#8217;s port 80.<\/p>\n<p>[js]<br \/>\niptables -t nat -A PREROUTING -i eth0 -p tcp &#8211;dport 80 -j DNAT &#8211;to 10.0.3.245:80<br \/>\n[\/js]<\/p>\n<p>Now you can access your site, by<br \/>\nhttp:\/\/your-public-ipaddress ( host machine )<\/p>\n<p>Migrating Your lxc container to another host<\/p>\n<p>Install LXC on destination host and stop LXC on your source host<\/p>\n<p>[js]<br \/>\nrsync -va \/var\/lib\/lxc\/container-name destination-host-ip:\/var\/lib\/lxc\/<br \/>\n[\/js]<\/p>\n<p>start container on your destination host.<\/p>\n<p>Once you&#8217;re done with your containers, you can stop it<\/p>\n<p>[js]<br \/>\nlxc-stop -n application<br \/>\n[\/js]<\/p>\n<p>or if you want to terminate your container, you can destroy it<\/p>\n<p>[js]<br \/>\nlxc-destroy -n application<br \/>\n[\/js]<\/p>\n<p>Thanks,<br \/>\nNikhil Kumar Sharma<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LXC (LinuX Containers) is an operating system\u2013level 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 &amp; migrate it to another server Installing LXC To downloads the package lists from the repositories and &#8220;updates&#8221; them to [&hellip;]<\/p>\n","protected":false},"author":124,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":30},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15943"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/124"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=15943"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15943\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=15943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=15943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=15943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}