This website requires JavaScript.

将WordPress从LEMP环境的Debain迁移至LAMP环境的Archlinux

胖哥在N年前玩过三年Linux,期间Archlinux和Gentoo用的时间最多.这两天看到Linode 带Arch系统,便萌生了迁移WP的想法,以下是我的迁移过程.

上手先把源改掉:

vim /etc/pacman.d/mirrorlist
官方镜像列表[ https://www.archlinux.org/mirrorlist/](https://www.archlinux.org/mirrorlist/)

一. 在Archlinux中安装LAMP环境

  1. 安装Apache

将/etc/httpd/conf/httpd.conf中的ServerAdmin 改为自己的邮箱

ServerAdmin admin@billhell.com
启动服务:
systemctl start httpd
设置开机自动启动:
systemctl enable httpd
以下是针对[Linode 1024](https://www.linode.com/?r=3754b12a4c5afa1410bcb5ad6816233c7f85285c)的优化配置,如果你跟我一样用的[Linode](https://www.linode.com/?r=3754b12a4c5afa1410bcb5ad6816233c7f85285c)的1G 的VPS,可以参考一下
vim /etc/httpd/conf/extra/httpd-mpm.conf
内容如下
<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 6
MaxSpareServers 12
MaxRequestWorkers 80
MaxRequestsPerChild 3000
</IfModule>
vim /etc/httpd/conf/extra/httpd-default.conf
内容如下
KeepAlive Off
  1. 安装PHP

pacman -S php php-apache
php-apache 自带的 libphp5.so 与 mod_mpm_event 不兼容,需要换成 mod_mpm_prefork。否则有以下错误:
Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.  You need to recompile PHP.
AH00013: Pre-configuration failed
httpd.service: control process exited, code=exited status=1
打开 /etc/httpd/conf/httpd.conf,然后把:
LoadModule mpm_event_module modules/mod_mpm_event.so
改为:
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
启动PHP模块,在
LoadModule dir_module modules/mod_dir.so
之后加上:
LoadModule php5_module modules/libphp5.so
然后还要在 Include 列表末尾加上:
Include conf/extra/php5_module.conf
接着重启 httpd.service:
systemctl restart httpd
PHP配置如下: 编辑 /etc/php/php.ini
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off 
log_errors = On 
error_log = /var/log/php/error.log
max_execution_time = 30 
memory_limit = 128M
max_input_time = 30
创建日志目录
mkdir /var/log/php
chown http /var/log/php
测试一下 php 是否安装妥当,编辑 test.php:
vim /srv/http/test.php
内容如下
<?php phpinfo(); ?>
浏览器打开自己的域名www.bihell.com 查看是否OK
  1. 安装MariaDB

pacman -S mariadb
运行以下命令,否则MySQL会启动失败
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
启动MySQL服务
systemctl start mysqld
systemctl enable mysqld
运行安全安装命令,设置root密码,删除远程访问和实例数据库等.
mysql_secure_installation
编辑/etc/php/php.ini,将以下两行注释去掉
extension=pdo_mysql.so
extension=mysqli.so
  1. 还原WordPress

备份方式请参考我之前的博文 使用Dropbox Uploader脚本定时备份Linux数据 迁移WordPress备份文件解压以后将Wordpress中所有文件移动到站点跟目录 (默认为/srv/http) 注意修改权限 如果不知道自己Web的线程的用户名,可以通过以下php代码获得

<?php echo(exec("whoami")); ?>
chown -R http:http http

浏览网站,此时应该能访问首页,但是固定链接会报错. 由于Apache 开启Rewrite之后会在站点目录下生成.htaccess文件.而nginx没有. 如果你知道怎么写,可以自行创建该文件.若不会.可以采用简单暴力的办法: 装一个新的WP 然后选择固定链接让它自动生成.htaccess. 然后覆盖掉数据库,并且把themes,plugins和uploads文件夹复制到新建的WordPress的wp-content目录下. 之后配置Apache ,开启rewrite模块,并进行相关配置, 编辑 /etc/httpd/conf/httpd.conf,取消下面这行注释:

LoadModule rewrite_module modules/mod_rewrite.so
创建并编辑/etc/httpd/conf/extra/wordpress.conf
<IfModule mod_rewrite.c>
<Directory "/srv/http/wordpress">
        Options FollowSymLinks
        AllowOverride All
</Directory>
</IfModule>
然后在把它加到 /etc/httpd/conf/httpd.conf 的 Include 列表:
Include /etc/httpd/conf/extra/wordpress.conf
至此整个迁移就完成了.
  1. 其他配置

如果需要建立虚拟目录则需要额外配置 编辑/etc/httpd/conf/httpd.conf将下行注释去掉

Include conf/extra/httpd-vhosts.conf
然后编辑配置文件httpd-vhosts.conf
vim /etc/httpd/conf/extra/httpd-vhosts.conf
当然,直接弄两个Host配置文件也可以 Host1
vim /etc/httpd/conf/extra/www.bihell.com.conf
<VirtualHost *:80>
     ServerAdmin tpxcer@outlook.com
     ServerName bihell.com
     ServerAlias www.bihell.com
     DocumentRoot /srv/http/www.bihell.com/public_html
     ErrorLog /srv/http/www.bihell.com/logs/error.log
     CustomLog /srv/http/www.bihell.com/logs/access.log combined
    <Directory "/srv/http/www.bihell.com/public_html/">
        DirectoryIndex index.html index.php
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
Host2
vim /etc/httpd/conf/extra/ss.bihell.com.conf
<VirtualHost *:80>
     ServerAdmin tpxcer@outlook.com
     ServerName ss.bihell.com
     ServerAlias ss.bihell.com
     DocumentRoot /srv/http/ss.bihell.com/public_html
     ErrorLog /srv/http/ss.bihell.com/logs/error.log
     CustomLog /srv/http/ss.bihell.com/logs/access.log combined
    <Directory "/srv/http/www.bihell.com/public_html/">
        DirectoryIndex index.html index.php
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
把这两个文件加入到主配置文件中
vim /etc/httpd/conf/httpd.conf
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
Include conf/extra/www.bihell.com.conf
Include conf/extra/ss.bihell.com.conf
可以先测试一下配置是否正确
apachectl configtest
创建相关目录
vim /etc/httpd/conf/extra/www.bihell.com.conf
mkdir -p /srv/http/www.bihell.com/{public_html,logs}
mkdir -p /srv/http/ss.bihell.com/{public_html,logs}

参考文档

Wordpress Archlinux Wiki Apache HTTP Server Archlinux Wiki WordPress 从 openSUSE 迁移到 Arch Linux LAMP Server on Arch Linux

0条评论
avatar