首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

ubuntu系统筹建LAMP环境

2012-09-02 
ubuntu系统搭建LAMP环境LAMP,即LinuxApacheMysqlPHP,常用来搭建动态网站或者服务器的开源软件,本身都是各

ubuntu系统搭建LAMP环境

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

下面我就给大家讲解一下LAMP环境的搭建方法。本例采用的操作系统是ubuntu-12.04-desktop-i386.iso。

1、更新系统。命令:

sudo apt-get install update
sudo apt-get install upgrade

这是为了能找到apache等程序做的准备。

2、安装Apache服务。命令:

sudo apt-get install apache2

这里可以打开 http://127.0.0.1 或者 http://localhost,看到网页显示”it works”。(图1)

ubuntu系统筹建LAMP环境(图1)

  3、安装php5。命令:

sudo apt-get install php5
sudo /etc/init.d/apache2 restart   //重启apache服务

这里可以用命令

sudo gedit /var/www/testphp.php

建一个php文件,并且在里面插入

<?php phpinfo() ?>

保存后退出。打开网页http://localhost/testphp.php可以看到网页显示有关php的配置信息。(图2)

ubuntu系统筹建LAMP环境(图2)

  4、安装mysql。命令:

sudo apt-get install mysql-server    //安装时提示设置密码(图3)
sudo apt-get install mysql-client

ubuntu系统筹建LAMP环境(图3)

  5、让apache、php支持mysql

sudo apt-get install libapache2-mod-auth-mysql
sudo apt-get install php5-mysql
sudo /etc/init.d/apache2 restart

此时LAMP环境已经搭建成功,但为了方便管理,我们再下载个管理工具phpMyAdmin(phpMyAdmin 是用PHP编写的,可以通过 web 方式控制和操作 MySQL 数据库。通过 phpMyAdmin 可以完全对数据库进行操作,例如建立、复制、删除数据等等。)。

6、安装phpMyAdmin

sudo apt-get install phpmyadmin

当它提示你选择那种web server时,我们选择apache2,或者也可以什么都不选,直接点击OK安装就行。安装过程中需要输入mysql密码,以及设定phpMyAdmin密码。安装完成后打开http://localhost/phpmyadmin,用户名为root,登录后即可通过web,图形化管理mysql数据库。(图4)

再做一个软链接,从/user/share/phpmyadmin链接到var/www/下就可以了

sudo ln -s /etc/phpmyadmin/apache.conf/etc/apache2/conf.d/phpmyadmin.conf

sudo /etc/init.d/apache2 reload


ubuntu系统筹建LAMP环境(图4)





二、手工编译为Ubuntu安装PHP+MYSQL+Apache

1、下载软件

MySql:wget http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gz

Apache:wget http://apache.freelamp.com/httpd/httpd-2.2.13.tar.gz

PHP:wgethttp://125.39.113.23:9203/CDE349DEF7D7A6AC19DE5771F752CA258C693F634815D4BE/cn.php.net/distributions/php-5.2.10.tar.bz2

2、安装MySql

安装步骤:

shell> groupadd mysql

shell> useradd -g mysql mysql

shell> gunzip < mysql-VERSION.tar.gz | tar -xvf – 或 tar -zxvf  mysql-5.0.56.tar.gz(解压mysql源码包)

shell> cd mysql-VERSION(进入mysql源码文件夹)

shell> ./configure –prefix=/usr/local/mysql

shell> make

shell> make install

shell> cp support-files/my-medium.cnf /etc/my.cnf

shell> cd /usr/local/mysql

shell> bin/mysql_install_db –user=mysql

shell> chown -R root  .

shell> chown -R mysql var

shell> chgrp -R mysql .

shell> bin/mysqld_safe –user=mysql &

修改mysql root 密码
$ mysqladmin -u root password newpass
添加服务项
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig –add mysqld

3、安装Apache

tar zvxf httpd-2.2.13.tar.gz
cd httpd-2.2.13
修改src/include/httpd.h 增大最大线程数

#define HARD_SERVER_LIMIT 256

改成

#define HARD_SERVER_LIMIT 2560

保存退出编译apache
./configure –prefix=/usr/local/apache –enable-module=so –enable-module=rewrite –enable-shared=max –htdocsdir=/var/www &&
make
make install

#这里我们通过enable-module参数告诉设置脚本,我们需要启动so和rewrite模块,so模块是用来提DSO支持的apache核 心模块,而rewrite模块则是用意实现地址重写的模块,由于rewrite模块需要DBM支持,如果在初次安装时没有编译进apache,以后需要用 到时需要重新编译整个apache才可以实现。为此除非你可以确定以后不会用到rewrite模块,否则还是建议你在第一次编译的时候把rewrite模 块编译好。

enable-shared=max 这个参数的作用时编译apache时,把除了so以外的所有apache的标准模块都编译成DSO模块。而不是编译进apache核心内。

好了安装apache很简单的哦,启动apache看看

/usr/local/apache/bin/apachectl start
然后 通过浏览器查看http://youhost/,如果正常则说明安装成功。

apache设为linux服务

cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd

在在#!/bin/sh后面加入下面两行
#chkconfig:345 85 15
#description: Start and stops the Apache HTTP Server.

然后
chmod +x /etc/rc.d/init.d/httpd
chkconfig –add httpd

4、安装PHP

(1)tar zvxf php-5.2.10.tar.bz2
(2)cd php-5.2.10

(3)./configure -prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc -with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-ldap –with-ldap-sasl –-with-apxs2=/usr/local/apache/bin/apxs

(4)make

(5)make install

最后一步重新启动apache报如下错误:
httpd: Syntax error on line 53 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

原因:是Linux有一个SELinux保护模式引起的。

解决办法:

1关闭SELINUX的方法:
vi /etc/selinux/config 将SELINUX=enforcing 改成SELINUX=disabled 需要重启
这个方法可能会对服务器带来风险。

2不关闭SELINUX的方法:依次执行如下命令# setenforce 0# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so

# service httpd restart
# setenforce 1

vi /usr/local/apache/conf/httpd.conf

查找

在此范围添加

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

然CPOPY PHP的配置文件

cp ../php-5.2.10/php.ini.dist /usr/local/php/lib/php.ini

修改php.ini文件
register_globals = On

ok!重新启动一下apache服务器
/usr/local/apache/bin/apachectl restart

然后写个php测试页info.php:内容如下

<?php
phpinfo();
?>
正常的话,应该能看到php的信息了,恭喜你的Apche+Mysql+PHP安装成功。


热点排行