ubuntu安装lamp

服务器配置

网络拓扑

Mysql Server

Web Server
   (dynamic )

Picture Server
   (Static)

原理

需要4台主机,一个公网ip10.5.0.226

Web服务器处理php代码,pictureserver处理静态文件的访问。上传图片先由web服务器处理,再通过nfs从web服务器存入picture server。

用户访问代理服务器test.com。代理服务器根据请求文件的后缀判断,并将动态文件请求转发给web服务器,静态文件请求转发给picture server

由于nginx处理静态文件更有优势,所以静态picture服务器使用的是nginx服务器。
测试代码,提供单页无刷新的图片上传,展示和删除测试。

IP配置

本机操作

1.修改配置文件

vi /etc/network/interfaces

2.重启网卡

ifdown eth0

ifup eth0

3查看网络配置信息

ifconfig

4.检查是否可以联网

ping www.baidu.com

安装web服务器

主机ip:10.5.0.223

Apache

1.安装apache

apt-get install apache2

输入ip:10.5.0.223测试

PHP

1.安装php

apt-get install php5

apt-get install libapache2-mod-php5

2.输入测试代码phpinfo();

vi /var/www/html/test.php

3.测试

http://10.5.0.223/test.php

Mysql客户端

apt-get install mysql-client

安装mysql服务器

主机ip:10.5.0.224

1.安装

apt-get install mysql-server

2.检查安装是否成功

mysql –u root -p

3.开启外部访问权限

grant all privileges on *.*  to [email protected]"%"  identified by "root";

flush privileges

4. 允许外联:

vi /etc/mysql/my.cnf

注释bind-address=127.0.0.1这行

5.重启mysql

service mysql restart

让apache、php支持 mysql

主机ip:10.5.0.223

apt-get install libapache2-mod-auth-mysql

apt-get install php5-mysql

测试:

service apache2 restart

连接mysql服务器:

vi /var/www/html/test.php

<?php

$link = mysql_connect(‘10.5.0.224‘,‘root‘,‘root‘);

var_dump($link);

安装phpmyadmin

主机ip:10.5.0.223

安装

apt-get install phpmyadmin

ln -s /usr/share/phpmyadmin /var/www/html/

配置phpmyadmin连接的mysql主机地址

$cfg[‘Servers‘][$i][‘host‘] = ‘localhost‘;改为$cfg[‘Servers‘][$i][‘host‘] = ‘10.5.0.224‘;

连接登陆

http://10.5.0.223/phpmyadmin/index.php

安装图片服务器

主机ip:10.5.0.225

1.安装nginx

apt-get install nginx

查看10.5.0.225

3.添加需要共享的文件夹

mkdir /usr/share/nginx/html/image

4.修改该文件夹权限

配置文件夹所属用户为任意普通用户

chown wangrui.wangrui image/

5.安装NFS

apt-get install nfs-kernel-server

6.配置共享文件夹

vi /etc/exports

在末尾加入

/usr/share/nginx/html/image 10.5.0.203(rw,sync,anonuid=1000,anongid=1000)

10.5.0.223用户登入时,用户权限和uid为1000的权限一样,该用户为拥有/usr/share/nginx/html/image读写权限的普通用户

7.重启nfs

service nfs-kernel-server restart

8.查看共享文件夹

showmount -e

安装nfs客户端

主机ip:10.5.0.223

apt-get install nfs-common

1.添加需要挂载的文件夹

mkdir /var/www/html/image

chmod 777 /var/www/html/image

2.挂载到图片服务器的共享文件夹

mount -t nfs 10.5.0.225:/usr/share/nginx/html/image/var/www/html/image/

3.测试:

在10.5.0.223 /var/www/html/image增删文件,实际是操作10.5.0.225 /usr/share/nginx/html/image

上传图片到

10.5.0.225  的/usr/share/nginx/html/image目录

可以通过http://10.5.0.223/image/1.jpg访问到

安装haproxy

主机ip:10.5.0.226

1.安装

apt-get install haproxy

2.配置

vi /etc/haproxy/haproxy.cfg

#---------------------------------------------------------------------

# main frontend which proxys to the backends

#---------------------------------------------------------------------

frontend  proxy*:80    #前端代理

aclurl_static            path_end       -i .jpg.gif .png

acl dynamic_content  path_end      -i .php .html .css .js

use_backend static          if url_static

default_backend            dynamic

#---------------------------------------------------------------------

# static backend for serving up images, stylesheets and such

#---------------------------------------------------------------------

backend static    #后端静态服务器

server      web1 10.5.0.225:80  inter 3000 rise 2fall 3 check maxconn 5000

#---------------------------------------------------------------------

# round robin balancing between the various backends

#---------------------------------------------------------------------

backend dynamic    #后端动态服务器

server      web2 10.5.0.223:80  inter 3000 rise 2fall 3 check maxconn 5000

综合测试

1.创建数据库

create database if not exists test charset utf8;

use test;

create table if not exists test_image(

id intprimary key auto_increment,

namevarchar(32) not null comment ‘name of image‘,

pathvarchar(100) not null comment ‘path of image‘,

create_timeint not null comment ‘file create time‘

)charset utf8;

2.上传代码到web服务器10.5.0.223

Config.php为数据库配置文件DB_HOST地址为mysql服务器地址

3.配置Host文件

10.5.0.226 test.com

4访问测试

访问地址test.com/test.html

所有响应来自test.com

数据库:

图片服务器:10.5.0.225

如果关闭nginx不能访问到图片,说明请求图片文件时,haproxy是请求的nginx

时间: 2024-08-04 19:36:35

ubuntu安装lamp的相关文章

9.17 ubuntu安装LAMP服务

更新ubuntu源 /etc/apt/sources.list Cp /etc/apt/sources.list /etc/apt/sources.list.bak备份 修改vim /etc/apt/sources.list 将其中的数据修改为最新的源镜像地址 deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubun

Ubuntu 安装lamp

安装lamp sudo apt-get install lamp-server^ 安装phpmyadmin sudo apt-get install libapache2-mod-auth-mysql phpmyadmin

Ubuntu安装LAMP环境(PHP5.6) 以及下载安装phpmyadmin

参考路径: http://blog.nciaer.com/?p=133 修改apache(2.4.18)的web路径时, 需要将 /etc/apache2/sites-available/000default.config 和  /etc/apache2/apache2.conf 中的/var/www/html 改成相应路径即可 安装phpmyadmin的方法: 1 先去官网下载phpmyadmin的压缩包 2. 解压后一般放到web目录下,然后找到phpmyadmin的libraries文件夹

xshell远程终端操作Ubuntu server安装LAMP环境之最详细笔记之二PHP开发环境配置

前言: 昨天学会了安装server,今天试着通过远程终端xshell来安装LAMP,搭配一下开发环境,也有集成环境可以一键安装使用,还是瞎折腾一下,手动一步一步搭建一下这个开发环境. 接上一篇:ubuntu server 14.04 LTS下搭建LAMP环境之最详细笔记之一U盘安装双系统本文原创博客地址:http://www.cnblogs.com/unofficial官网地址:www.pushself.com) 准备: 在windows系统上首先需要安装xhsell,具体下载地址可以搜一下,安

Ubuntu Server 12.04 LTS 安装LAMP环境

Ubuntu的LAMP环境apt-get一键搭建: sudo apt-get install apache2 php5 mysql-server php5-mysql Ubuntu的LAMP环境tasksel一键搭建:(tasksel提供了Ubuntu一些常见的软件套装) sudo tasksel install lamp-server apache默认网站根目录:/var/www 环境工作是否正常测试: sudo vim info.php <?php     echo "这是测试LAMP

在 Ubuntu Server 16.04 LTS 上安装 LAMP

在 Ubuntu Server 16.04 LTS 上安装 LAMP LAMP 方案是一系列自由和开源软件的集合,包含了 Linux.Web 服务器 (Apache). 数据库服务器 (MySQL / MariaDB) 和 PHP (脚本语言). LAMP 是那些需要安装和构建动态网页应用的基础平台,比如WordPress.Joomla.OpenCart 和 Drupal,我将描述如何在 Ubuntu Server 16.04 LTS 上安装 LAMP,众所周知 Ubuntu 是一个基于 Lin

在Ubuntu上安装LAMP服务器

1.安装Ubuntu上安装LAMP apt-get install lamp-server^ 2.安装过程中设置MySql密码 3.测试 创建index.php var/www/html/index.php index.php的内容为 <?php phpinfo(); ?> 重启apache, service apache2 restart 在浏览器中输入 http://localhost/index.php 或者localhost改为IP地址 5配置MYSql cat /etc/hosts

ubuntu下安装lamp环境

使用普通用户来安装lamp环境: 1.安装apache: sudo apt-get install apache2 输入:y 安装完成之后查看是否安装成功: apache2 -v 2.安装php sudo apt-get install php5 安装完后查看是否安装成功: php5 -v 注意:apache和php进行交互,apache必须安装libphp5.so模块,所以我们必须先看apache是否安装了此模块,使用如下命令进行检查: cat /etc/apache2/mods-enable

UBUNTU安装PHP,即所谓得LAMP

Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台.随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注.从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案.