Q1、编译安装LNMP,并安装wordpress
1、准备好源码包
[root@Centos7 ~]# cd /usr/local/src/
[root@Centos7 src]# ls -lh
total 82M
-rw-r--r-- 1 root root 69M Dec 6 2019 mariadb-10.2.25.tar.gz
-rw-r--r-- 1 root root 1009K Apr 28 17:02 nginx-1.16.1.tar.gz
-rw-r--r-- 1 root root 12M Mar 7 22:26 php-7.3.15.tar.xz
2、编译mariadb-10.2.25
[root@Centos7 src]# mkdir /data/mysql
[root@Centos7 src]# useradd -r -s /sbin/nologin -d /data/mysql mysql
[root@Centos7 src]# chown mysql.mysql /data/mysql
#安装依赖
[root@Centos7 src]# 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 -y
#编译
[root@Centos7 ~]$ tar xf mariadb-10.2.25.tar.gz
[root@Centos7 ~]$ cd mariadb-10.2.25/
[root@Centos7 mariadb-10.2.25]$ cmake . -DCMAKE_INSTALL_PREFIX=/apps/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=utf8mb4 \
-DDEFAULT_COLLATION=utf8_general_ci
[root@Centos7 mariadb-10.2.25]$ make && make install
[root@Centos7 mariadb-10.2.25]$ chown mysql.mysql /apps/mysql
#编译后一些准备工作
[root@Centos7 mariadb-10.2.25]# echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@Centos7 mariadb-10.2.25]# . /etc/profile.d/mysql.sh
[root@Centos7 mariadb-10.2.25]# cd /apps/mysql/
[root@Centos7 mysql]# cp support-files/my-huge.cnf /etc/my.cnf
[root@Centos7 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@Centos7 mysql]# vim /etc/my.cnf
[client]
default-character-set=utf8mb4
[mysqld]
character_set_server=utf8mb4
[root@Centos7 mysql]# scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql
3、编译php-fpm
[root@Centos7 src]# yum install libxml2-devel bzip2-devel libmcrypt-devel gcc openssl-devel -y
[root@Centos7 src]# tar xf php-7.3.15.tar.xz
[root@Centos7 src]# cd php-7.3.15/
[root@Centos7 php-7.3.15]# ./configure --prefix=/apps/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
[root@Centos7 php-7.3.15]# make && make install
#准备配置文件
[root@Centos7 php-7.3.15]# cp php.ini-production /etc/php.ini
[root@Centos7 php-7.3.15]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@Centos7 php-7.3.15]# chmod +x /etc/init.d/php-fpm
[root@Centos7 php-7.3.15]# cp /apps/php/etc/php-fpm.conf.default /apps/php/etc/php-fpm.conf
[root@Centos7 php-7.3.15]# cp /apps/php/etc/php-fpm.d/www.conf.default /apps/php/etc/php-fpm.d/www.conf
[root@Centos7 php-7.3.15]# vim /apps/php/etc/php-fpm.d/www.conf
user = nginx
group = nginx
listen = /var/run/php7-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
4、编译nginx
[root@Centos7 src]# yum install git gcc pcre-devel openssl-devel zlib-devel perl-ExtUtils-Embed -y
[root@Centos7 src]# tar xf nginx-1.16.1.tar.gz
[root@Centos7 src]# git clone https://github.com/openresty/echo-nginx-module.git
[root@Centos7 src]# cd nginx-1.16.1/
[root@Centos7 nginx-1.16.1]# groupadd -r nginx
[root@Centos7 nginx-1.16.1]# useradd -r -g nginx -s /sbin/nologin nginx
[root@Centos7 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-http_perl_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--add-module=/usr/local/src/echo-nginx-module
[root@Centos7 nginx-1.16.1]# make && make install
[root@Centos7 nginx-1.16.1]# ln -sv /apps/nginx/sbin/nginx /usr/sbin/
#安装wordpress
1、配置nginx支持fastcgi
[root@Centos7 ~]# cd /apps/nginx/
[root@Centos7 nginx]# vim conf/nginx.conf
http {
...
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
include "/apps/nginx/conf.d/*.conf";
...
}
[root@Centos7 nginx]# mkdir conf.d
[root@Centos7 nginx]# vim conf.d/www.conf
server_tokens off;
server {
listen 80;
server_name www.x.com;
root /data/php;
index index.php index.html;
access_log logs/x.com.access.log;
location ~* \.php$ {
fastcgi_pass unix:/var/run/php7-fpm.sock;;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
2、创建mysql用户
[root@Centos7 ~]# service mysqld start
[root@Centos7 ~]# mysql -e 'create database wordpress;grant all on wordpress.* to wpuser@"192.168.37.%" identified by "centos";flush privileges;'
3、安装wordpress网站
[root@Centos7 ~]# mkdir /data/php
[root@Centos7 ~]# tar -xf wordpress-5.4.1-zh_CN.tar.gz -C /data/php
[root@Centos7 ~]# cd /data/php/wordpress/
[root@Centos7 wordpress]# cp wp-config-sample.php wp-config.php
[root@Centos7 wordpress]# vim wp-config.php
define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'centos' );
define( 'DB_HOST', '192.168.37.87' );
[root@Centos7 wordpress]# mkdir wp-content/uploads
[root@Centos7 wordpress]# cp * ../
[root@Centos7 ~]# chown -R nginx.nginx /data/php/
4、服务启动
[root@Centos7 ~]# service php-fpm start
[root@Centos7 ~]# nginx
#客户端测试
http://www.x.com/
1、配置www.x.com虚拟主机
[root@Centos7 conf.d]# vim www.conf
server_tokens off;
server {
listen 80;
server_name www.x.com;
root /data/php/;
index index.php index.html;
access_log logs/x.com.access.log;
location ~* \.php$ {
fastcgi_pass unix:/var/run/php7-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
2、配置admin.x.com虚拟主机
server {
listen 80;
server_name admin.x.com;
access_log logs/admin.x.com.access.log;
location / {
rewrite ^/(.*) http://www.x.com/wp-login.php;
}
}
3、重启nginx
nginx -s reload
4、客户端测试
[root@Centos6 ~]# curl -IL admin.x.com
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Wed, 01 Jul 2020 13:22:15 GMT
Content-Type: text/html
Content-Length: 138
Connection: keep-alive
Location: http://www.x.com/wp-login.php
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 01 Jul 2020 13:22:16 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/7.3.15
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Set-Cookie: wordpress_test_cookie=WP+Cookie+check; path=/
X-Frame-Options: SAMEORIGIN