LAMP环境搭建及wordpress的安装配置

LAMP:linux+apache+mysql+php

mariadb安装参考博客:https://www.cnblogs.com/zhanzhan/p/7729981.html

yum install mariadb-server mariadb
yum install php
yum install php-mysql
yum install httpd 
systemctl start mariadb
netstat –tnlp
tcp6       0      0 :::3306                 :::*                    LISTEN      8512/mysqld 

可以看到3306端口已监听

设置用户密码并删除匿名账户

mysql_secure_installation
[root@node35 ~]# 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, we'll need the current
password for the root user.  If you've just installed MySQL, 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): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
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] 
New password: 
Sorry, you can't use an empty password here.

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...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - 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!




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

Thanks for using MySQL!

进入mysql交互环境

mysql –uroot –p

[root@node35 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.6.40 MySQL Community Server (GPL)

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

授予所有主机可访问所有数据库

mysql> grant all privileges on *.* to 'root'@'%' identified by 'rootpassword' with grant option;   
Query OK, 0 rows affected (0.00 sec) 

刷新mysql系统权限表

mysql> flush  privileges; 

创建数据库wordpress(创建的数据库是给wordpress使用的)

mysql> create database wordpress;
Query OK, 1 row affected (0.01 sec)

启动apache服务器

systemctl start httpd

添加httpd对php文件的解析支持

         vim/etc/httpd/conf/httpd.conf加入

         AddTypeapplication/x-httpd-http .php .phtml

测试php程序:

          php程序执行环境

在/var/www/html文件夹下

vim testphp.php

在test.php文件中加入

<?php
     phpinfo();
?>

通过网页访问可以看到php的详细信息

在/var/www/html文件夹下新建phptest.php文件,在文件中加入

 <?php
        $conn=mysql_connect('localhost','root',密码);
        if ($conn)
                echo "ok";
        else
                echo "failure";
        mysql_close();
        phpinfo();
?>

通过网页访问:http://192.168.137.135/phptest.php


安装使用wordpress:

wordpress官网:https://cn.wordpress.org/

下载wordpress

wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
tar -zxvf wordpress-4.9.4-zh_CN.tar.gz

将解压后的文件夹放置在/var/www/html/下

cd wordpress/
cp wp-config-sample.php  wp-config.php
vim wp-config.php
修改数据库名,用户,密码,主机地址

主要信息:

define('DB_NAME', 'wordpress');

/** MySQL数据库用户名 */
define('DB_USER', 'root');

/** MySQL数据库密码 */
define('DB_PASSWORD', '密码');

/** MySQL主机 */
define('DB_HOST', 'localhost');

/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');

访问wordpress的安装网页

http://192.168.137.135/wordpress/wp-admin/install.php

其中的IP改为主机IP

wordpress官网安装指导页面


设置登录账号并登录










猜你喜欢

转载自blog.csdn.net/matengbing/article/details/80264977