1. 程式人生 > >ubuntu17.10安裝LAMP並部署php探針系統

ubuntu17.10安裝LAMP並部署php探針系統

following for bsp 代碼 div 改密 oracl fast net

ubuntu17.10修改密碼以及安裝LAMP並部署php探針系統

步驟1:ubuntu17.10配置IP (這個版本配置IP方式改變較大,apt-get upgrade更新至最新以前配置方式也可以用了)

root@ubuntu:~# vi /etc/netplan/01-netcfg.yaml

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens32:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.10.222/24]
      gateway4: 192.168.10.1
      nameservers:
        addresses: [61.134.1.5, 114.114.114.114]

配置修改保存後執行命令讓配置生效:

root@ubuntu:~# netplan apply

步驟2:安裝 Apache Web Server

輸入以下命令來安裝Apache Web服務器。該apache2-utils包將安裝一些有用的實用程序,如Apache HTTP服務器基準測試工具(ab)。

root@ubuntu:~# sudo apt install -y apache2 apache2-utils

  安裝完成後,應自動啟動Apache。 使用systemctl檢查其狀態。

root@ubuntu:~# systemctl status apache2.service
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset:
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running) since Mon 2018-01-22 22:14:47 EST; 1min 52s ago
 Main PID: 21380 (apache2)
    Tasks: 55 (limit: 4915)
   Memory: 4.9M
      CPU: 179ms
   CGroup: /system.slice/apache2.service
           ├─21380 /usr/sbin/apache2 -k start
           ├─21382 /usr/sbin/apache2 -k start
           └─21383 /usr/sbin/apache2 -k start

Jan 22 22:14:47 ubuntu systemd[1]: Starting The Apache HTTP Server...
Jan 22 22:14:47 ubuntu apachectl[21360]: AH00558: apache2: Could not reliably de
Jan 22 22:14:47 ubuntu systemd[1]: Started The Apache HTTP Server.

如果沒有運行,請使用systemctl啟動它。使Apache啟動時自動啟動也是一個好方法

root@ubuntu:~# sudo systemctl start apache2
root@ubuntu:~# sudo systemctl enable apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2

  

啟動後瀏覽器測試IP是否可以打開訪問

技術分享圖片

現在我們需要將www-data(Apache用戶)設置為文檔根目錄的所有者。 默認情況下,它由root用戶擁有。

root@ubuntu:~# sudo chown www-data:www-data /var/www/html/ -R

步驟 3: 安裝 MariaDB 數據庫服務器

MariaDB是MySQL的替代品。 輸入以下命令將其安裝在Ubuntu 17.10上。

root@ubuntu:~# sudo apt install mariadb-server mariadb-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  galera-3 libaio1 libcgi-fast-perl libcgi-pm-perl libdbd-mysql-perl
  libdbi-perl libencode-locale-perl libfcgi-perl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl
  libhttp-message-perl libio-html-perl libjemalloc1 liblwp-mediatypes-perl

安裝完畢後,MariaDB服務器應自動開啟。 使用systemctl檢查其狀態。

root@ubuntu:~# systemctl start mariadb
  root@ubuntu:~# systemctl enable mariadb  //開機自動自動

root@ubuntu:~# systemctl status mariadb

● mariadb.service - MariaDB 10.1.30 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset:
   Active: active (running) since Mon 2018-01-22 22:34:51 EST; 5s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 23372 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_STA
  Process: 23368 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SU
  Process: 23254 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VA
  Process: 23246 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_STAR
  Process: 23237 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/r
 Main PID: 23341 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 26 (limit: 4915)
   Memory: 59.2M
      CPU: 464ms
   CGroup: /system.slice/mariadb.service
           └─23341 /usr/sbin/mysqld

Jan 22 22:34:50 ubuntu systemd[1]: Starting MariaDB 10.1.30 database server...
Jan 22 22:34:50 ubuntu mysqld[23341]: 2018-01-22 22:34:50 139684071342016 [Note]
Jan 22 22:34:51 ubuntu systemd[1]: Started MariaDB 10.1.30 database server.

現在運行安裝後的安全腳本。

sudo mysql_secure_installation

當它要求您輸入MariaDB root密碼時,按Enter鍵,因為root密碼尚未設置。 然後輸入y設置MariaDB服務器的root密碼。

root@ubuntu:~# sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we‘ll need the current
password for the root user.  If you‘ve just installed MariaDB, and
you haven‘t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:

##後面的設置選項按需選擇即可

默認情況下,Ubuntu上的MaraiDB軟件包使用unix_socket對用戶登錄進行身份驗證,這主要表示您可以使用操作系統的用戶名和密碼登錄到MariaDB控制臺。 因此,您可以運行以下命令登錄,而不提供MariaDB root密碼。

root@ubuntu:~# sudo mariadb -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.1.30-MariaDB-0ubuntu0.17.10.1 Ubuntu 17.10

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> exit
Bye

步驟 4: 安裝 PHP7.1

在撰寫本文時,PHP7.1是PHP的最新穩定版本,在PHP7.0上具有較小的性能優勢。 輸入以下命令來安裝PHP7.1。

root@ubuntu:~# sudo apt install php7.1 libapache2-mod-php7.1 php7.1-mysql php-common php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-readline
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php7.1 php-common php7.1 php7.1-cli php7.1-common php7.1-json
  php7.1-mysql php7.1-opcache php7.1-readline
0 upgraded, 9 newly installed, 0 to remove and 3 not upgraded.
Need to get 3,783 kB of archives.
After this operation, 15.0 MB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu artful/main amd64 php-common all 1:54ubuntu1 [12.1 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu artful-updates/main amd64 php7.1-common amd64 7.1.11-0ubuntu0.17.10.1 [836 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu artful-updates/main amd64 php7.1-json amd64 7.1.11-0ubuntu0.17.10.1 [17.5 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu artful-updates/main amd64 php7.1-opcache amd64 7.1.11-0ubuntu0.17.10.1 [146 kB]

啟用Apache php7.1模塊,然後重新啟動Apache Web服務器。

root@ubuntu:~# sudo a2enmod php7.1
Considering dependency mpm_prefork for php7.1:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php7.1:
Module php7.1 already enabled
root@ubuntu:~# sudo systemctl restart apache2
root@ubuntu:~# php --version
PHP 7.1.11-0ubuntu0.17.10.1 (cli) (built: Nov 1 2017 16:30:52) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.11-0ubuntu0.17.10.1, Copyright (c) 1999-2017, by Zend Technologies

要使用Apache服務器測試PHP腳本,我們需要在文檔根目錄中創建一個info.php文件。

root@ubuntu:~# sudo vi /var/www/html/info.php

將以下PHP代碼粘貼到文件中。

<?php phpinfo(); ?>

技術分享圖片

順便測試下探針,將tz.php放/var/www/html/目錄下

技術分享圖片

至此 ubuntu17.10的web環境已經ok!!!

ubuntu17.10安裝LAMP並部署php探針系統