Ubuntu Server 14.04 安装Web服务器(Linux+Apache+MySQL+PHP)


之前整过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 multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse

再更新apt-get

apt-get update
sudo apt-get upgrade

然后更新系统并重启

sudo apt-get install update

五、Samba安装网上邻居

  1. 默认安装 apt-get install samba
  2. 为samba创建ubuntu系统已经存在的用户somebody:
smbpasswd -a somebody

然后会提示你输入密码,这是访问网上邻居文件夹的密码。
3. 修改配置文件:

cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
vi /etc/samba/smb.conf

在其后增加共享目录:

[share]
    path = /home/somebody/samba_share
      available = yes 
      browseable = yes 
      public = no 
      writable = yes
  1. 重启samba就可以像windows一样访问
/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_ci
init-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!

------------------------------------分割线------------------------------------

CentOS 6.5系统安装配置LAMP(Apache+PHP5+MySQL)服务器环境

Ubuntu 14.04 配置 LAMP+phpMyAdmin PHP(5.5.9)开发环境 

Windows 7下硬盘安装Ubuntu 14.10图文教程

U盘安装Ubuntu 14.10

Ubuntu 14.10 正式发布下载

Ubuntu 14.04 LTS 如何升级到 Ubuntu 14.10 

Ubuntu 14.10 下安装 LAMP 服务图文详解 

------------------------------------分割线------------------------------------

相关内容

    暂无相关文章