如何在CentOS 6安装最新的wordpress

时间:2019-08-20 17:58:22  来源:igfitidea点击:

安装wordpress非常简单,但在这里我们将创建一个数据库用户,该用户只能访问wordpress数据库。
我们在新安装的CentOS 6.4上进行搭建Wordpress,因此我们将会安装一些额外的包。

安装wget包,用命令行下载WordPress。

yum -y install wget

用wget命令下载最新的WordPress包

cd /root
wget http://wordpress.org/latest.tar.gz

安装所需的依赖关系,web服务器(apache)和数据库服务器(MySQL)

yum install httpd mysql-server php php-mysql php-pdo

将下载的WordPress包解压到/var/www/html中

tar -xvzf /root/latest.tar.gz -C /var/www/html

将提取出来的目录 wordpress改名为其他名称

这里我将其更名为 blog
同时修改它的拥有者和组。

mv /var/www/html/wordpress /var/www/html/blog
chown -R apache:apache /var/www/html/blog

禁用SELINUX

编辑文件 /etc/sysconfig/selinux,将SELINUX改成disabled

[root@localhost ~]#  vi /etc/sysconfig/selinux 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

重启操作系统,使Selinux更改生效

init 6

再次登录服务器。启动apache和mysql服务器。

/etc/init.d/httpd start 
/etc/init.d/mysqld start

设置mysql root密码。

如果我们是在已安装了MySQL的服务器中搭建Wordpress,并且已经有了mysql root用户,则可以跳过这一步。此设置是首次安装Mysql进行的.

执行命令“/usr/bin/mysql_secure_installation”,根据提示进行操作:

[root@localhost ~]# /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, well need the current
password for the root user.  If youve just installed MySQL, and
you havent set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...



All done!  If youve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


[root@localhost ~]# 

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 10
Server version: 5.1.69 Source distribution

Copyright (c) 2000, 2013, 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>  exit

启动并配置web服务器。

我们将wordpress包放在/var/www/html,并将wordpress目录重命名为blog。
因此, DocumentRoot是/var/www/html/blog

编辑文件/etc/httpd/conf/httpd.conf文件
并在最后一行粘贴下面的内容。

vi /etc/httpd/conf/httpd.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/blog
    ServerName example.com
    ErrorLog logs/example.com-error_log
    CustomLog logs/example.com-access_log common
</VirtualHost>

重新启动Web服务器

/etc/init.d/httpd restart

创建MySQL用户名并设置密码

登录MySQL 服务器

mysql -u root -p

创建数据库用户、密码并为该用户提供权限

mysql> create database wordpress;
 
mysql> create user 'wordpressuser'@'localhost' IDENTIFIED BY 'GivePassword';
 
mysql> GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost';
 
mysql> flush privileges;
 
mysql> exit;

停止iptables服务

/etc/init.d/iptables off ;chkconfig iptables off

如果不想关闭防火墙,则执行下面命令来添加iptable规则
iptables-A INPUT-ptcp-mtcp--dport 80-j ACCEPT

安装WordPress

在浏览器中,打开 http://服务器ip
开始安装WordPress,按照说明填写所需信息。

安装完成后,我们可以通过
http://example.com/wp-admin访问WP后台
http://example.com/访问WP站点。