User Tools

Site Tools


linux:digitalocean

Moving web from hostgator to DigitalOcean

1. Install missing components on DigitalOcean

install basic packages

yum install vim mc man telnet

create swap file for your linux server

Most cloud virtual machine providers do not set up swapfiles as part of their server provisioning.

If you are running the recommended 2 GB of memory for Discourse, a swap file is technically not required, but can be helpful just in case your server experiences memory pressure. With a swap file, rather than randomly terminating processes with an out of memory error, things will slow down instead.

This can be done at any time from the command line on your server.

Set up a 1 GB swap file

Adding a swap file gives Discourse some extra breathing room during memory-intensive operations. 1GB swap should suffice, though if you are attempting the minimum memory configuration you should set up a 2GB swap.

In the shell you have opened to your droplet, do the following:

  1. Step1: Check your swap on
    swapon -s
  2. Step2: Create an empty swapfile
    sudo install -o root -g root -m 0600 /dev/null /swapfile
  3. Step3: write out a 1 GB file named 'swapfile'
    dd if=/dev/zero of=/swapfile bs=1k count=1024k
  4. Step4: tell linux this is the swap file:
    mkswap /swapfile
  5. Step5: Activate it
    swapon /swapfile
  6. Step6: Add it to the file system table so its there after reboot:
    echo "/swapfile       swap    swap    auto      0       0" | sudo tee -a /etc/fstab
  7. Step7: Set the swappiness to 10 so its only uses as an emergency buffer
    sudo sysctl -w vm.swappiness=10
    echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

mysqld

  • setup:
      yum install mysql-server.x86_64
     
  • start:
      /etc/init.d/mysql start
     

httpd

  • setup:
      yum install httpd.x86_64
     
  • start:
      /etc/init.d/httpd start
     

php

  • setup:
      yum install php.x86_64
      yum install php-mysql.x86_64
     

2. Copy data from hostgator to Digitalocean

create backup file for web and database on Hostgator

backup web

cd ~/public_html/
tar czf babyshopvn.tar.gz babyshopvn/

backup database

mysqldump -u'anhvc_babies' -p anhvc_babyshopvn > babyshopvn.sql

copy data to Digitalocean with scp

(To run scp, you must install openssh-clients both client and server)

  • check ssh connect:
      ssh -p 2222 anhvc@192.232.218.215
  • scp
      scp -P 2222 anhvc@192.232.218.215:~/public_html/babyshopvn.tar.gz .
      scp -P 2222 anhvc@192.232.218.215:~/babyshopvn.sql .

3.Import database and config to run web on DigitalOcean

Import database

  • create database:
      mysqladmin create babyshopvn;
  • Import database:
      mysql -f --default-character-set=utf8 -uroot babyshopvn < babyshopvn.sql

config httpd

check location of httpd config file

cat /etc/init.d/httpd | grep conf

⇒ Output:

# chkconfig: - 85 15
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
  graceful|help|configtest|fullstatus)
        echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"

⇒ config: /etc/httpd/conf/httpd.conf

check default DocumentRoot of web

cat /etc/httpd/conf/httpd.conf | grep -v '#'

⇒ DocumentRoot:

DocumentRoot "/var/www/html"
 
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
 
 
<Directory "/var/www/html">
 
    Options Indexes FollowSymLinks
 
    AllowOverride None
 
    Order allow,deny
    Allow from all
 
</Directory>

create Simple code in DocumentRoot to check

Create helloworld.php in /var/www/html

<?php
  echo "hello world";
?>

⇒ Check:http://128.199.236.122/helloworld.php

config Virtualhost for babies.vn

  • Create babies.vn.conf in /etc/httpd/conf.d
    <VirtualHost *:80>
        ServerName shop.babies.vn
        DocumentRoot "/data/www/babyshopvn"
        <Directory /data/www/babyshopvn>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride all
            Order Deny,Allow
            Allow from all
        </Directory>
        ErrorLog logs/shop.babies.vn-error_log
        CustomLog logs/shop.babies.vn-access_log common
    </VirtualHost>
  • reload httpd:
      /etc/init.d/httpd reload
  • copy helloworld.php to /data/www/babyshopvn and check http://shop.babies.vn/helloworld.php

config source babies.vn(magento)

  • change config connect to database [app/etc/local.xml]
  • On debug mode for magento:
    • [/etc/httpd/conf.d/babies.vn.conf]: SetEnv MAGE_IS_DEVELOPER_MODE “true”
    • index.php: ini_set('display_errors', 1);

chown the www directory

  • check the user and group run Apache
      cat /etc/httpd/conf/httpd.conf | grep -v '#'
      =>
      User apache
      Group apache
     
  • chown the www directory
      chown -R apache.apache /data/www

4. Other changes

config httpd and mysqld auto start when server reboot

chkconfig httpd on
chkconfig mysqld on

Change pass of mysql

mysqladmin password 'newpassword'

secure ssh in sshd_config

  • Edit new port for ssh
    Port 1362
  • Generate key ssh for login with key follow ssh. And disale allow login with password via ssh
    PasswordAuthentication no
  • secure user:
    AllowUsers root anhvc
  • change usedns in sshd.conf
    UseDNS no

config php debug

Follow tutorial config_debug_mode_in_php
Check error log in: /var/log/httpd/shop.babies.vn-error_log

change timezone

Follow tutorial change_timezone

5. Debug and fix error

PHP error log

missing php-xml

  • error log: PHP Fatal error: Class 'DOMDocument' not found
  • fix:
    yum install php-xml
    /etc/init.d/httpd restart
linux/digitalocean.txt · Last modified: 2022/10/29 16:15 by 127.0.0.1