用戶經過瀏覽器輸入域名請求nginx web服務,若是請求時靜態資源,則由nginx解析返回給用戶;若是是動態請求(.php結尾),那麼nginx就會把它經過FastCGI接口(生產經常使用方法)發送給PHP引擎服務(FastCGI進程php-fpm)進行解析,若是這個動態請求要讀取數據庫數據,那麼,PHP就會繼續向後請求MYSQL數據庫,以讀取須要的數據,並最終經過Nginx服務把獲取的數據返回給用戶,這就是LNMP環境的基本請求順序流程php
MYSQL是一種關係形數據庫管理軟件,關係型數據庫的特色是將數據保存在不一樣的二維表中,而且將這些表放入不一樣的數據庫中,而不是把全部數據統一放在一個大倉庫裏,這樣的設計增長了MYSQL的讀取速度,靈活性和可管理性也獲得了很大提升。html
1. 爲何選擇MYSQL數據庫mysql
2. 安裝MYSQL數據庫linux
當前使用最爲普遍是MYSQL5.5系列版本的數據庫,MYSQL安裝方式比較在nginx web服務應用咱們已經說過
下面咱們直接經過二進制文件安裝nginx
包源
http://mirrors.sohu.com/ 可經過搜狐源站下載對應包 http://dev.mysql.com mysql下載官網 安裝 [root@Poppy mysql]# useradd -s /sbin/nologin mysql -M # 建立啓動mysql的用戶 [root@Poppy tools]# wget dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz # 下載二進制文件 [root@Poppy tools]# tar -xf mysql-5.5.49-linux2.6-x86_64.tar.gz # 解壓縮文件 [root@Poppy tools]# mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49 # 將解壓出來的目錄移動到咱們的程序目錄下 [root@Poppy tools]# ln -s /application/mysql-5.5.49/ /application/mysql # 作個連接 [root@Poppy tools]# cd /application/mysql # 切換到連接的目錄下 [root@Poppy mysql]# chown -R mysql.mysql /application/mysql/ # 將連接的目錄屬主屬組更替成啓動mysql的用戶 [root@Poppy mysql]# yum install libaio # 安裝缺省庫文件 [root@Poppy mysql]# ./scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql Installing MySQL system tables... # 初始化數據庫 180610 22:58:07 [Note] /application/mysql//bin/mysqld (mysqld 5.5.49) starting as process 10106 ... OK Filling help tables... 180610 22:58:07 [Note] /application/mysql//bin/mysqld (mysqld 5.5.49) starting as process 10113 ... OK --basedir=/application/mysql/ # 安裝的根 --datadir=/application/mysql/data/ # 放數據的 [root@Poppy mysql]# ls data/ # 驗證默認庫是否建立 mysql performance_schema 內部管理的庫 test
配置並啓動MYSQl數據庫程序員
經過守護進程控制服務的啓動 [root@Poppy support-files]# sed -i 's#/usr/local/#/application/#g' mysql.server # 默認安裝路徑是/usr/local/因此咱們替換成咱們的目錄 [root@Poppy support-files]# cp -rf my-small.cnf /etc/my.cnf # 生成配置文件 [root@Poppy support-files]# cp -a mysql.server /etc/init.d/mysqld cp: overwrite ‘/etc/init.d/mysqld’? y # 複製到守護進程下,控制啓停 [root@Poppy support-files]# chmod +x /etc/init.d/mysqld [root@Poppy support-files]# /etc/init.d/mysqld stop Shutting down MySQL. [ OK ] [root@Poppy support-files]# /etc/init.d/mysqld start Starting MySQL.. 這是啓動mysql規範的方式之一,還可使用 [root@Poppy bin]# cd bin [root@Poppy bin]# sed -i 's#/usr/local/#/application/#g' mysqld_safe [root@Poppy mysql]# cp support-files/my-small.cnf /etc/my.cnf # 生成配置文件 [root@Poppy mysql]# /application/mysql/bin/mysqld_safe --user=mysql 180610 23:35:05 mysqld_safe Logging to '/application/mysql/data/Poppy.err'. 180610 23:35:06 mysqld_safe Starting mysqld daemon with databases from /application/mysql/data 經過netstat -ntlp可查看端口是否開啓
登陸到MYSQLweb
絕對路徑方式登陸 [root@Poppy mysql]# /application/mysql/bin/mysql 登陸命令加載 [root@Poppy mysql]# echo "PATH='/application/mysql/bin/:$PATH'" >> /etc/profile [root@Poppy mysql]# . /etc/profile # 中間有個空格 [root@Poppy mysql]# echo $PATH # 按順序加載命令,若是是rpm,yum優先級會在前面 /application/mysql/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@Poppy mysql]# mysql
MYSQL設置密碼redis
mysql -uroot -p 沒有密碼直接回車 設置密碼 [root@Poppy ~]# mysqladmin -u root password 'joker123' 更改密碼 [root@Poppy ~]# mysqladmin -uroot -pjoker123 password '123456' 若是是遠程主機加入-h參數
附贈安裝腳本算法
useradd -s /sbin/nologin mysql -M wget dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz tar -xf mysql-5.5.49-linux2.6-x86_64.tar.gz mkdir -p /application mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49/ ln -s /application/mysql-5.5.49/ /application/mysql cd /application/mysql chown -R mysql.mysql /application/mysql/ yum install -y libaio ./scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql cd support-files/ cp -rf my-small.cnf /etc/my.cnf sed -i 's#/usr/local/#/application/#g' mysql.server cp -amysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld /etc/init.d/mysqld start echo "PATH='/application/mysql/bin/:$PATH'" >> /etc/profile . /etc/profile mysqladmin -u root password 'joker123'
忘記登陸密碼解決方法sql
# 修改配置文件my.cnf [mysqld] skip-grant-tables ' # 登陸mysql就不須要密碼了 mysql> UPDATE mysql.user SET Password = password ( ‘123456’ ) WHERE User = ‘root’; mysql>flush privileges;
1. FastCGI產生
CGI的全稱爲「通用網關接口」,爲HTTP服務器與其餘機器上的程序服務通訊交流一種工具,CGI程序須運行在網絡服務器上
傳統CGI接口方式的主要缺點是性能較差,由於每次HTTP服務器遇到動態程序時都須要經過從新啓動解析器來執行解析,以後結果纔會被返回給HTTP服務器。這就在處理高併發訪問時幾乎是不可用的,所以就誕生了FastCGI。另外,傳統的CGI接口方式安全性也不好,故而如今已經不多被使用了
2. 什麼是FastCGI
3. FastCGI運行原理
nginx不支持對外部動態程序的直接調用或者解析,全部的外部程序(包括PHP)必須經過FastCGI接口來調用。FastCGI接口在linux下是socket,爲了調用CGI程序,還須要一個FastCGI的wrapper(能夠理解爲用於啓動另外一個程序的程序),這個wrapper綁定在某個固定的socket上,如端口或文件socket。當nginx將CGI請求發送給這個socket時候,經過FastCGI接口,wrapper接收到消息,而後派生出一個新的線程,這個線程調用解釋器或外部程序處理腳原本讀取返回的數據;接着,wrapper再將返回的數據經過FastCGI接口,沿着固定的socket傳遞給nginx;最後,nginx將返回的數據發送給客戶端。
FastCGI的主要優勢是把動態語言和HTTP服務器分離開來,使nginx專門處理靜態請求及向後轉發的動態請求,而PHP服務器則專門解析PHP請求。
1. 安裝前準備
第一點:mysql,nginx
mysql|nginx 正常啓動工做
第二點:檢查安裝PHP所需的lib庫
PHP程序在開發及運行時會調用一些諸如zlib,gd等函數庫,所以須要確認lib庫是否已經安裝
[root@Poppy ~]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel libjpeg-turbo-devel-1.2.90-5.el7.x86_64 zlib-devel-1.2.7-17.el7.x86_64 libxml2-devel-2.9.1-6.el7_2.3.x86_64 libiconv-devel 沒有安裝成功,由於默認yum源沒有此包 [root@Poppy ~]# rpm -qa freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libcurl-devel-7.29.0-46.el7.x86_64 freetype-devel-2.4.11-15.el7.x86_64 libpng-devel-1.5.13-7.el7_2.x86_64 libxslt-devel-1.1.28-5.el7.x86_64 gd-devel-2.0.35-26.el7.x86_64 其中:libjpeg-turbo-devel是早期的libjpeg-devel的新名字,libcurl-devel是早期curl-devel的新名字 提示:庫文件通常安裝 *-devel包,就會把*安裝,例如安裝gd-devel,就會把gd安裝 這些lib不是必須安裝,可是目前企業環境下通常都須要安裝的,不然,php程序運行時會出現問題,例如驗證碼 yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel 咱們經過編譯安裝上面沒有安裝成功的庫libiconv-devel [root@Poppy tools]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz [root@Poppy tools]# tar -zxf libiconv-1.14.tar.gz [root@Poppy tools]# cd libiconv-1.14 [root@Poppy tools]# ./configure --prefix=/application/libiconv-1.14/ [root@Poppy tools]# make && make install [root@Poppy tools]# ln -s /application/libiconv-1.14/ /application/libiconv [root@Poppy tools]# rm -fr libiconv-1.14 報錯: In file included from progname.c:26:0: ./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); ^ make[2]: *** [progname.o] Error 1 make[2]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib' make[1]: *** [all] Error 2 make[1]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib' make: *** [all] Error 2 解決: [root@Poppy tools]# vi srclib/stdio.in.h 找到698行,_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");*/ 替換成 #if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); #endif #endif ......便可 安裝libmcrypt庫 這是一個使用動態加載模塊化的libmcrypt,libmcrypt對於在程序運行時添加/移除算法是有用的,libmcrypt目前再也不被官方支持,其軟件地址爲http://mcrypt.hellug.gr/lib/,編譯PHP的過程當中,libmcrypt庫不是必需要安裝的包 Centos默認的yum源裏面沒有libmcrypt-devel,所以須要事先配置epel第三方yum源 [root@Poppy ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo [root@Poppy ~]# yum -y install libmcrypt-devel 安裝mhash加密擴展庫 mhash是基於離散數據原理不可逆向的PHP加密方式擴展庫,其在默認狀況下不會開啓。mhash能夠用於建立校驗數值,消息摘要,消息認證碼,以及無需原文的關鍵信息保存(如密碼)等。它爲PHP提供了多種散列算法,如MD5,SHA1,GOST等,能夠經過MHASH_hashname()查看其支持的算法有哪些 須要注意的是: 1. 該擴展不能提供最新的散列算法 2. 該擴展結果原則上運算不可逆 [root@Poppy ~]# yum -y install libmcrypt-devel 安裝mcrypt加密擴展庫 PHP程序員在編寫代碼程序時,除了要保證代碼的高性能以外,還有一點是很是重要的,那就是程序的安全性保障,PHP除了自帶的幾種加密函數外,還有功能更全面的PHP加密擴展庫mcrypt和mhash 其中,mcrypt擴展庫能夠實現加密解密功能,就是既能將明文加密,也能夠將密文還原 能夠說,mcrypt是PHP裏面重要的加密支持擴展庫,該庫默認狀況下不開啓 mcrypt庫支持20多種加密算法和8種加密模式,具體能夠經過函數mcrypt_list_algorithms()和mcrypt_list_modes()來顯示 [root@Poppy ~]# yum install mcrypt [root@Poppy ~]# rpm -qa libmcrypt-devel mhash mcrypt mcrypt-2.6.8-11.el7.x86_64 mhash-0.9.9.9-10.el7.x86_64 libmcrypt-devel-2.5.8-13.el7.x86_64
2. 開始安裝 PHP(FastCGI方式)服務
經過搜狐的源站,選取軟件包 http://mirrors.sohu.com/ 選取php-5.5.32.tar.gz,右鍵複製連接地址 [root@Poppy tools]# wget http://mirrors.sohu.com/php/php-5.5.32.tar.gz [root@Poppy tools]# tar -xf php-5.5.32.tar.gz [root@Poppy tools]# cd /php-5.5.32 [root@Poppy tools]# ./configure --prefix=/application/php-5.5.32/ --with-mysql=/application/mysql/ --with-iconv-dir=/application/libiconv/ --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr/ --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=www --with-fpm-group=www --enable-ftp [root@Poppy tools]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/ [root@Poppy tools]# cd php-5.5.32 [root@Poppy tools]# touch ext/phar/phar.phar 錯誤事例1: error while loading shared libraries;libmysqlclient.so.18;cannot open shared object file;no such file or directory make;***[ext/phar/phar.php]error 127 報錯緣由,這個緣由是很常見的,即PHP找不到指定的庫,通常是相應庫的路徑不對致使的 解決方法 [root@Poppy tools]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/ 錯誤事例2: chmod:cannot access 'ext/phar/phar.phar':no such file or directory make:[ext/phar/phar.phar]error 1 (ignored) 報錯緣由,上述報錯提示是不能訪問xt/phar/phar.phar這個文件或者目錄 若是編譯時使用--with-mysql=mysqlnd替代--with-mysql=/application/mysql/,就不會出現上面錯誤事例 [root@Poppy tools]# make Build complete. Don't forget to run 'make test'. [root@Poppy php-5.5.32]# make install [root@Poppy application]# php/bin/php -v PHP 5.5.32 (cli) (built: Jun 11 2018 18:58:39) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
附贈經過yum安裝php56w
默認的yum源沒有此包信息,咱們須要第三方源 [root@jokerpro ~]# cat /etc/yum.repos.d/webtatic.repo [webtatic] name=Webtatic Repository EL6 - $basearch #baseurl=https://repo.webtatic.com/yum/el6/$basearch/ mirrorlist=https://mirror.webtatic.com/yum/el7/$basearch/mirrorlist failovermethod=priority enabled=1 gpgcheck=0
檢驗有沒有該包
yum list |grep php56 安裝
yum -y install php56w.x86_64 php56w-mbstring.x86_64 php56w-xml.x86_64 php56w-pdo.x86_64 php56w-mssql.x86_64 php56w-fpm.x86_64 php56w-pear.noarch php56w-pecl-redis.x86_64 php56w-common.x86_64 php56w-bcmath.x86_64 php56w-mysql.x86_64 php56w-process.x86_64 php56w-pecl-igbinary.x86_64 php56w-opcache.x86_64
查看安裝成功否,和安裝位置 rpm -qa ql
3. 配置PHP引擎配置文件php.ini
配置文件存儲在解壓出來的目錄裏面,模版的配置文件有開發模版,生產模版二個版本,開發環境的模版更多的是開啓日誌,調試信息,而生產環境都是關閉狀態 [root@Poppy php-5.5.32]# cp php.ini-production /application/php/lib/php.ini [root@Poppy php-5.5.32]# cd /application/php/etc [root@Poppy etc]# cp php-fpm.conf.default php-fpm.conf 啓動PHP服務(FastCGI) [root@Poppy etc]# /application/php/sbin/php-fpm 檢查啓動 [root@Poppy etc]# netstat -ntlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 8521/php-fpm: maste [root@Poppy etc]# ps -ef|grep php-fpm root 8521 1 0 23:51 ? 00:00:00 php-fpm: master process (/application/php-5.5.32/etc/php-fpm.conf) www 8522 8521 0 23:51 ? 00:00:00 php-fpm: pool www www 8523 8521 0 23:51 ? 00:00:00 php-fpm: pool www 默認一個主進程,二個子進程
1. 配置nginx支持PHP程序請求訪問,經過nginx請求訪問PHP
nginx主配置文件 [root@Poppy conf]# cat nginx.conf worker_processes 1; events { worker_connections 1024; } # 關鍵字,日誌文件,錯誤日誌級別 error_log logs/error.log error; http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; # 訪問日誌,main就是讀http裏面的main日誌變量 # access_log logs/www_access.log main; include extra/*.conf; } [root@Poppy conf]# cat extra/blog.conf server { listen 80; server_name blog.joker.com; location / { root html/blog; index index.html index.htm; } location ~ .*\.(php|php5)?$ { root html/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } } 建立php測試文件 [root@Poppy blog]# cat test_info.php <?php phpinfo(); ?> 客戶端訪問 [root@joker ~]# curl blog.joker.com blog [root@joker ~]# curl blog.joker.com/test_info.php
2. PHP連接MYSQL的狀況進行測試
[root@Poppy blog]# cat test_mysql.php <?php $link_id=mysql_connect('localhost','root','123456') or mysql_error(); if($link_id){ echo "mysql successful by root"; }else{ echo mysql_error(); } // 這是單行註釋 /* 這是多行註釋 */ ?> 客戶端訪問 [root@joker ~]# curl blog.joker.com/test_mysql.php mysql successful by root
WordPress是一套利用PHP語言和MySQL數據庫開發的開源免費的blog(博客,網站)程序,用戶能夠在支持PHP環境和MySQL數據庫的服務器上創建blog站點,它的功能很是強大,擁有衆多插件,易於擴充功能。
1. MySQL數據庫配置準備
[root@Poppy blog]# mysql -uroot -p mysql> drop database test; # 清除無用的庫 mysql> select user(); # 查看當前用戶 mysql> create database wordpress;# 建立wordpress庫 mysql> select user,host from mysql.user; # 查看用戶,地址 mysql> grant all on *.* to wordpress@'localhost' identified by '123456'; # 受權帳號權限登陸 mysql> drop user wordpress@'localhost'; mysql> grant all on wordpress.* to wordpress@'localhost' identified by '123456'; mysql> show grants for wordpress@'localhost'; mysql> flush privileges; # 刷新
2. nginx及PHP環境配置準備
wordpress軟件包默認首頁就是index.php
[root@Poppy extra]# cat blog.conf server { listen 80; server_name blog.joker.com 能夠是ip; location / { root html/blog; index index.php index.html index.htm; } location ~ .*\.(php|php5)?$ { root html/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } }
3. 獲取wordpress程序
https://cn.wordpress.org/
https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
4. 開始安裝wordpress程序
[root@Poppy tools]# tar -xf wordpress-4.9.4-zh_CN.tar.gz [root@Poppy tools]# cp -a wordpress/* /application/nginx/html/blog/ [root@Poppy tools]# chown -R www.www /application/nginx/html/blog/ [root@Poppy extra]# mysql -uwordpress -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | wordpress | +--------------------+ 2 rows in set (0.00 sec) mysql> use wordpress; Database changed mysql> show tables; Empty set (0.00 sec) 瀏覽器訪問ip,就會出現一個數據庫鏈接信息,按照以前咱們建立的庫,帳號填寫,點擊繼續,就會多出一個wp-config.php文件,存數據庫鏈接信息,站點目錄必須有權限,www [root@Poppy blog]# ls wp-config.php wp-config.php [root@Poppy blog]# pwd /application/nginx/html/blog [root@Poppy blog]# ls wp-config.php wp-config.php 點擊繼續安裝,到歡迎頁面,填寫博客標題,用戶名,密碼等 點擊安裝wordpress,頁面提示成功,此時數據庫就會多了不少表,點擊登陸就會跳轉到博客登陸頁面
5. 靜態化
咱們訪問http://博客ip/?p=7,?p=7是動態化的數據,咱們須要給它靜態化,顯示成這樣。http://博客ip/archives/7.html
實現此功能時,首先要在wordpress後臺依次單擊settings-固定連接-自定義結構,而後輸入以下代碼/archives/%post_id%.html,保存,接着在nginx配置文件的server容器中添加下面的代碼
[root@Poppy extra]# cat ../nginx.conf worker_processes 1; events { worker_connections 1024; } # 關鍵字,日誌文件,錯誤日誌級別 error_log logs/error.log error; http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; # 訪問日誌,main就是讀http裏面的main日誌變量 # access_log logs/www_access.log main; include extra/*.conf; } [root@Poppy extra]# cat blog.conf server { listen 80; server_name blog.joker.com ip; location / { root html/blog; index index.php index.html index.htm; if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (!-f $request_filename){ rewrite (.*) /index.php; } } location ~ .*\.(php|php5)?$ { root html/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } }
[root@Poppy extra]# /application/nginx/sbin/nginx -s reload
咱們將咱們搭建好的博客進行拆分,數據庫使用遠程服務器,編寫文章上傳圖片到nfs
mysql更改和php連接mysql更改以下
原數據庫數據 [root@Poppy tools]# mysqldump -uroot -p123456 wordpress -B|gzip>wordpress.sql.gz 備份wordpress數據庫,若是是-A則表明全部庫 [root@Poppy tools]# scp wordpress.sql.gz root@遠程數據庫服務器:/tmp 遠程數據庫 [root@joker tmp]# gzip -d wordpress.sql.gz [root@joker tmp]# mysqladmin -uroot -password 123456 [root@joker tmp]# mysql -uroot -p123456 < wordpress.sql [root@joker tmp]# mysql -uroot -p123456 -e "show databases like 'wordpress'" [root@joker tmp]# mysql -uroot -p123456 -e "use wordpress;show tables" 數據庫受權登陸權限 mysql> grant all on wordpress.* to wordpress@'%' identified by '123456'; mysql> flush privileges; 更改wp-config.php裏面的數據庫鏈接 [root@Poppy blog]# pwd /application/nginx/html/blog [root@Poppy blog]# cat wp-config.php // ** MySQL 設置 - 具體信息來自您正在使用的主機 ** // /** WordPress數據庫的名稱 */ define('DB_NAME', 'wordpress'); /** MySQL數據庫用戶名 */ define('DB_USER', 'wordpress'); /** MySQL數據庫密碼 */ define('DB_PASSWORD', '123456'); /** MySQL主機 */ define('DB_HOST', '遠程數據庫ip地址'); # 修改這裏 /** 建立數據表時默認的文字編碼 */ define('DB_CHARSET', 'utf8mb4'); /** 數據庫整理類型。如不肯定請勿更改 */ define('DB_COLLATE', '');
nfs搭建配置
發表文章,插入圖片,咱們點擊圖片的地址是以下這個位置 http://ip/wp-content/uploads/2018/06/111.jpg 咱們能夠經過nfs來替代這個路徑 咱們先安裝nfs服務器 [root@Poppy ~]# yum install rpcbind nfs-utils [root@joker ~]# cat /etc/exports # share /nfsbackup by joker for poppy at today /nfsbackup nfs客戶端ip(rw,sync,all_squash,anonuid=1006,anongid=1006) # 開啓帳號映射,將遠程連接的用戶映射到本地用戶 [root@joker ~]# id www uid=1006(www) gid=1006(www) groups=1006(www) [root@joker ~]# ls -ld /nfsbackup/ drwxr-xr-x 3 www www 4096 Jun 12 18:01 /nfsbackup/ [root@joker ~]# systemctl start nfs.service [root@joker ~]# showmount -e 127.0.0.1 Export list for 127.0.0.1: /nfsbackup nfs客戶端ip 客戶端,也就是咱們以前lnmp一臺上的 [root@Poppy ~]# yum install rpcbind nfs-utils [root@Poppy ~]# systemctl start rpcbind.service [root@Poppy uploads]# pwd /application/nginx/html/blog/wp-content/uploads [root@Poppy uploads]# ls -ld /application/nginx/html/blog/wp-content/uploads/ drwxr-xr-x 3 1006 1006 4096 Jun 12 18:01 /application/nginx/html/blog/wp-content/uploads/ [root@Poppy uploads]# mv 2018/ /tmp [root@Poppy uploads]# mount -t nfs nfs服務器ip/nfsbackup /application/nginx/html/blog/wp-content/uploads/ [root@Poppy uploads]# mv /tmp/2018 ./ [root@Poppy uploads]# 空的也不要緊,當咱們建立文章添加圖片了自動會生成 [root@Poppy uploads]# ls 2018/06/111 111-100x100.jpg 111-150x150.jpg 111-300x93.jpg 111.jpg