CentOS7.2配置LNMP环境并安装配置网站WordPress
1,安装环境查看
2,安装MySQL5.7.22
下载MySQL
wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
解压
tar -xf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
清理mysql-libs
yum remove mysql-libs
安装,安装顺序为common-libs-client-server
rpm -vih mysql-community-common-5.7.22-1.el7.x86_64.rpm rpm -vih mysql-community-libs-5.7.22-1.el7.x86_64.rpm rpm -vih mysql-community-client-5.7.22-1.el7.x86_64.rpm rpm -vih mysql-community-server-5.7.22-1.el7.x86_64.rpm rpm -vih mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm
PS: mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm需要安装 否则在安装php时会报错
修改my.cnf配置文件增加一行取消密码复杂度验证
validate_password_policy=LOW
启动
systemctl start mysqld systemctl status mysqld systemctl enable mysqld
初始密码为
cat /var/log/mysqld.log | grep password
登录修改密码
mysql -uroot -p1qaz2wsx set password=password('password');
创建数据库设置权限
create database wordpress; create user wordpress@'localhost' identified by 'password'; garnt all on wordpress.* ro wordpress@'localhost'; flush privileges;
3,安装nginx
下载
wget http://nginx.org/download/nginx-1.16.0.tar.gz
解压
tar -xf nginx-1.16.0.tar.gz
安装必要插件
yum -y install gcc-c++ zlib-devel pcre-devel
安装
cd nginx ./configure --prefix=/usr/local/nginx-1.16.0 make && make install
设置软连接
ln -s /usr/local/nginx-1.16.0/ /usr/local/nginx
修改配置文件
/usr/local/nginx/conf/nginx.conf
增加以下内容
location ~ \.php$ { root html/wordpress; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
PS:标红地方与默认配置不同,需要注意,如不设置如此会导致网站访问php文件出现404
启动
/usr/local/nginx/sbin/nginx
4,安装配置php
设置yum
rpm -ivh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装php7
yum -y install php70w php70w-fpm php70w-pdo php70w-mysql
查看php版本
php -v php-fpm -v
验证在跟目录下面创建test.php
<?php phpinfo() ?>
访问
http://ip/test.php
出现以下界面代表安装php成功
php连接mysql测试
mysql.php
<?php $mysqli = new mysqli("localhost", "root", "Mysql123456!"); if(!$mysqli) { echo"database error"; }else{ echo"MySQL successful"; } $mysqli->close(); ?>
访问出现以下代表php连接mysql成功
5,安装wordpress
官网下载压缩包下载地址
https://cn.wordpress.org/download/
解压至网站根目录,页面访问按照提示一步步操作即可,配置文件wp-config.php会在页面生成复制代码新建配置文件即可