環境:虛拟機 centos7
1、首先先安裝必須要的軟體
yum install httpd -y #安裝apache
yum install php -y #安裝PHP
yum install mariadb-server mariadb #安裝mariadb
2、接下來關閉防火牆
systemctl stop firewalld.service #關閉防火牆
setenforce 0 #關閉selinux
systemctl restart httpd #重新開機apache
3、測試PHP是否安裝成功
vim /var/www/html/info.php #建立一個檔案
#輸入以下内容
<?php
phpinfo();
?>
浏覽器裡輸入ip/info.php,如果有PHP資訊出現,那就是安裝成功了
4、配置mariadb
這裡先要啟動Mysql服務
systemctl start mariadb.service
mysql_secure_installation #進入配置
Enter current password for root (enter for none): #輸入原始root密碼,空密碼就回車
Set root password? [Y/n] #是否設定root密碼
New password: #輸入新密碼
Re-enter new password: #再次輸入
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] #是否移除匿名使用者
... Success!
Disallow root login remotely? [Y/n] #是否禁止遠端root登陸
... skipping.
Remove test database and access to it? [Y/n] #是否删除測試資料庫
Reload privilege tables now? [Y/n] #重新載入
... Success!
5、安裝pypmyadmin
yum install epel-release #安裝epel源
yum install phpMyAdmin #安裝phpmyadmin
vim /etc/httpd/conf.d/phpMyAdmin.conf #配置phpmyadmin
将<Directory /usr/share/phpMyAdmin/>這一段注釋掉,換成以下配置
<Directory /usr/share/phpMyAdmin/>
Options none
AllowOverride Limit
Require all granted
</Directory>
修改認證方式(将 cookie 修改為 http)
vim /etc/phpMyAdmin/config.inc.php
[...]
$cfg['Servers'][$i]['auth_type'] = 'http'; // Authentication method (config, http or cookie based)?
[...]
重新開機httpd服務後,浏覽器中輸入ip/phpmyadmin,輸入你之前設定的資料庫賬号和密碼。如果如下圖所示,就是安裝成功了
phpmyadmin是可裝可不裝的,裝了後設定會比較友善些,畢竟可視化的。
6、配置資料庫
需要建立一個給wordpress使用的新資料庫,兩種方法,一種是phpmyadmin,這種之前的文章說過了。另一種登陸MariaDB
mysql -u root -p #登入資料庫,root是使用者名
輸入正确密碼就能登入成功,開頭語句是MariaDB [(none)]> ,我這裡建立一個test的資料庫,使用者為test1,密碼為123456,語句後面的分号不能忘記了
create database test; #建立test資料庫
CREATE USER test1@localhost IDENTIFIED BY '123456'; #建立使用者,密碼為123456
GRANT ALL PRIVILEGES ON test.* TO test1@localhost; #更改test1權限
FLUSH PRIVILEGES;
exit #退出
完成後重新開機httpd與mariadb服務
7、安裝wordpress
yum -y install wget unzip net-tools #安裝解壓工具
wget http://wordpress.org/latest.zip #下載下傳wordpress壓縮包
unzip -q latest.zip #解壓
cp -rf wordpress/* /var/www/html/ #将wordpress目錄裡的檔案複制到html目錄裡
修改目錄權限
chown -R apache:apache /var/www/html/
chmod -R 755 /var/www/html/
mkdir -p /var/www/html/wp-content/uploads
chown -R :apache /var/www/html/wp-content/uploads
編輯配置檔案,修改資料名,使用者和密碼,這些是之前配置資料庫時建立的,如下圖
cd /var/www/html
cp wp-config-sample.php wp-config.php
vim wp-config.php
重新開機httpd和mariadb服務
8、接下來浏覽器輸入ip,出現如下圖,那便是安裝成功了
問題:
過程中多次出現問題,一一列舉出來
1、一些配置修改後,導緻不能打開網站或其他,需要重新開機服務
systemctl restart httpd
systemctl restart mariadb.service
2、完成wordpress安裝後可以打開網站了,但是在自定義主題時,提示Non-existent changeset UUID,查詢後得知,是資料庫方面的問題,将你建立的資料庫的option項裡的siteurl修改為域名,原因不清楚
3、後來wordpress更新時有提示
這是因為目錄權限的問題。之前我已經給了目錄權限,不知道為什麼會出現這種問題,後來百度後,找到解決辦法,找到wp-config.php,添加以下語句
define("FS_METHOD", "direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);
PS:主題檔案在
wp-content/themes
裡