User Tools

Site Tools


linux:digitalocean

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
linux:digitalocean [2014/05/23 03:50] – [PHP Fatal error: Class 'DOMDocument' not found] adminlinux:digitalocean [2019/08/05 15:42] – [2. copy data from hostgator to Digitalocean] admin
Line 1: Line 1:
 +====== Moving web from hostgator to DigitalOcean ======
  
 +===== 1. Install missing components on DigitalOcean =====
 +==== install basic packages ====
 +<code bash>
 +yum install vim mc man telnet
 +</code>
 +==== 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:
 +  - Step1: Check your swap on<code bash>
 +swapon -s
 +</code>
 +  - Step2: Create an empty swapfile<code bash>
 +sudo install -o root -g root -m 0600 /dev/null /swapfile
 +</code>
 +  - Step3: write out a 1 GB file named 'swapfile'<code bash>
 +dd if=/dev/zero of=/swapfile bs=1k count=1024k
 +</code>
 +  - Step4: tell linux this is the swap file:<code bash>
 +mkswap /swapfile
 +</code>
 +  - Step5: Activate it<code bash>
 +swapon /swapfile
 +</code>
 +  - Step6: Add it to the file system table so its there after reboot:<code bash>
 +echo "/swapfile       swap    swap    auto      0       0" | sudo tee -a /etc/fstab
 +</code>
 +  - Step7: Set the swappiness to 10 so its only uses as an emergency buffer<code bash>
 +sudo sysctl -w vm.swappiness=10
 +echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
 +</code>
 +==== mysqld ====
 +  * setup:<code bash>
 +  yum install mysql-server.x86_64
 +  </code>
 +  * start:<code bash>
 +  /etc/init.d/mysql start
 +  </code>
 +==== httpd ====
 +  * setup:<code bash>
 +  yum install httpd.x86_64
 +  </code>
 +  * start:<code bash>
 +  /etc/init.d/httpd start
 +  </code>
 +==== php ====
 +  * setup:<code bash>
 +  yum install php.x86_64
 +  yum install php-mysql.x86_64
 +  </code>
 +
 +===== 2. Copy data from hostgator to Digitalocean =====
 +==== create backup file for web and database on Hostgator ====
 +=== backup web ===
 +<code bash>
 +cd ~/public_html/
 +tar czf babyshopvn.tar.gz babyshopvn/
 +</code>
 +=== backup database ===
 +<code bash>
 +mysqldump -u'anhvc_babies' -p anhvc_babyshopvn > babyshopvn.sql
 +</code>
 +==== copy data to Digitalocean with scp ====
 +(To run scp, you must install openssh-clients both client and server)
 +  * check ssh connect: <code bash>
 +  ssh -p 2222 [email protected]
 +</code>
 +  * scp<code bash>
 +  scp -P 2222 [email protected]:~/public_html/babyshopvn.tar.gz .
 +  scp -P 2222 [email protected]:~/babyshopvn.sql .
 +</code>
 +===== 3.Import database and config to run web on DigitalOcean =====
 +==== Import database ====
 +  * create database:<code bash>
 +  mysqladmin create babyshopvn;
 +</code>
 +  * Import database:<code bash>
 +  mysql -f --default-character-set=utf8 -uroot babyshopvn < babyshopvn.sql
 +</code>
 +==== config httpd ====
 +=== check location of httpd config file ===
 +<code bash>
 +cat /etc/init.d/httpd | grep conf
 +</code>
 +=> Output:
 +<code text>
 +# 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}"
 +</code>
 +=> config: /etc/httpd/conf/httpd.conf
 +
 +=== check default DocumentRoot of web ===
 +<code bash>
 +cat /etc/httpd/conf/httpd.conf | grep -v '#'
 +</code>
 +=> DocumentRoot:
 +<code text>
 +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>
 +</code>
 +=== create Simple code in DocumentRoot to check ===
 +Create helloworld.php in /var/www/html
 +<code php>
 +<?php
 +  echo "hello world";
 +?>
 +</code>
 +=> Check:http://128.199.236.122/helloworld.php
 +=== config Virtualhost for babies.vn ===
 +  * Create babies.vn.conf in /etc/httpd/conf.d<code>
 +<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>
 +</code>
 +  * reload httpd:<code bash>
 +  /etc/init.d/httpd reload
 +</code>
 +  * 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<code bash>
 +  cat /etc/httpd/conf/httpd.conf | grep -v '#'
 +  =>
 +  User apache
 +  Group apache
 +  </code>
 +  * chown the www directory<code bash>
 +  chown -R apache.apache /data/www
 +</code>
 +===== 4. Other changes =====
 +==== config httpd and mysqld auto start when server reboot ====
 +<code bash>
 +chkconfig httpd on
 +chkconfig mysqld on
 +</code>
 +==== Change pass of mysql ====
 +<code bash>
 +mysqladmin password 'newpassword'
 +</code>
 +==== secure ssh in sshd_config ====
 +  * Edit new port for ssh<code bash>
 +Port 1362
 +</code>
 +  * Generate key ssh for login with key follow [[linux:services#ssh|ssh]]. And disale allow login with password via ssh<code bash>
 +PasswordAuthentication no
 +</code>
 +  * secure user:<code bash>
 +AllowUsers root anhvc
 +</code>
 +  * change usedns in sshd.conf<code>
 +UseDNS no
 +</code>
 +==== config php debug ====
 +Follow tutorial [[php:php#config_debug_mode_in_php]]\\
 +Check error log in: /var/log/httpd/shop.babies.vn-error_log
 +==== change timezone ====
 +Follow tutorial [[linux:shellcommands#change_timezone]]
 +===== 5. Debug and fix error =====
 +==== PHP error log ====
 +=== missing php-xml ===
 +  * error log: PHP Fatal error:  Class 'DOMDocument' not found
 +  * fix:<code bash>
 +yum install php-xml
 +/etc/init.d/httpd restart
 +</code>
linux/digitalocean.txt · Last modified: 2022/10/29 16:15 by 127.0.0.1