基于LNMP搭建wordpress個人主頁

N23,

操作系統:Centos7.4

數據庫:Mariadb5.5

php版本:php-fpm

搭建Nginx服務

準備工作

1、關閉防火墻及selinux

[root@Nginx ~]# systemctl disable firewall

[root@Nginx ~]# systemctl stop firewall

[root@Nginx ~]#sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

2、安裝開發組件(yum源安裝)

[root@Mariadb ~]# yum grouplist
        Loaded plugins: fastestmirror
        Available Environment Groups:
           Minimal Install
           Compute Node
           Infrastructure Server
           File and Print Server
           Basic Web Server
           Virtualization Host
           Server with GUI
           GNOME Desktop
           KDE Plasma Workspaces
           Development and Creative Workstation
        Available Groups:
           Compatibility Libraries
           Console Internet Tools
           Development Tools
           Graphical Administration Tools
           Legacy UNIX Compatibility
           Scientific Support
           Security Tools
           Smart Card Support
           System Administration Tools
           System Management
        Done

[root@Nginx ~]#yum groupinstall -y 'Development tools'

3、下載Nginx安裝包

這里是Nginx官方下載頁面download_links,本次安裝Nginx1.8穩定版

[root@Nginx ~]#tar -zxvf nginx-1.8.1.tar.gz

4、編譯安裝 編譯之前需要安裝一些依賴包,否則編譯過程會報錯:

[root@Nginx nginx-1.8.1]# yum install -y gd pcre-devel openssl-devel zlib-devel
[root@Nginx nginx-1.8.1]# ./configure \
    --prefix=/usr/local/nginx1.8 \
    --conf-path=/etc/nginx.conf \
    --error-log-path=/var/log/nginx/nginx.log \
    --pid-path=/var/run/nginx.pid \
    --user=nginx \
    --group=nginx \
    --with-http_ssl_module \
    --with-http_image_filter_module \
    --with-http_gzip_static_module \
    --with-http_auth_request_module

配置環境變量,并加載配置文件啟動服務

[root@Nginx nginx-1.8.1]#export PATH=/usr/local/nginx1.8/sbin:$PATH
[root@Nginx ~]# nginx -c /etc/nginx.conf    /*指定加載配置文件,否則會報錯
[root@Nginx ~]# nginx -t
nginx: the configuration file /etc/nginx.conf syntax is ok
nginx: configuration file /etc/nginx.conf test is successful
[root@Nginx ~]#nginx -s reopen

5、訪問測試頁

http://SERVERIP/index.html

安裝PHP-FPM服務

因為Nginx本身直接僅支持FastCGI,所以,相應的php調用需要php-fpm

1、安裝php-fpm(配置本地yum源安裝)

[root@Nginx nginx-1.8.1]#yum install php-fpm
[root@Nginx nginx-1.8.1]#systemctl start php-fpm.service

本次實驗將php-fpm與Nginx安裝在同一臺服務器上,故需要修改配置;

2、下面我們進行測試配置

配置nginx支持FastCGI(參照以下內容),將.php模塊的#號去掉

[root@Nginx ~]#vi /etc/nginx.conf
     server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.php index.html index.htm;      /*添加index.php
        }
        location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx1.8/html/$fastcgi_script_name;
        include        fastcgi_params;
        }
        location /favicon.ico {
         root html;
        }
    }

其中fastcgi_param為php文件所在的絕對路徑

在html路徑下新建一個index.php測試頁內容如下:

[root@Nginx ~]#cd /usr/local/nginx1.8/html
[root@localhost html]#vi index.php
        <?php
            phpinfo();
        ?>
[root@Nginx ~]#systemctl restart php-fpm
[root@Nginx ~]#nginx -s reload

3、打開php測試頁,便可看到phpinfo()測試頁

http://$SERVERIP/index.php

安裝Mariadb數據庫

[本次安裝僅適用yum源安裝]Mariadb官方的安裝已經給的很全了,已經有針對systemd的編譯的完整包,可直接下載使用

[root@Nginx ~]#yum install mariadb-server
[root@Nginx ~]#systemctl start mariadb.service
[root@Nginx ~]#mysql -uroot
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> alter user set password=password('xxxxx') where User='root';  /*設置root密碼
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> grant all privileges on mysql.* to 'root'@'%';         /*root用戶賦權,可以從任意主機遠程訪問數據庫,當數據庫與web服務器不在同一臺主機時有效
MariaDB [mysql]> flush privileges;

更改root密碼也可以使用命令mysqladmin實現

[root@Nginx ~]#mysqladmin -u root -p password xxxxxxx

測試php是否可以訪問數據庫

[root@Nginx ~]#vim /usr/local/nginx1.8/html/index.php
    <?php
        $link=mysql_connect('localhost','root','xxxxxx');
        if ($link)
            echo 'mysql is running!';
        else
            echo 'mysql isn't connected!';
    ?>
[root@Nginx ~]#nginx -s reload

瀏覽器打開 http://$SERVERIP/index.php

部署wordpress

1、Wordpress官方下載最新版本linux安裝包WordPress4.8

    [root@Nginx ~]#tar -zxvf wordpress4.8.2.tar.gz
    [root@Nginx ~]#mv wordpress4.8.2/* /usr/local/nginx1.8/html/
    [root@Nginx ~]#cd /usr/local/nginx1.8/html/
    [root@Nginx html]#cp wp-config-sample.php wp-config.php
    [root@Nginx html]#vi wp-config.php
        // ** MySQL 設置 - 具體信息來自您正在使用的主機 ** //
        /** WordPress數據庫的名稱 */
        define('DB_NAME', 'mysql');

        /** MySQL數據庫用戶名 */
        define('DB_USER', 'root');

        /** MySQL數據庫密碼 */
        define('DB_PASSWORD', '$MYSQLPASSWORD');

        /** MySQL主機 */
        define('DB_HOST', '$DATABASEIP');

        /** 創建數據表時默認的文字編碼 */
        define('DB_CHARSET', 'utf8');

        /** 數據庫整理類型。如不確定請勿更改 */
        define('DB_COLLATE', '');
        ……
        ……
        ……
        /* 如果沒有ftp服務器的話,需要在配置文件添加如下代碼,以保證安裝主題時會提示先登陸ftp服務器
        define('WP_TEMP_DIR', ABSPATH.'wp-content/tmp');
        define("FS_METHOD", "direct");
        define("FS_CHMOD_DIR", 0777);
        define("FS_CHMOD_FILE", 0777);
 

2、修改/etc/nginx.conf配置文件,以至于能正確解析wordpress的php文件

[root@Nginx ~]#vi /etc/nginx/
    location ~ \.php$ {
            root           /usr/local/nginx1.8/html/wordpress;          /*wordpress的目錄,如果是html根目錄,則默認即可
            fastcgi_pass   127.0.0.1:9000;          /*本地php-fpm監聽地址
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx1.8/html/wordpress$fastcgi_script_name;
           include        fastcgi_params;
        }
        ……
        ……
    location \favicon.ico {
            root html;          /*防止nginx找不到favicon.ico文件而打開頁面失敗
    }
[root@Nginx ~]#nginx -t
[root@Nginx ~]#nginx -s reload

現在,找個瀏覽器就可以瀏覽wordpress,簡單的安裝即可開始個性的博客之旅。

TIM圖片20171102162719

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/88183

(0)
396064847396064847
上一篇 2017-11-01 16:11
下一篇 2017-11-02 18:08

相關推薦

  • N26-第九周

    1、寫一個腳本,判斷當前系統上所有用戶的shell是否為可登錄shell(即用戶的shell不是/sbin/nologin);分別這兩類用戶的個數;通過字符串比較來實現; #!/bin/bash # # # NUM1=0 NUM2=0 for i in `cut -d: -f7 /etc/passwd` ;do if [[ “$i” = ‘/bin/bash…

    Linux干貨 2017-03-15
  • LINUX 下正確關機方法

    Linux下正確關機方法 Table of Contents 1關機前 1.1觀察系統使用 1.2通知在線使用者關機 2關機 2.1 sy 2.2 shutdo 2.3 rebo 2.4 ha 2.5 powero 3執行 3.1等級 3.2等級 1關機前準備 1.1觀察系統使用狀態 誰在線:who 聯網狀態:netstat -a 后臺執行的程序:ps -a…

    Linux干貨 2017-08-21
  • Linux文本處理工具grep,egrep

    簡介:     grep即(Global search REgular expression and Print out the line)全局的搜索正則表達式并且打印顯示出來。     通俗點講:根據用戶指定的文本模式(搜索條件)對目標文件進行逐行搜索,顯示能匹配到的行。 &n…

    Linux干貨 2015-05-11
  • 馬哥教育網絡班20期第2周課程練習

    一、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關  示例演示。 linux上文件管理命令包括: ls,cat,pwd,cp,rm,cd,head,tail,more,less,cut,which,whereis,find,mkdir,mv; 1、ls 命令;顯示文件/文件夾清單   例如:如下顯示列出根目錄下的文件及目錄…

    Linux干貨 2016-06-23
  • 有證說話硬–實現CA和證書申請

    centos下利用openssl來實現證書的頒發 直接進入正題,細節坑就不說了,自己解決起來更有挑戰性不是 步驟流程: 我是拿的7.3版本做CA主機,6.8版本做客戶端 1.創建CA 2.生成私鑰 3.生成自簽名證書 4.到客服端 5.生成私鑰 6.生成證書申請文件 7.將請求發送給-CA主機 8.CA主機-驗證簽署 9.拷回給客戶端使用 用法:openss…

    2017-04-11
  • linux用戶管理實戰

    ?1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登陸多次,則只顯示一次即可。 [root@localhost ~]# who |cut -d ‘ ‘ -f1 |sort -u ?2、取出最后登陸到當前系統的用戶的相關信息。 [root@localhost ~]# who |tail -1 ?3、取出當前系統上被用戶當做…

    2018-02-08
欧美性久久久久