[WordPress] WordPress를 다른 서버로 이전하기

기존에 쓰던 Raspberry pi 3의 OS 버전 업그레이드를 게을리 했더니 해당 버전이 php5까지만 지원해서 그런가 자꾸 누가 들어온다;; 근래 설치했던 php7을 지원하는 Raspberry pi 4 4GB 모델로 워드프레스 블로그를 이전한다.

워드프레스 컨텐츠 내보내기

wordpress 내보내기 도구로 모든 컨텐츠 내보내기

먼저, 기존 워드프레스에서 wordpress 내보내기 도구를 이용해 모든 컨텐츠를 다운로드 받는다: “대시보드” > “도구” > “내보내기” > “모든 컨텐츠” 선택 후 “내보내기 파일 다운로드”

내보낸 파일에서 site 경로 수정하기 (optional)

여기서 내가 예전에 했던 일로 나만 적용되는 게 있는데, 맨 처음에 티스토리에서 워드프레스로 이전할 때 블로그 도메인 이름을 wp.dasomoli.org로 썼던 적이 있다. 그래서 모든 그 때 이전했던 글들 안의 이미지 경로가 wp.dasomoli.org를 사용한채로 export되었다. 내려받은 xml 파일 안의 모든 “wp.dasomoli.org” 혹은 “wp-dasomoli-org” 를 “blog.dasomoli.org”와 “blog-dasomoli-org”로 바꿔주었다.

미디어 라이브러리 복사해두기

미디어 라이브러리도 옮기기 위해 wp-content 안의 uploads/ 디렉토리를 압축해서 이전할 서버로 복사한다.

/var/www/wordpress/wp-content# tar cvfz uploads.tgz uploads
/var/www/wordpress/wp-content# scp uploads.tgz dasomoli@192.168.0.x:/home/dasomoli/

옮긴 미디어 라이브러리의 이전될 서버에서의 DB 등록을 위해서 “Moving Media Library” 플러그인을 설치한 후, 내보내기 후 json파일을 저장한다.

미디어 라이브러리 json 파일 내의 site 경로 수정하기 (optional)

여기서도 역시 json 파일 내부의 모든 “wp.dasomoli.org”를 “blog.dasomoli.org”로 수정한다.

ads.txt 파일 복사하기 (optional)

ads.txt 파일도 있다면 복사해둔다.

/var/www/wordpress# scp ads.txt dasomoli@192.168.0.x:/home/dasomoli/

https 인증서 관련 파일 복사하기

https를 위한 letsencrypt 관련 파일도 압축해서 옮긴다.

/etc# tar cvfz letsencrypt.tgz letsencrypt
/etc# scp letsencrypt.tgz dasomoli@192.168.0.x:/home/dasomoli/

테마 추가 CSS 백업해두기

사용 중인 테마의 추가 CSS가 있다면, 해당 CSS 코드를 어딘가에 복사해두도록 한다: “테마 디자인” > “테마” > “사용자 정의하기” > “추가 CSS”

위젯 백업해두기

사용 중인 위젯들이 있다면, 해당 텍스트나 링크, 코드 등을 어딘가에 복사해두도록 한다: “테마 디자인” > “위젯”의 “Sidebar”

apache2 설정

새로 옮길 서버의 워드 프레스 경로는 이전 서버와 동일하게 “/var/www/wordpress”로 한다. 다음과 같이 이전 서버에서와 동일한 apache2의 site 설정 파일을 작성한다. https를 위한 Rewrite로 시작하는 마지막쯤의 주석 3줄은 지워도 무방하다.

# vi /etc/apache2/sites-available/blog.dasomoli.org.conf
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName blog.dasomoli.org

        <Directory /var/www/wordpress>
                Options FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>

        ServerAdmin dasomoli@gmail.com
        DocumentRoot /var/www/wordpress

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/blog_error.log
        CustomLog ${APACHE_LOG_DIR}/blog.access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
#RewriteEngine on
#RewriteCond %{SERVER_NAME} =blog.dasomoli.org
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

wordpress 설치

wordpress 내려받아 압축 해제하기

https://wordpress.org/ 에서 최신 버전의 wordpress의 .tar.gz 파일을 내려받아 새로 설치할 사이트의 /var/www/ 아래에서 압축을 해제한다. 현재는 5.4.1이다.

/var/www# tar xvfz wordpress-5.4.1.tar.gz

ads.txt 복사하기

ads.txt를 복사해온다.

/var/www/wordpress# cp ~dasomoli/ads.txt .

wordpress 디렉토리 아래 파일 owner와 권한 설정하기

/var/www/wordpress 디렉토리와 파일의 owner는 apache2를 실행하는 www-data로, 권한은 디렉토리는 755로, 파일은 644로 설정한다.

/var/www# chown -R www-data:www-data wordpress
/var/www# chmod 755 wordpress
/var/www# cd wordpress
/var/www/wordpress# find . -type d -exec chmod 755 {} \;
/var/www/wordpress# find . -type f -exec chmod 644 {} \;

phpmyadmin 설치

기본적으로 https://wordpress.org/support/article/how-to-install-wordpress/ 의 설치 방법을 따른다. 해당 가이드에서처럼 편의를 위해 phpmyadmin를 설치하자. [MySQL] phpmyadmin 설치 글의 절차를 따른다.

# apt-get install phpmyadmin

phpmyadmin은 내부 네트워크에서만 접속 가능하도록 만들자.

# vi /etc/apache2/conf-enabled/phpmyadmin.conf

아래처럼 Require ip 구문을 추가한다. “::1” 은 local interface, 즉 127.0.0.1과 같다. “192.168.0” 은 192.168.0.x 대역을 말한다.

<Directory /usr/share/phpmyadmin>
    Options SymLinksIfOwnerMatch
    DirectoryIndex index.php
    Require ip 192.168.0
    Require ip ::1

apache2를 reload한다.

# systemctl reload apache2

wordpress가 사용할 database와 user 추가 및 설정하기

phpmyadmin은 phpmyadmin에서 database를 추가하기 위해서 root 사용자로 로그인하려고 할 때 어려움을 겪는다면, [MySQL] phpmyadmin에서 root 사용자 사용 불가 시 사용자 추가 방법을 참고하자. “wordpress” database와 “wordpress” 사용자를 추가한다. “wordpress” 사용자는 “wordpress” database에 모든 권한을 갖도록 설정한다.

apache2에서 wordpress site enable

apache2의 아까 설정했던 site를 enable한다.

# a2ensite blog.dasomoli.org.conf

워드프레스 설치 페이지 접속해 설치하기

워드프레스 설치 URL wp-admin/install.php (예를 들면, http://blog.dasomoli.org/wp-admin/install.php) 에 접속한다. 설치가 끝나면 wp-config.php가 생성될 것이다. 파일 권한 문제가 있어 생성하지 못하는 경우, 브라우저에 나타난 wp-config.php를 복사해서 쉘에서 생성 후 붙여넣기 한다.

미디어 라이브러리 복구하기

아까 복사해뒀던 미디어 라이브러리 압축 파일(uploads.tgz)를 wp-content/ 아래에서 압축 해제한다.

/var/www/wordpress/wp-content# cp ~dasomoli/uploads.tgz .
/var/www/wordpress/wp-content# tar xvfz uploads.tgz

uploads 디렉토리 역시 owner를 www-data로, 디렉토리는 755, 파일은 644로 권한 설정을 해준다.

/var/www/wordpress/wp-content# chown -R www-data:www-data uploads
/var/www/wordpress/wp-content# find . -type d -exec chmod 755 {} \;
/var/www/wordpress/wp-content# find . -type f -exec chmod 644 {} \;

새로 설치한 워드프레스에 접속해서 “Moving Media Library”를 설치한 후, “가져오기”로 json파일을 선택해 미디어 파일들을 DB에 등록한다.

이제 아까 저장해뒀던 모든 contents의 xml 파일을 가져온다. 모두 잘 보이는지 확인한다.

워드프레스 고유 주소 설정 (optional)

나는 티스토리에서 이전할 때 설정했던대로 사용했던 고유주소를 postname으로 설정할 것이다. “대시보드” > “설정” > “고유주소” > “글 이름”을 선택하여 /%postname%/ 가 되도록 만든다.

.htaccess 만들기 (optional)

나의 경우는 무엇때문인지 .htaccess 파일이 생성이 안되었었는데, 이 경우 직접 만들어서 아래 내용을 붙여 넣어주면 된다.

/var/www/wordpress# vi .htaccess
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

파일 owner와 권한주는 것을 잊지 말자.

/var/www/wordpress# chown www-data:www-data .htaccess
/var/www/wordpress# chmod 755 .htaccess

https 설정하기

letsencrypt.tgz을 /etc/에 복사한 후 압축을 해제한다.

/etc# cp ~dasomoli/letsencrypt.tgz .
/etc# tar xvfz letsencrypt.tgz

rewrite 모듈을 enable하고, php-imagick를 설치한다.

# a2enmod rewrite
# apt-get install php-imagick

letsencrypt를 위한 certbot을 설치한후, apache 설정을 위해 실행한다. 아래는 라즈베리파이인 경우이다.

# apt-get install python-certbot-apache
# certbot --apache

우분투 22.04의 경우 다음과 같다.

# apt install certbot python3-certbot-apache
# certbot --apache

기존 인증서를 유지하면서 설치하도록 하면 된다.

설치한 워드프레스에 접속해서 “설정” > “일반” > “워드프레스 주소 (URL)”와 “사이트 주소 (URL)”을 https:// 로 바꾼다.

테마 재설치하기

기존에 설치했던 테마를 다시 설치한다. 나는 현재 sparkling 테마를 사용하고 있다.

추가 CSS가 있다면, 다시 설정하자: “테마 디자인” > “테마” > “사용자 정의하기” > “추가 CSS” 에 기존 사이트의 추가 CSS를 복사 붙여넣기.

pre {
	font-family: 'Nanum Gothic Coding', monospace;
	tab-size: 8;
}

.main-content-area {
	width: 100%;
	margin: 0px;
}

@media (min-width:992px) {
  .main-content-inner {
	  width: 70%;
	  margin: 0px;
  }

  .widget-area {
  	width: 30%;
  }
}

위젯 복구하기

아까 백업해두었던 위젯 설정을 다시 설정한다.

[Raspberry Pi] 라즈베리파이에 미디어위키(MediaWiki) 설치

라즈베리파이의 OS, Raspbian에서는 패키지를 제공하므로 매우 간단하다.

sudo apt-get install mediawiki

 

설치하면 apache2의 available configuration에 mediawiki라는 새로운 configuration(/etc/apache2/conf-available/mediawiki.conf)이 생긴다.

아래의 Alias를 풀어서 /mediawiki 로 접근해도 된다.

#Alias /mediawiki /var/lib/mediawiki

 

난 VirtualHost를 이용한다.

/etc/apache2/sites-available/wiki.dasomoli.org.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName wiki.dasomoli.org

        ServerAdmin dasomoli@gmail.com
        DocumentRoot /var/lib/mediawiki

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/wiki_error.log
        CustomLog ${APACHE_LOG_DIR}/wiki.access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        Include conf-available/serve-cgi-bin.conf
</VirtualHost>

 

이제 mediawiki configuration을 enable 하자

sudo a2enconf mediawiki

wiki.dasomoli.org site도 enable하자

sudo a2ensite wiki.dasomoli.org.conf

apache2도 reload하자

sudo service apache2 reload

 

이제 wiki.dasomoli.org에 접속해서 mediawiki 설치를 시작한다.

설치가 끝나면 LocalSettings.php 파일을 저장할 수 있는데, 이 파일을 /etc/mediawiki/LocalSettings.php 로 저장한다.

다시 wiki.dasomoli.org로 접속해보면. 설치된 위키를 볼 수 있다!