Ubuntu Server 14.04 安裝+安全Web伺服器(linux+apache+mysql+php)搭建流程(更新),ubuntu14.04

來源:互聯網
上載者:User

Ubuntu Server 14.04 安裝+安全Web伺服器(linux+apache+mysql+php)搭建流程(更新),ubuntu14.04

之前整過CentOS,整了Ubuntu才發現,Ubuntu簡單多了~~不知道效能相比又如何。

以Ubtuntu 14.04為例,記錄一下搭建流程。

一、安裝注意點1. IP地址

安裝時先不要插網線,不然會DHCP,後續配置起來也麻煩

2. 硬碟分區

自動分區貌似有:/、swap、efiswap、/boot(200MB)
實際兩個區就足夠了:swap為記憶體的1~2倍大小,剩餘皆為/

二、IP配置

裝完後一般遠端連線,需要配置ip地址,以下是多ip配置。(安裝時會以嚮導形式配好一個IP,修改時只要複製粘貼就可以)

vi /etc/network/interfaces

配置資訊:

 # The primary network interface auto em0 iface em0 inet static         address 192.168.1.1         netmask 255.255.252.0         network 192.168.1.0         broadcast 192.168.1.255         gateway 192.168.8.254         # dns-* options are implemented by the resolvconf package, if installed         dns-nameservers 8.8.8.8 8.8.8.9         # dns-search 163.com # The second network interface auto em1 iface em1 inet static         address 192.168.1.2         netmask 255.255.252.0         network 192.168.1.0

重啟網卡(貌似不一定生效,reboot肯定可以)

/etc/init.d/networking restart
三、SSH伺服器

預設安裝後vi /etc/ssh/sshd_config,修改設定檔。
安全起見,可以建立允許清單:

1. 修改/etc/hosts.allow:
sshd: 192.168.1. , 192.168.0. : allow
2. 修改/etc/hosts.deny:
sshd : ALL
四、系統更新

先更新源,用以Trusty Tahr (14.04)為例,其他版本看配置產生器

deb http://mirrors.ustc.edu.cn/ubuntu/ trusty main restricted universe multiversedeb http://mirrors.ustc.edu.cn/ubuntu/ trusty-security main restricted universe multiversedeb http://mirrors.ustc.edu.cn/ubuntu/ trusty-updates main restricted universe multiversedeb http://mirrors.ustc.edu.cn/ubuntu/ trusty-proposed main restricted universe multiversedeb http://mirrors.ustc.edu.cn/ubuntu/ trusty-backports main restricted universe multiversedeb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty main restricted universe multiversedeb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-security main restricted universe multiversedeb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-updates main restricted universe multiversedeb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-proposed main restricted universe multiversedeb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse

再更新apt-get

apt-get updatesudo apt-get upgrade

然後更新系統並重啟

sudo apt-get install update
五、Samba安裝網路位置
smbpasswd -a somebody

然後會提示你輸入密碼,這是訪問網路位置檔案夾的密碼。
3. 修改設定檔:

cp /etc/samba/smb.conf /etc/samba/smb.conf.bakvi /etc/samba/smb.conf

在其後增加共用目錄:

[share]    path = /home/somebody/samba_share      available = yes       browseable = yes       public = no       writable = yes
/etc/init.d/samba restart 
六、安裝apache2
apt-get install apache2  

裝好後訪問http://localhost就可以看到“It Works!”
apache2設定檔在/etc/apache2/apache2.conf,web目錄在/var/www/html

預設使用者是www-data,定義在./envvars檔案中

其他設定檔在:./sites-enabled/*.conf

七、安裝mysql
apt-get install mysql-server mysql-client

安裝過程需要設定root的密碼。Ubuntu下,MySQL的配置資訊在/etc/mysql目錄

MySQL預設的字元集是latin1:

為了避免中文可能帶來的亂碼問題,將預設字元集改成utf-8,具體可以參考這篇文章,修改 /etc/mysql/my.cnf 檔案,在相應位置添加:

[client]default-character-set=utf8[mysql]default-character-set=utf8[mysqld]collation-server = utf8_unicode_ciinit-connect='SET NAMES utf8'character-set-server = utf8

修改後是這樣的:

八、安裝php5及Apache的php5模組
apt-get install php5 libapache2-mod-php5 php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

OK! It Works!

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.