Quick-start for setting up WP and VPN Server on DigitalOcean

Prerequisite

First you should check your Linux Version, for this tutorial is only works for ubuntu, that means, if you run archlinux/centos/debian on DigitalOcean, this tutorial won’t be fit for your need.

root@justfordemo:~# cat /etc/issue
Ubuntu 14.04.1 LTS \n \l

Upgrade to the newest system via:

root@justfordemo:~# apt-get update && apt-get upgrade

Enter Y if system asks you to confirm.

NGINX and PHP

Following commands refers to:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04 and https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-nginx-on-ubuntu-14-04.

Install nginx

Install the nginx server via:

# apt-get install nginx

Get the ip address via:

# ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
10.0.0.6
fe80::a00:27ff:fe38:b7c5

Use you browser to visit http://10.0.0.6, you will see following page which indiciates the nginx works for you.
/images/nginxworks.jpg

Install mysql server

Install it via:

apt-get install mysql-server

When you see following window, choose your password(You should remember this password, for it’s for administration!!!)
/images/mysqlpasswd.jpg

Then you should run following commands for install the database and enable secure installation. The suggested answer is listed as following:

root@justfordemo:~# mysql_install_db
root@justfordemo:~# mysql_secure_installation 
Change the root password? [Y/n] n
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Install PHP

Install php for processing:

# apt-get install php5-fpm php5-mysql

Open the main php5-fpm configuration file with root privileges:

# nano /etc/php5/fpm/php.ini

Change

;cgi.fix_pathinfo=1

to

cgi.fix_pathinfo=0

Save and restart the php5-fpm service:

# service php5-fpm restart
php5-fpm stop/waiting
php5-fpm start/running, process 15959

Enable php prcessor in NGINX

Change the configuration file /etc/nginx/sites-available/default:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    server_name localhost;

    location / {
        try_files $uri $uri/ =404;
    }
}

to

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    server_name server_domain_name_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

Visit http://10.0.0.6/info.php(assume our ipaddress is 10.0.0.6), then the picture may seems like following:
/images/phprun.jpg

Now your webserver with php support is ready for use.

Wordpress

Create MYSQL database and users

The steps is quite simple, listed as following:

root@justfordemo:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 5.5.40-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

Wordpress

Download the latest wordpress installation file in home directory:

# cd ~
# wget http://wordpress.org/latest.tar.gz

Unzip the tar.gz file and install, but we have to install php-gd and libssh2-php first:

# apt-get install php5-gd libssh2-php
# tar xzvf latest.tar.gz
# cd wordpress
# cp wp-config-sample.php wp-config.php
# nano 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', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');
. . .

Make wordpress running directory and copy the source code here:

# mkdir -p /var/www/html
# rsync -avP ~/wordpress/ /var/www/html/
# chown -R www-data:www-data /var/www/html/*
# cd /var/www/html/
root@justfordemo:/var/www/html# mkdir wp-content/uploads
root@justfordemo:/var/www/html# chown -R :www-data /var/www/html/wp-content/uploads

Modify nginx blocks

# cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress
# nano /etc/nginx/sites-available/wordpress
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/html;
        index index.php index.html index.htm;

        server_name your_domain.com;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}


Now restart the service via:

# ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
# service nginx restart
# service php5-fpm restart

Now visit:
http://10.0.0.6/ you will get the wordpress configuration window, Enjoy it!!!

Trouble-Shooting on LXC of ArchLinux

I try to install ubuntu on ArchLinux using LXC, for the nfs server in ArchLinux seems forbidden the nfsv3’s client request, but in my joggler(which runs 12.04 server) the nfs server works OK, so I installed this version for validation.

Install method

Install the ubuntu machine via following method:

lxc-create -n Ubuntu_Container -t /usr/share/lxc/templates/lxc-ubuntu

Trouble Shooting

qemu-debootstrap

No debootstrap in Archlinux:

which: no qemu-debootstrap in

Solution: create a soft link from debootstrap to qemu-debootstrap:

lrwxrwxrwx 1 root root            11 Oct 19 20:13 qemu-debootstrap -> debootstrap

Keyrings

No keyring file:

I: Keyring file not available at /usr/share/keyrings/ubuntu-archive-keyring.gpg;

directly copy one keyring file from installed ubuntu system to local machine.

gpg Checking

gpg1v for checking signature error:

Error executing gpg1v to check Release signature

Solution: use –no-check-gpg
Edit the /usr/share/lxc/templates/lxc-ubuntu file, add –no-check-gpg after all of the debootstrap:

debootstrap --arch=amd64 --verbose --no-check-gpg

Now everything should goes OK, and you could enjoy the ubuntu installed on your lxc container.

AutoRestart autrace

autrace is a proxy tool which I used for auto-converting the proxy for cross the firewall, it runs in remote server but sometimes it will runs into crash condition. Following is the command for auto-restart this proxy tool.

$ cat autrace.sh
#!/bin/sh
while true; do
   /home/xxxxxxxx/code/autrace -s 
done

Everytime we run autrace.sh like following:

/home/xxxxx/code/autrace.sh &

thus autrace will automatically be restart if it crashes.

Cross-compile the kernel for utu2440

Cross-compiler Preparation

The official documentation said use gcc-3.4.1 for compiling the kernel.

$ cat ~/.zshrc | grep -i set341
alias set341='export PATH=/opt/cross/arm-linux-gcc_3.4.1/bin:$PATH'
$ set341
$ pwd
/media/y/embedded/utu2440/UTU2440-F-T1-20080328/YC2440CDROM_DM9000_080328/utuLinuxfor2440V1.5.8/utu-linux_for_s3c2440_dm9000_V1.5.8
$ arm-linux-gcc -v
Reading specs from /opt/cross/arm-linux-gcc_3.4.1/bin/../lib/gcc/arm-linux/3.4.1/specs
Configured with: /work/crosstool-0.27/build/arm-linux/gcc-3.4.1-glibc-2.3.2/gcc-3.4.1/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/usr/local/arm/3.4.1 --with-headers=/usr/local/arm/3.4.1/arm-linux/include --with-local-prefix=/usr/local/arm/3.4.1/arm-linux --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 3.4.1

Kernel Compilation

Compile the kernel via:

$ make menuconfig
"Load an Alternate Configuration File"-> config_480272_ts
$ make uImage -j4

Trouble shooting: in ArchLinux, install uboot’s mkimage tool via:

$ yaourt -S uboot-mkimage

After compilation finished, copy it to tftpd server and test:

$ cp arch/arm/boot/uImage /media/nfs/rootfs/
$ ls -l uImage 
-rwxrwxrwx 1 root root 1483696 Oct 19  2014 uImage
$ ls -l s3c_kernel/uImage_T5_480x272_ts 
-rw------- 1 nobody nobody 1483468 Oct 19  2014 s3c_kernel/uImage_T5_480x272_ts

We use the compiled kernel and let it runs into the system. Next step we will upgrade the Linux kernel, this may lead to some kernel driver related working.
Current kernel is:

[root@utu-linux /]# uname -a
Linux utu-linux 2.6.13-utulinux2440 #380 Sat Oct 18 16:14:06 CST 2014 armv4tl unknown

Embedded Environment on Arch

NFS Server

Server Setup

$ sudo pacman -S nfs-utils
$ sudo vim /etc/idmapd.conf
[General]

#Verbosity = 0
Verbosity = 1
Pipefs-Directory = /var/lib/nfs/rpc_pipefs
Domain = localdomain

[Mapping]

Nobody-User = nobody
Nobody-Group = nobody

$ sudo vim /etc/conf.d/nfs-common.conf
STATD_OPTS="-p 32765 -o 32766 -T 32803"

$ sudo vim  /etc/conf.d/nfs-server.conf
MOUNTD_OPTS="-p 20048"

$ sudo mkdir -p /srv/nfs4/music
$ cat /etc/exports
/srv/nfs4/ 10.0.0.0/24(rw,fsid=root,no_subtree_check)
/srv/nfs4/music 10.0.0.0/24(rw,no_subtree_check,nohide) # note the nohide option which is applied to mounted directories on the file system.
$ sudo exportfs -rav
$ sudo systemctl restart nfs-server.service

Testing Server:

$ sudo mount -t nfs 10.0.0.221:/srv/nfs4 /mnt
$ ls /mnt

tftpd Server

Server:

$ sudo pacman -S tftp-hpa
$ sudo vim /etc/systemd/system/tftpd.service
[Unit]
Description=hpa's original TFTP daemon

[Service]
ExecStart=/usr/sbin/in.tftpd -s /srv/tftp/
StandardInput=socket
StandardOutput=inherit
StandardError=journal
$ sudo systemctl start tftpd.socket
$ sudo systemctl enable tftpd.socket

Client(10.0.0.230):

$ tftp 10.0.0.221
tftp> get abc.txt
tftp> quit
$ ls -l abc.txt
-rw-r--r-- 1 root root 0 Oct 18 20:23 abc.txt

NFS Servers(Easy)

$ sudo pacman -S nfs-utils
$ cat /etc/exports
/media/home/xxxx *(rw,sync,no_subtree_check)
$ sudo systemctl enable rpcbind.service
$ sudo systemctl start rpcbind.service
$ sudo systemctl enable nfs-server.service
$ sudo systemctl start nfs-server.service