2020-06-12 第二十周作業(yè)

▲就業(yè)班和全程班的小伙伴看這里:(學(xué)習(xí)老王視頻的作業(yè)第39-40節(jié))

1、編譯安裝LNMP,并安裝wordpress

安裝準(zhǔn)備:

本次通過虛擬機(jī)的方式進(jìn)行安裝,各個(gè)軟件版本如下:

centos系統(tǒng)版本: 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

確認(rèn)關(guān)閉selinux,關(guān)閉防火墻功能。

配置好yum源、epel源,以便于安裝各個(gè)軟件的依賴包。

一、編譯安裝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 創(chuàng)建 mysql 用戶

#useradd -r -s /sbin/nologin -d /data/mysql mysql

3 建立數(shù)據(jù)庫(kù)文件夾并更改屬組

#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 安裝

解壓源碼包,并進(jìn)入解壓后的源碼包目錄

#make?

#make install

6 準(zhǔn)備環(huán)境變量

#echo 'PATH=/app/mysql/bin:$PATH' > /etc/profile.d/mysql.sh

#. /etc/profile.d/mysql.sh

7 生成數(shù)據(jù)庫(kù)文件

#cd /app/mysql/

#scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql

8 準(zhǔn)備配置文件

#cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf

9 準(zhǔn)備啟動(dòng)腳本

#cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld

10 啟動(dòng)服務(wù)

#chkconfig --add mysqld

#service mysqld start

11 建立wordpress數(shù)據(jù)庫(kù)及用戶

mysql>create database wordpress;

mysql>grant all on wordpress.* to wordpress@'192.168.37.%' identified by 'centos';

二、編譯安裝nginx:

1)安裝相關(guān)的包

#yum install -y gcc pcre-devel openssl-devel zlib-devel

2)創(chuàng)建賬號(hào)并編譯安裝

# 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環(huán)境

#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 設(shè)置 hosts 文件,使域名可以解析到主機(jī),在 hosts 文件中添加一行(如果利用Linux圖形桌面上的瀏覽器進(jìn)行網(wǎng)站安裝,hosts文件為 /etc/hosts,如果是用windows安裝,則host文件 路徑為 C:\Windows\System32\drivers\etc)

  192.168.37.7 blog.wordpress.com

?6.2 利用瀏覽器進(jìn)行安裝,輸出域名blog.wordpress.com,根據(jù)安裝向?qū)О惭b


2、配置虛擬主機(jī),www.x.com域名實(shí)現(xiàn)首頁訪問,admin.x.com域名實(shí)現(xiàn)wordpress的后臺(tái)訪問。

(1)?將 www.x.com?與?admin.x.com?域名配置在hosts 文件中

192.168.37.7www.x.com admin.x.com

(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的配置文件

# 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;

? ? }

? ? #添加重寫規(guī)則,用前臺(tái)域名訪問后臺(tái)時(shí),跳轉(zhuǎn)到后臺(tái)域名訪問

? ? 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;

? ? ? ? }

? ? }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容