安裝之前:建議安裝各種軟件
[root@localhost ~]# yum -y install wget zip unzip net-tools
一、安裝apache
測試環境建議關閉防火牆和SELinux
1.1安裝apache
[root@localhost ~]# yum -y install httpd
1.2配置apache
1.2.1首先需要創建一個存放網站的目錄(文件夾)
[root@localhost ~]# cd /home/www
[root@localhost www]# mkdir test //創建站點目錄,這里創建了一個test站點目錄
1.2.2修改apache配置文件(默認配置文件是/etc/httpd/conf/http.conf)
[root@localhost conf.d]# cd /etc/httpd/conf/
[root@localhost conf]# vim httpd.conf //增加以下內容,紅色部分根據自己的實際情況修改
<VirtualHost *:80>
Serveradmin 443753982@qq.com
ServerName www.test.cn
DocumentRoot /home/www/test
<Directory "/home/www/test">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*).htmp$ index.html
</IfModule>
</Directory>
</VirtualHost>
[root@localhost conf]# systemctl start httpd
[root@localhost conf]# systemctl enbale httpd
二、安裝mariadb(Mysql)
2.1安裝mariadb
Centos7已經沒有自帶mysql了,默認自帶的是Mariadb
[root@localhost ~]# yum -y install mariadb-server mariadb
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb
2.2 初始化mariadb,並配置root密碼:
[root@localhost ~]# mysql_secure_installation //初始化mariadb並配置數據庫的root密碼
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't 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): (輸入原始root密碼,默認無,直接回車)
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y (是否設置root密碼,一般都需要設置一個密碼)
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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 (是否移除匿名用戶,為了安全建議刪除)
... skipping.
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 (是否禁止遠程root登陸,為了安全建議禁止)
... skipping.
By default, MariaDB 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 (是否刪除測試數據庫,為了安全,建議刪除)
... skipping.
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 you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@localhost ~]#
三、安裝PHP
3.1安裝PHP
3.1.1 配置源:(或者去官網下載更新的版本上傳到服務器)
[root@localhost ~]# rpm -Uvh http://mirror.webtatic.com/yum/el7/epel-release.rpm
[root@localhost ~]# rpm -Uvh http://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3.1.2安裝fpm和組件,fpm是php的進程管理器
[root@localhost ~]# yum -y install php56w-fpm //(也可以php70w-fpm,或者更高的版本)
[root@localhost ~]# yum search php //查看php有哪些組件
[root@localhost ~]# yum -y install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 //安裝php組件
四、配置WordPress數據庫
4.1首先登陸MariaDB為WordPress建立數據庫及用戶
[root@localhost ~]# mysql -u root -p
Enter password: //輸入數據庫密碼進入數據庫
MariaDB [(none)]>
MariaDB [(none)]> create database wordpressdb; //新建的數據庫為wordpressdb
MariaDB [(none)]> CREATE USER wordpressuser@localhost IDENTIFIED BY '123456'; //新建用戶為wordpressuser,密碼為123456
MariaDB [(none)]> grant all privileges on wordpressdb.* to wordpressuser@localhost; //並為新建的wordpressuser這個用戶賦予@localhost(即本地)的權限
MariaDB [(none)]> flush privileges; //刷新用戶權限
MariaDB [(none)]> exit
五、安裝WordPress
5.1下載wordpress
[root@localhost ~]# cd /home/www/test
[root@localhost test]# wget http://wordpress.org/latest.zip
[root@localhost test]# unzip -q latest.zip
或者可以在windows電腦里面下載好了上傳到 /home/www/test這個文件夾
5.2修改文件夾權限
[root@localhost test]# chown -R apache:apache /home/www/test
5.3編輯配置文件
[root@localhost ~]# cd /home/www/test/wordpress //進入wordpress解壓的目錄里面
[root@localhost test]# cp wp-config-sample.php wp-config.php //先把配置文件的原始文件備份一個
[root@localhost test]# vim wp-config.php //修改配置
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpressdb' ); //修改為第四步自己新建數據庫的名稱
/** MySQL database username */
define( 'DB_USER', 'wordpressuser' ); //修改為第四步自己新建數據庫用戶的用戶名
/** MySQL database password */
define( 'DB_PASSWORD', '123456' ); //修改為第四步自己新建數據庫用戶的密碼
修改后保存退出,並重啟服務
[root@localhost ~]# systemctl restart httpd.service
[root@localhost ~]# systemctl restart mariadb.service
六、登陸wordpress
打開瀏覽器輸入網址:http://www.test.cn/wp-admin/index.php 然后初始化配置即可