> ## Content Index
> Fetch the complete content index at: https://note.xdq.me/llms.txt
> Use this file to discover other available public pages before exploring further.

# Centos 7 安装wordpress
- URL: https://note.xdq.me/centos-7-an-zhuang-wordpress/
- Published: 2016-07-09T03:05:23.000Z
- Updated: 2026-10-03T03:02:29.000Z
- Author: xud6
- Tags: centos, centos7, apache, #Import 2026-10-03 02:45

首先安装LAMP  
[Centos 7 安装LAMP并配置event MPM和FastCGI](https://note.xdq.me/centos-7-an-zhuang-lampbing-pei-zhi-event-mpmhe-fastcgi/)

以下假设wordpress安装在/opt/wordpress下  
创建安装文件夹

```
sudo mkdir /opt/wordpress
sudo chown -R `whoami`:`whoami` /opt/wordpress

```

##### 准备数据库

```
mysql -u root -p

```

输入MySQL的ROOT密码

```
CREATE DATABASE 数据库名;
CREATE USER 用户名@localhost IDENTIFIED BY '用户密码';
GRANT ALL PRIVILEGES ON 数据库名.* TO 用户名@localhost IDENTIFIED BY '用户密码';
FLUSH PRIVILEGES;
exit

```

##### 安装wordpress

```
cd $home
wget http://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
mv wordpress/* /opt/wordpress/
cd /opt/wordpress/
mkdir wp-content/uploads
> .htaccess
cp wp-config-sample.php wp-config.php
nano wp-config.php

```

替换`database_name_here`为数据库名，替换`username_here`为用户名，替换`password_here`为用户密码  
在末尾添加`define('FS_METHOD','direct');`  
更改文件夹所有者为apache

```
sudo chown -R apache:apache ./

```

配置selinux

```
sudo yum install -y policycoreutils-python -y
sudo semanage fcontext -a -t httpd_sys_content_t "/opt/wordpress(/.*)?"
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/opt/wordpress/wp-content(/.*)?"
sudo semanage fcontext -a -t httpd_sys_rw_content_t /opt/wordpress/.htaccess
sudo semanage fcontext -a -t httpd_sys_rw_content_t /opt/wordpress/wp-config.php
sudo restorecon -R -v /opt/wordpress

```

##### 添加virtualhost

```
sudo nano /etc/httpd/conf.d/wordpress.conf

```

内容为

```
<VirtualHost *>
    DocumentRoot /opt/wordpress
    ServerName 你的服务器域名
    <Directory "/opt/wordpress">
        AllowOverride none
        Require all granted
        Allow from all
        DirectoryIndex index.php
        IncludeOptional /opt/wordpress/.htaccess
    </Directory>
</VirtualHost>

```

重启Apache

```
sudo systemctl restart httpd

```

##### 安装php插件

```
sudo yum install php-gd opcache -y

```

重启php-fpm

```
sudo systemctl restart php-fpm

```

##### wordpress初始化

访问http://域名 开始wordpress初始化

##### 其他

###### 允许发送邮件

```
sudo setsebool -P httpd_can_sendmail 1

```