Posted on 六月 14, 2018
CentOS7搭建WordPress
搭服务器和买东西是一样一样的,每一步都在选择。选服务器,选服务器型号,选操作系统,选操作系统版本…
经过一系列抉择后,用了AlphaRacks家的2G内存虚机,操作系统是CentOS7。和阿里云相比,价格还是相当相当便宜的,而且境外主机不用备案,还能用作VPN服务器,相当合适。但是稳定性是个未知数。而且经过几天的体验,晚间高峰期有点坑,经常无响应。
安装Apache
安装 yum -y install httpd 设置开机启动 systemctl enable httpd.service 编辑配置文件 vim /etc/httpd/conf/httpd.conf
配置和其他平台的配置基本一致。不过并不需要配置PHP相关(不知道为什么)。
开启url重写(开启VirtualHost之后不知道这个配置还有没有用了) <Directory /> AllowOverride All Require all denied </Directory>
开启多个VirtualHost
#监听多个端口 Listen 81 Listen 82 #文件末尾增加 <VirtualHost *:81> DocumentRoot /aa/bb/cc ServerName localhost:81 </VirtualHost> <Directory /aa/bb/cc> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> <VirtualHost *:82> DocumentRoot /dd/ee/ff ServerName localhost:83 </VirtualHost> <Directory /dd/ee/ff> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
这样就开启了两个HTTP服务,监听端口分别是81、82,根目录是/aa/bb/cc、/dd/ee/ff
启动apache systemctl start httpd 我用的是 httpd -k start 不知道什么区别 停止 httpd -k stop 重启 httpd -k restart
测试是否好用
echo "This is a httpd test page.">/aa/bb/cc/index.html curl http://localhost This is a httpd test page.
但是外网访问无响应,提示no route to host
解决方法:
sudo iptables -F
https://blog.csdn.net/yijunwanghaha/article/details/72809208
安装PHP
安装 yum -y install php yum -y install php-mysql 测试PHP echo " <html> <h1>This is a php test page.</h1> <?php phpinfo(); ?> </html>">/var/www/html/index.php curl http://localhost/index.php
可以看到PHP信息
安装MariaDB
安装 yum -y install mariadb-service mariadb 开机启动 systemctl enable mariadb.service 开启MariaDB服务 systemctl start mariadb.service
由于CentOS7放弃了MySQL,所以使用MySQL的分支MariaDB代替。
安装配置WordPress
下载压缩包 在某个目录下时 wget -O wordpress.zip https://cn.wordpress.org/wordpress-4.9.4-zh_CN.zip 解压,复制到http根目录,命令忘了 修改wordpress配置文件 vim /var/www/html/wordpress/wp-config.php ###主要是配置数据库名及用户密码 /** WordPress数据库的名称 */ define('DB_NAME', 'wpdb'); /** MySQL数据库用户名 */ define('DB_USER', 'wpadmin'); /** MySQL数据库密码 */ define('DB_PASSWORD', 'pass'); /** MySQL主机 */ define('DB_HOST', 'localhost'); /** 创建数据表时默认的文字编码 */ define('DB_CHARSET', 'utf8'); /** 数据库整理类型。如不确定请勿更改 */ define('DB_COLLATE', ''); 创建wordpress数据库及用户 mysql MariaDB [(none)]> create database wpdb character set utf8; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all privileges on wpdb.* to 'wpadmin'@'localhost' identified by 'pass'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)
打开浏览器,访问主页,根据提示配置即可。
安装主题时,提示
“要执行请求的操作,WordPress需要访问您网页服务器的权限”
解决方法:
chown -R www /home/wwwroot/wpztw.com/ chmod -R 775 /home/wwwroot/wpztw.com/ chmod -R 777 /home/wwwroot/wpztw.com/wp-content/
wp-config.php添加:
define("FS_METHOD", "direct"); define("FS_CHMOD_DIR", 0777); define("FS_CHMOD_FILE", 0777);
https://blog.csdn.net/qq_15710883/article/details/59058237
至此搭建结束。
参考
https://blog.csdn.net/leshami/article/details/78208260
https://www.cnblogs.com/apro-abra/p/4862285.html
https://blog.csdn.net/shineniefei/article/details/76691481
关于ftp搭建:
https://www.cnblogs.com/leoxuan/p/8329998.html
搭建是搭建起来了,没研究透彻。记录一下。