一、安装apache、php并测试安装结果
[root@node1 ~]# yum -y install httpd php php-mysql
[root@node1 ~]# yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel #安装php相关组件
[root@node1 ~]# mkdir /data/web/a.org/ -p #以此目录作为网站目录
[root@node1 ~]# cd /data/web/a.org
[root@node1 a.org]# vim phpinfo.php #打开此文件加入以下内容测试php的安装
<html>
<title>PHP Test Page</title>
<body>
<h1>PHP Info Page</h1>
<?php
phpinfo();
?>
</body>
</html>
#编辑/etc/httpd/conf/httpd.conf
#简单键入一个虚拟主机内容如下:
[root@node1 a.org]# vim /etc/httpd/conf/httpd.conf
<VirtualHost 192.168.1.129>
ServerName www.a.org
DocumentRoot "/data/web/a.org"
<Directory "/data/web/a.org">
Require all granted ##主要是这个apache2.4必须要加上否则没权限
</Directory>
</VirtualHost>
[root@node1 a.org]# systemctl start httpd
从浏览器访问主机http://192.168.1.129/phpinfo.php,出现如下页面则php安装成功
二、测试php和mariadb的连接
[root@node1 ~]# yum -y install mariadb-server
[root@node1 ~]# mysql_secure_installation
Enter current password for root (enter for none):(输入原始root密码,若无enter)
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] (是否设置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!
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@node1 a.org]# vim php-mysql.php
<?php
$conn = mysql_connect('127.0.0.1','root','PASSWORD'); # 输入设定的密码没有则为空
if ($conn)
echo "OK";
else
echo "NO";
?>
[root@node1 a.org]# systemctl start mariadb.service
从浏览器访问主机http://192.168.1.129/php-mysql.php,出现如下页面则连接成功
出现如下页面则表示连接成功
三、配置wordpress个人博客
首先登陆MariaDB为WordPress建立数据库及用户
[root@node1 ~]# mysql -u root -p # 这里进入了MariaDB,按行执行下面代码:
CREATE DATABASE wordpressdb //新建的数据库为wordpressdb
CREATE USER wordpressuser@localhost IDENTIFIED BY '123456' //用户为wordpressuser,密码为123456
GRANT ALL PRIVILEGES ON wordpressdb.* TO wordpressuser@localhost
FLUSH PRIVILEGES //更改用户权限
\q # 退出
重启相关服务
[root@node1 a.org]# systemctl restart httpd.service
[root@node1 a.org]# systemctl restart mariadb.service
下载wordpress并进行配置
[root@node1 ~]# wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
[root@node1 ~]# tar xf wordpress-4.9.4-zh_CN.tar.gz
[root@node1 ~]# mv wordpress /data/web/a.org/
[root@node1 ~]# chown -R apache:apache /data/web/a.org/wordpress
[root@node1 ~]# cd /data/web/a.org/wordpress
[root@node1 wordpress]# cp wp-config-sample.php wp-config.php
[root@node1 wordpress]# vim wp-config.php
往下找到需要修改的内容,修改三个部分:其中wordpressdb为数据库名称,wordpressuser为数据库用户名,123456为数据库密码
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpressdb');
/** MySQL数据库用户名 */
define('DB_USER', 'wordpressuser');
/** MySQL数据库密码 */
define('DB_PASSWORD', '123456');
# 保存并退出后重启相关服务
[root@node1 ~]# systemctl restart httpd.service
[root@node1 ~]# systemctl restart mariadb.service
随后访问站点http://192.168.1.129/wordpress进行相关配置
php与mariadb的连接主要是为了安装phpmyadmin而测试的,这一步在以上可以忽略,你们可以自行查询相关资料进行安装配置,非常简单,可以通过它来对mariadb以页面方式进行管理。