一爬虱、編譯安裝LNMP,并安裝wordpress
主機(jī): 一臺(tái)(192.168.17.7)窝革,系統(tǒng)為CentOS7.6
軟件包:nginx-1.16.1.tar.gz姻蚓,mariadb-10.2.25.tar.gz,php-7.3.12.tar.bz2堆生,wordpress-5.2.2.tar.gz
1专缠、Ngnix的編譯安裝
(1) 安裝相關(guān)依賴包
[root@centos7 data]# yum install-y gcc pcre-devel openssl-devel zlib-devel
(2)解壓源碼包,創(chuàng)建nginx用戶顽频,開(kāi)始編譯安裝
[root@centos7 data]# tar -zxvf nginx-1.16.1.tar.gz
[root@centos7 data]# useradd -r -s /sbin/nologin nginx
[root@centos7 data]# cd nginx-1.16.1/
[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-pcre \
> --with-stream \
> --with-stream_ssl_module \
> --with-stream_realip_module
[root@centos7 nginx-1.16.1]# make && make install
(3)啟動(dòng)nginx服務(wù)
[root@centos7 nginx-1.16.1]# /apps/nginx/sbin/nginx
[root@centos7 nginx-1.16.1]# ss -nlt | grep 80
LISTEN? ? 0? ? ? 128? ? ? ? ? *:80? ? ? ? ? ? ? ? ? ? ? *:*?
2藤肢、Mariadb的編譯安裝
(1) 解壓源碼包,創(chuàng)建mysql用戶和數(shù)據(jù)目錄
[root@centos7 ~]# cd /data
[root@centos7 data]# tar -zxvf mariadb-10.2.25.tar.gz
[root@centos7 data]# useradd -r -s /sbin/nologin -d /data/mysql mysql
[root@centos7 data]# mkdir /data/mysql
[root@centos7 data]# chown root:mysql /data/mysql
(2) 安裝相關(guān)依賴包
[root@centos7 data]# yum install -y 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
(3) 編譯安裝mariadb
[root@centos7 data]# 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=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci
[root@centos7 mariadb-10.2.25]# make && make install
(4) 配置環(huán)境變量糯景,初始化數(shù)據(jù)庫(kù)嘁圈,生成數(shù)據(jù)庫(kù)文件
[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]# scripts/mysql_install_db --datadir=/data/mysql --user=mysql
(5) 準(zhǔn)備配置文件與啟動(dòng)腳本
[root@centos7 mysql]# cp /apps/mysql/support-files/my-huge.cnf /etc/my.cnf
[root@centos7 mysql]# cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld
(6) 啟動(dòng)服務(wù)
[root@centos7 mysql]# chkconfig --add mysqld
[root@centos7 mysql]# service mysqld start
Starting mysqld (via systemctl):? ? ? ? ? ? ? ? ? ? ? ? ? [? OK? ]
[root@centos7 mysql]# ss -ntlp | grep 3306
LISTEN? ? 0? ? ? 80? ? ? ? ? :::3306? ? ? ? ? ? ? ? ? ? :::*? ? ? ? ? ? ? ? ? users:(("mysqld",pid=22869,fd=21))
3省骂、php-fpm的編譯安裝
1) 安裝相關(guān)依賴包
[root@centos7 mysql]# yum install-y libxml2-devel bzip2-devel libmcrypt-devel
(2) 解壓源碼包,然后進(jìn)行編譯安裝
[root@centos7 data]# tar -jxvf php-7.3.12.tar.bz2
[root@centos7 php-7.3.12]# ./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.12]# make && make install
編譯代碼
[root@centos7 php-7.3.12]# make && make install
./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
(3) 準(zhǔn)備配置文件最住,并修改?www.conf?配置文件中啟動(dòng)用戶與組為 nginx钞澳,默認(rèn)用戶與組為 nobody
[root@centos7 php-7.3.12]# cp php.ini-production /etc/php.ini
[root@centos7 php-7.3.12]# cd /apps/php/etc/
[root@centos7 etc]# cp php-fpm.conf.default php-fpm.conf
[root@centos7 etc]# cd php-fpm.d/
[root@centos7 php-fpm.d]# cp www.conf.default www.conf
[root@centos7 php-fpm.d]# vim www.conf
#找到以下兩項(xiàng),將nobody改為nginx
user = nginx
group = nginx
(4) 準(zhǔn)備服務(wù)啟動(dòng)腳本涨缚,并啟動(dòng) php-fpm 服務(wù)
[root@centos7 php-fpm.d]# cd /data/php-7.3.12/
[root@centos7 php-7.3.12]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@centos7 php-7.3.12]# chmod +x /etc/init.d/php-fpm
[root@centos7 php-7.3.12]# chkconfig --add php-fpm
[root@centos7 php-7.3.12]# service php-fpm start
Starting php-fpm? done
[root@centos7 php-7.3.12]# ss -nlt | grep 9000
LISTEN? ? 0? ? ? 128? ? 127.0.0.1:9000? ? ? ? ? ? ? ? ? ? *:*
4轧粟、wordpress的安裝
(1) 在數(shù)據(jù)庫(kù)中創(chuàng)建庫(kù)和授權(quán)用戶
[root@centos7 ~]# mysql
Welcome to the MariaDB monitor.? Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.2.25-MariaDB-log Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE wordpress charset 'utf8';
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON wordpress.* to 'wpuser'@'192.168.17.%' IDENTIFIED BY 'centos';
Query OK, 0 rows affected (0.00 sec)
(2) 解壓wordpress程序包到 /apps/nginx/html/ 目錄,并在源碼目錄給 nginx 用戶設(shè)置訪問(wèn)控制權(quán)限
[root@centos7 ~]# cd /
[root@centos7 data]# tar -xf wordpress-5.2.2.tar.gz -C /apps/nginx/html
[root@centos7 data]# setfacl -Rm u:nginx:rwx /apps/nginx/html/wordpress
(3) 修改nginx的虛擬主機(jī)配置文件脓魏,并重啟nginx服務(wù)
root@centos7 ~]# vim /apps/nginx/conf/nginx.conf
#在http{}段中添加以下內(nèi)容
? ? 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;
? ? ? ? }
? ? }
[root@centos7 ~]# /apps/nginx/sbin/nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@centos7 ~]# /apps/nginx/sbin/nginx -s reload
(4) 設(shè)置 hosts 文件兰吟,使域名可以解析到主機(jī),在 hosts 文件中添加一行(如果利用Linux圖形桌面上的瀏覽器進(jìn)行網(wǎng)站安裝茂翔,hosts文件為 /etc/hosts混蔼,如果是用windows安裝,則host文件 路徑為 C:\Windows\System32\drivers\etc)
192.168.17.7 blog.wordpress.com
(5) 利用瀏覽器進(jìn)行安裝珊燎,輸出域名blog.wordpress.com惭嚣,根據(jù)安裝向?qū)О惭b
二、配置虛擬主機(jī)悔政,www.x.com域名實(shí)現(xiàn)首頁(yè)訪問(wèn)
admin.x.com域名實(shí)現(xiàn)wordpress的后臺(tái)訪問(wèn)
(2) 登錄wordpress后臺(tái)晚吞,在Settings --》General Settings 中,將 WordPress Address (URL) 改為后臺(tái)地址admin.x.com谋国,Site Address (URL) 改為前臺(tái)地址www.x.com
(3) 修改nginx的配置文件槽地,在http{}中添加以下內(nèi)容
server {
? ? listen 80;
? ? server_name www.x.com;
? ? location / {
? ? ? ? root html/wordpress;
? ? ? ? index index.php index.html index.htm;
? ? }
? ? #添加重寫(xiě)規(guī)則,用前臺(tái)域名訪問(wèn)后臺(tái)時(shí)烹卒,跳轉(zhuǎn)到后臺(tái)域名訪問(wèn)
? ? 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;
? ? ? ? }
? ? }