▲就业班和全程班的小伙伴看这里:(学习老王视频的作业第39-40节)
1、编译安装LNMP,并安装wordpress
安装准备:
本次通过虚拟机的方式进行安装,各个软件版本如下:
centos系统版本: 7
nginx-1.16.1.tar.gz
mariadb-10.2.23.tar.gz
php-7.3.7.tar.bz2
wordpress-5.0.3-zh_CN.tar.gz
确认关闭selinux,关闭防火墙功能。
配置好yum源、epel源,以便于安装各个软件的依赖包。
一、编译安装Mariadb:
1 安装依赖的包
#yum install bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel libdb-cxx-devel
2 创建 mysql 用户
#useradd -r -s /sbin/nologin -d /data/mysql mysql
3 建立数据库文件夹并更改属组
#mkdir /data/mysql ;chown mysql.mysql /data/mysql
4 编译配置文件
cmake . \
-DCMAKE_INSTALL_PREFIX=/app/mysql \
-DMYSQL_DATADIR=/data/mysql/ \
-DSYSCONFDIR=/etc/ \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
5 安装
解压源码包,并进入解压后的源码包目录
#make
#make install
6 准备环境变量
#echo 'PATH=/app/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
#. /etc/profile.d/mysql.sh
7 生成数据库文件
#cd /app/mysql/
#scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql
8 准备配置文件
#cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf
9 准备启动脚本
#cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
10 启动服务
#chkconfig --add mysqld
#service mysqld start
11 建立wordpress数据库及用户
mysql>create database wordpress;
mysql>grant all on wordpress.* to wordpress@'192.168.37.%' identified by 'centos';
二、编译安装nginx:
1)安装相关的包
#yum install -y gcc pcre-devel openssl-devel zlib-devel
2)创建账号并编译安装
# tar -zxvf nginx-1.16.1.tar.gz
# useradd -r -s /sbin/nologin nginx
# cd nginx-1.16.1/
# ./configure --prefix=/apps/nginx \> --user=nginx \> --group=nginx \> --with-http_ssl_module \> --with-http_v2_module \> --with-http_realip_module \> --with-http_stub_status_module \> --with-http_gzip_static_module \> --with-pcre \> --with-stream \> --with-stream_ssl_module \> --with-stream_realip_module
# make && make install
三、编译安装php:
1)安装依赖的包
#yum install libxml2-devel bzip2-devel libmcrypt-devel
2)编译PHP
#tar xvf php-7.3.7.tar.xz
#cd php-7.3.7/
#./configure --prefix=/app/php --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo
#make && make install
#cp php.ini-production /etc/php.ini
#cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#chmod +x /etc/init.d/php-fpm
#chkconfig --add php-fpm
#chkconfig php-fpm on
#cd /app/php/etc
#cp php-fpm.conf.default php-fpm.conf
#cd php-fpm.d/
#cp www.conf.default www.conf
#vim www.conf
user = nginx
group =nginx
:wq
#service php-fpm start
四、配置wordpress环境
#mkdir /data/wordpress
#tar xvf wordpress-5.0.4-zh_CN.tar.gz -C /apps/nginx/html
# setfacl -Rm u:nginx:rwx /apps/nginx/html/wordpress
#cd /apps/nginx/html/wordpress
#cp wp-config-sample.php wp-config.php
#vim wp-config.php
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wordpress');
/** MySQL database password */
define('DB_PASSWORD', 'centos');
/** MySQL hostname */
define('DB_HOST', '192.168.37.17');
:wq
五、修改nginx配置文件
# vim /apps/nginx/conf.d/wordpress_nginx.conf
server {
listen 80;
server_name blog.wordpress.com;
location / {
root html/wordpress;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
六、利用浏览器访问
6.1 设置 hosts 文件,使域名可以解析到主机,在 hosts 文件中添加一行(如果利用Linux图形桌面上的浏览器进行网站安装,hosts文件为 /etc/hosts,如果是用windows安装,则host文件 路径为 C:\Windows\System32\drivers\etc)
192.168.37.7 blog.wordpress.com
6.2 利用浏览器进行安装,输出域名blog.wordpress.com,根据安装向导安装
2、配置虚拟主机,www.x.com域名实现首页访问,admin.x.com域名实现wordpress的后台访问。
(1) 将 www.x.com 与 admin.x.com 域名配置在hosts 文件中
192.168.37.7www.x.com admin.x.com
(2) 登录wordpress后台,在Settings --》General Settings 中,将 WordPress Address (URL) 改为后台地址 admin.x.com,Site Address (URL) 改为前台地址 www.x.com
(3) 修改nginx的配置文件
# vim /apps/nginx/conf.d/wordpress_nginx.conf
server {
listen 80;
server_name www.x.com;
location / {
root html/wordpress;
index index.php index.html index.htm;
}
#添加重写规则,用前台域名访问后台时,跳转到后台域名访问
location ~ /(wp-admin|wp-login.php) {
rewrite / http://admin.x.com/wp-login.php;
}
location ~ \.php$ {
root html/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name admin.x.com;
location / {
root html/wordpress;
index wp-login.php index.php;
}
location ~ \.php$ {
root html/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}