Linux下LAMP(Apache+PHP+MySql)环境配置(第二版)

2011-08-01 16:36:05 by 【6yang】, 127 visits, 收藏 | 返回

LAMP是一个缩写Linux+Apache+MySql+PHP,它指一组通常一起使用来运行动态网站或者服务器的自由软件:

* Linux,操作系统;
* Apache,网页服务器;
* MySQL,数据库管理系统(或者数据库服务器);
* PHP 和有時 Perl 或 Python,脚本语言。

今天介绍一下Linux下LAMP(Apache+PHP+MySql)环境配置:

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:wget http://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安装成功。

 

1、

安装 Apache2:
sudo apt-get install apache2
安装PHP模块:
sudo apt-get install php5
编辑测试页:()
sudo gedit /var/www/testphp.php

安装Mysql
sudo apt-get install mysql-server
mysqladmin -u root password db_user_password
#db_user_password替换为密码

安装Mysql模块
sudo apt-get install libapache2-mod-auth-mysql
sudo apt-get install php5-mysql
sudo apt-get install php5-gd
sudo /etc/init.d/apache2 restart

配置php.ini:
sudo gedit /etc/php5/apache2/php.ini
把文件在文件后面的:
#extension=mysql.so
#extension=gd.so
的#去掉。

安装phpmyadmin
sudo apt-get install phpmyadmin
测试:http://localhost/phpmyadmin/

将URL映射到其他目录

sudo gedit /etc/apache2/conf.d/alias

* 在新增的文件内加入下面这几行

Alias /URL-path /location_of_folder/

Options Indexes FollowSymLinks
AllowOverride All
order allow,deny
Allow from all

重起apache
sudo /etc/init.d/apache2 restart

 

2、无法解析php文件:
修改/etc/apache2/apache2.conf文件,添加:“AddType application/x-httpd-php .php”
然后重启apache即可:sudo /etc/init.d/apache2 restart

 

 

 

1、安装Apache服务
sudo apt-get install apache2
然后按照提示即完成apahce的安装了。这里 可以打开
http://127.0.0.1
,即可看于是It works
2、安装php5
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo apt-get install php5-gd
sudo apt-get install php5-dev
sudo /etc/init.d/apache2 restart
OK之后,我们来查看一下是否生效了。
gksudo gedit /var/www/testphp.php
入探针
保存运行
http://127.0.0.1/testphp.php
3、安装mysql
sudo apt-get install mysql-server
安装完成按提示设置root密
4、让apache、php支持mysql
sudo apt-get install libapache2-mod-auth-mysql
sudo apt-get install php5-mysql
sudo /etc/init.d/apache2 restart
至此apache2+php 5.2.4.2+mysql5.0.51的环境就完成了。
1、安装 Apache2+PHP5+MySQL
sudo apt-get install apache2 libapache2-mod-php5 php5 php5-gd mysql-server php5-mysql phpmyadmin

joelhy 提醒 这一步可以使用新立得来安装,同样效果。
打开新立得,编辑 –> 使用任务分组标记软件包 –> 勾选 LAMP Server

然后再单独安装 phpmyadmin
sudo apt-get install phpmyadmin

2、启用 mod_rewrite 模块
sudo a2enmod rewrite

3、配置 apache2.conf
sudo gedit /etc/apache2/apache2.conf

去掉 AddHandler cgi-script .cgi 前的注释 “#”。

然后在任意地方添加这么一段:

&<60;&<60; &<60;DocumentRoot /var/www/
&<60;&<60; &<60;
&<60;&<60; &<60; &<60; &<60;Options FollowSymLinks
&<60;&<60; &<60; &<60; &<60;AllowOverride all
&<60;&<60; &<60;
&<60;&<60; &<60;
&<60;&<60; &<60; &<60; &<60;Options ExecCGI
&<60;&<60; &<60;

重启服务器
sudo /etc/init.d/apache2 restart

搞定。

说明:PHP 程序放 /var/www/ 下面都可以,CGI 程序放 /var/www/cgi-bin/ 下面。

是不是太简单了,除去下载的时间,要不了一分钟就可以完成配置,在 Ubuntu 上还需要 APM 包吗?还是记住以下几个命令和位置就行了。

sudo /etc/init.d/apache2 restart (重启 apache)
sudo gedit /etc/php5/apache2/php.ini (配置 php.ini)
sudo gedit /etc/apache2/apache2.conf (配置 apache2.conf)
/var/www/(主目录位置)

分享到:
share

    图片原图

    loading

    loading