單臺部署LNMP架構

單臺部署LNMP架構

/ 安裝Nginx /
[root@jx_001 ~]# vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch
gpgcheck=0
enabled=1
[root@jx_001 ~]# yum makecache
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile

  • base: mirrors.aliyun.com
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
    base | 3.6 kB 00:00:00
    epel | 3.2 kB 00:00:00
    extras | 3.4 kB 00:00:00
    nginx | 2.9 kB 00:00:00
    updates | 3.4 kB 00:00:00
    (1/3): nginx/x86_64/primary_db | 42 kB 00:00:00
    (2/3): nginx/x86_64/other_db | 23 kB 00:00:01
    (3/3): nginx/x86_64/filelists_db | 58 kB 00:00:02
    元數據緩存已建⽴
    [root@jx_001 ~]# yum -y install nginx
    ......

    驗證中 : 1:nginx-1.14.2-1.el7_4.ngx.x86_64
    1/1
    已安裝:
    nginx.x86_64 1:1.14.2-1.el7_4.ngx
    完畢!
    [root@jx_001 ~]# systemctl start nginx ---開啓nginx服務
    [root@jx_001 ~]# systemctl enable nginx ---設置nginx服務開機⾃啓動
    / 安裝MariaDB數據庫 /
    / 安裝PHP環境 /
    / 整合 /
    -nginx設置
    Created symlink from /etc/systemd/system/multiuser.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
    ##確定ip地址, 並在瀏覽器中訪問, 得到歡迎⻚⾯即代表成功!
    [root@jx_001 ~]# yum -y install mariadb-server mariadb
    ......
    [root@jx_001 ~]# systemctl start mariadb
    [root@jx_001 ~]# systemctl enable mariadb
    Created symlink from /etc/systemd/system/multiuser.target.wants/mariadb.service to
    /usr/lib/systemd/system/mariadb.service.
    [root@jx_001 ~]#
    [root@jx_001 ~]# mysqladmin -uroot -p password "123456"
    Enter password:
    [root@jx_001 ~]# mysql -uroot -p"123456"
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 3
    Server version: 5.5.60-MariaDB MariaDB Server
    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)]> exit
    Bye
    [root@jx_001 ~]#
    [root@jx_001 ~]# yum -y install php php-devel php-fpm php-xml php-mbstring
    php-mcrypt php-gd php-mysql
    [root@jx_001 ~]# systemctl start php-fpm
    [root@jx_001 ~]# systemctl enable php-fpm
    Created symlink from /etc/systemd/system/multi-user.target.wants/phpfpm.service to /usr/lib/systemd/system/php-fpm.service.
    -mariadb設置

    vi /etc/nginx/conf.d/default.conf

    server {
    listen 80;
    server_name localhost;
    location / {
    root /usr/share/nginx/html;
    index index.php index.html index.htm;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/html;
    }
    location ~ .php$ {
    root /usr/share/nginx/html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    }

    systemctl restart nginx

    增加php⾸⻚並進⾏測試

    vi /usr/share/nginx/html/index.php

    <?php phpinfo(); ?>
    在瀏覽器中訪問主機IP地址,查看是否能夠訪問到PHP的信息
    [root@jx_001 ~]# mysql -uroot -p'123456'
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 4
    Server version: 5.5.60-MariaDB MariaDB Server
    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;
    Query OK, 1 row affected (0.01 sec)
    測試代碼:
    MariaDB [(none)]> exit
    Bye
    [root@jx_001 ~]# vi /usr/share/nginx/html/index.php
    寫⼊下⽅測試代碼
    <?php
    $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
    if (!$link) {
    die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    mysql_close($link);
    ?>
    ##項⽬上線流程
    [root@jx_001 ~]# curl -o wordpress.tar.gz
    https://wordpress.org/latest.tar.gz
    % Total % Received % Xferd Average Speed Time Time Time
    Current
    Dload Upload Total Spent Left
    Speed
    100 10.0M 100 10.0M 0 0 487k 0 0:00:21 0:00:21 --:--:--
    748k
    [root@jx_001 ~]#
    [root@jx_001 ~]# ls
    anaconda-ks.cfg wordpress.tar.gz
    [root@jx_001 ~]# tar xf wordpress.tar.gz
    [root@jx_001 ~]# ls
    anaconda-ks.cfg wordpress wordpress.tar.gz
    [root@jx_001 ~]# cp -rf wordpress/* /usr/share/nginx/html/
    [root@jx_001 ~]# cd /usr/share/nginx/html/
    [root@jx_001 html]# ls
    index.php wp-activate.php wp-comments-post.php wp-cron.php
    wp-load.php wp-settings.php xmlrpc.php
    license.txt wp-admin wp-config-sample.php wp-includes
    wp-login.php wp-signup.php
    readme.html wp-blog-header.php wp-content wp-links-opml.php
    wp-mail.php wp-trackback.php
    [root@jx_001 html]# mv wp-config-sample.php wp-config.php
    [root@jx_001 html]# vi wp-config.php
    // MySQL settings - You can get this info from your web host //
    / The name of the database for WordPress */
    define('DB_NAME', 'wordpress'); --數據庫名稱
    /* MySQL database username /
    訪問到下⽅⻚⾯即代表成功
    define('DB_USER', 'root'); --數據庫⽤戶名
    /
    MySQL database password */
    define('DB_PASSWORD', '123456'); --數據庫⽤戶的密碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章