您的位置:首页 > 其它

LNMP和LAMP的编译安装

2012-11-26 22:59 281 查看
在编译这些源码包之前,我们需要确认系统中有gcc,gcc-c++,make编译器,一般系统都自带了gcc和make编译器,所以我们只要安装gcc.

Shell> sudo apt-get install build-essentia ;

一般安装一个源码包的过程是:

1.解压源码包的tar.gz文件,如 tar -xvf mysql.tar.gz -C /opt/lamp,其中tar命令中的-C是指定解压路径.其实我们完全可以写一个shell脚本进行解压.

2.配置源码,使用命令 ./configure

3.编译源码,使用命令 make

4.安装,使用 make install

现在我们开始安装lamp环境,在此之前,我们需要安装一系列的必须库.

安装libxml2

1.进入libxml2源码包目录,进行配置设置安装的路径

Shell> ./configure --prefix=/usr/local/libxml2

2.使用make编译

3.使用make install 安装

注:在编译libxml2时,由于nanohttp.c中的open函数有问题,所以我们需要修改nanohttp.c的源代码,在1588行给open加上第三个参数0777就行了.

安装libmcrypt

1.进入libmcrypt源码包目录,进行配置设置安装

Shell> ./configure --prefix=/usr/local/libmcrypt

2.使用make编译

3.使用make install安装

4.但是需要注意的是在此目录下还有一个libltdl目录,里面的源码也需要进行编译.执行如下命令 ./configure --enable-ltdl-install ; make ; make install .

安装zlib

因为这个库是很多库安装必须要的,所以建议安装这个库的时候,按照默认的安装路径即可.执行如下命令 ./configure ; make ; make install

安装libpng

因为前面我们安装的zlib使用的是默认路径安装,所以这个配置就不需要指定zlib目录了,直接执行如下命令 ./configure --prefix=/usr/local/libpng ; make ; make install

安装jpeg-6b

因为这个在安装的过程中不能自动创建目录,所以我们必须提给它安装好必须的目录.

Shell> mkdir /usr/local/jpeg6

Shell> mkdir /usr/local/jpeg6/bin

Shell> mkdir /usr/local/jpeg6/lib

Shell> mkdir /usr/local/jpeg6/include

Shell> mkdir -p /usr/local/jpeg6/man/man1 这里-p表示递归创建man目录后再创建man1目录

然后开始配置,编译,安装命令如下 ./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static ; make ; make install

安装freetype

按顺序配置,编译和安装: ./configure --prefix=/usr/local/freetype ; make ; make install

安装autoconf

1.在安装之前我们需要在ubuntu10.10中安装m4

Shell>apt-get install m4

2.同zlib一样,建议按默认安装路径执行. 命令如下: ./configure ; make ; make install

安装gd

在安装这个库的时候,我们需要指定前面的3个库jpeg6,freetype和zlib.但是由于zlib是默认路径,就不需要特指出来.命令如下

./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6 --with-freetype=/usr/local/freetype ; make ; make install

安装httpd(apache)

./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd/ --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support ; make ; make install

检测是否安装成功,启动apache: /usr/local/apache/bin/apachectl start 查找进程,如果有则安装成功 ps aux | grep httpd

最后在浏览器上输入你的IP地址看是否成功.

注:有很多教程就在配置的时候加了 --with-z=/usr/local/zlib,但是因为我们已经把zlib安装在默认路径,所以在这里我们就不必加了。

如果在我们执行的时候,提示mod_rewrite.so或更多模块没有权限启动.则我们可以用这个命令解决:chcon -t texrel_shlib_t /usr/local/apache/modules/mod_name

安装mysql

1.在安装mysql的过程中,很容易出错,因为在安装mysql之前,我们必须要先安装编译一个ncurses.

安装ncurses

./configure --with-shared --without-debug --without-ada --enable-overwrite ; make ; make install

2.创建用户和用户组

Shell> groupadd mysql

Shell> useradd -g mysql mysql

3.开始安装mysql

./configure --prefix=/usr/local/mysql --with-extra-charsets=all ; make ; make install

4.把mysql源码里面support-files目录下的配置文件复制到/etc/目录下,生成配置文件

Shell> cp my-medium.cnf /etc/my.cnf

5.创建mysql数据库的授权表

Shell> /usr/local/mysql/bin/mysql_install_db --user=mysql

6.然后修改mysql数据目录的拥有者和拥有组

Shell> chown -R root /usr/local/mysql

Shell> chown -R mysql /usr/local/mysql/var

Shell> chgrp -R mysql /usr/local/mysql

7.启动mysql

Shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &

8.检查是否启动了

Shell> ps aux | grep mysql

可以使用mysqladmin查看所有的参数

Shell> ./mysqladmin variables

然后设置密码

Shell> ./mysqladmin -uroot password xiaozhe

9.设置开机自动启动

我们可以把这些启动命令写入系统每次开机时读取的文件如/etc/rc.d/rc.local,然后执行如下命令:

echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local

或者贝源码中自带的一个mysql.server文件拷贝到init.d目录下,可以重新取名.

Shell>cp /opt/lamp/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld

修改这个文件的权限和所有权

Shell> chown root.root /etc/rc.d/init.d/mysqld

Shell> chmod 755 /etc/rc.d/init.d/mysqld

使用chkconfig命令,没用过,我要学习这个命令

chkconfig --add mysqld

chkconfig --list mysqld

修改运行的等级

chkconfig --levels 245 mysqld off

安装php

1.如果是Nignx服务器,必须先下载php-fpm(既cgi,在配置中必须激活),然后把fpm加载入php安装文件夹中,如下:

Shell>gzip -cd php-fpm.gz | patch -d php-5.2.10 -p1

2.进行配置,编译和安装

./configure

--prefix=/usr/local/php

--with-config-file-path=/usr/local/php/etc/

--with-apxs2=/usr/local/apache2/bin/apxs #apache的配置

--with-mysql=/usr/local/mysql/

--with-libxml-dir=/usr/local/libxml2/

--with-jpeg-dir=/usr/local/jpeg6/

--with-freetype-dir=/usr/local/freetype/

--with-gd=/usr/local/gd2/

--with-mcrypt=/usr/local/libmcrypt/

--with-mysqli=/usr/local/mysql/bin/mysql_config #加载mysqli

--enable-soap

--enable-mbstring=all

--enable-sockets

--enable-fastcgi #Nignx的配置,激活cgi

--enable-fpm #Nignx的配置,激活cgi

make ; make install

3.将php源码包里面的配置文件复制到php配置目录里面

Shell> cp php.ini-dist /usr/local/php/etc/php.ini

4.修改apache配置文件增加执行php

Shell> vim /etc/httpd/httpd.conf

添加AddType application/x-httpd-php .php .phtml

5.重启服务器或先stop然后start

Shell> /usr/local/apache2/bin/apachectl restart

5.写一个php文件测试一下

vim /usr/local/apache2/htdocs/phpinfo.php

安装zend加速器

直接进入ZendOptimizer加速器目录,然后 ./install.sh

后面一切按配置自己修改

安装phpMyadmin

1.直接将phpmyadmin文件夹复制到htdocs目录下

Shell>cp -a phpMyAdmin-3.0.0-rc1-all-languages /usr/local/apache2/htdocs/phpmyadmin

2.进入phpmyadmin目录,重命名配置文件

Shell> cp config.sample.inc.php config.inc.php

3.修改配置文件,将auth_type为http即可

4.然后在浏览器打开phpmyadmin 找到index文件点进即可

LNMP的安装

安装nginx

1.在安装nginx之前先安装pcre,openssl等

Shell>sudo apt-get install zlib1g openssl libssl-dev libpcre3 libpcre3-dev

2.编译安装nginx:

Shell> ./configure \

--prefix=/usr/local/nginx \

--with-http_stub_status_module \

--with-http_ssl_module

Shell>make

Shell>make install

3.启动nginx:

Shell>/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

4.测试nginx:

安装完成后,在浏览器中输入:http://ip地址

显示“Welcome to nginx!”表示nginx安装成功

安装spawn-fcgi

1.Shell>sudo apt-get install spawn-fcgi2.执行spawn-fcgi

shell>/usr/bin/spawn-fcgi.standalone -a 127.0.0.1 -p 9000 -C 8 -u www-data -g www-data -f /usr/local/php/bin/php-cgi -P /var/run/fastcgi-php.pid

Nginxphp的整合:

1,修改nginx.confi 配置文件:

添加index.php

location / {

root html;

index index.html index.htm index.php ;

}

2.开启fastcgi执行php文件

location ~ .*\.(php|php5)?$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

#fastcgi_param SCRIPT_FILENAME html$fastcgi_script_name;

#include fastcgi_params;

include fastcgi.conf;

}

3.在/usr/local/nginx/html/下建立php测试页面文test.php

添加下面代码:

<?php

phpinfo();

?>

4.重新加载nginx配置文件(不用重启服务,重新加载配置文件平滑过渡)

测试配置文件,提示下面两条信息,表示没问题

Shell>/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

重新加载配置文件

Shell>Kill –HUP ‘cat /usr/local/nginx/logs/nginx.pid’

4,测试:

http://192.168.0.250/test.php,显示php信息,表示整合成功。

在/etc/rc.d/rc.local下添加下面两条信息,设置开机启动

1./usr/bin/spawn-fcgi.standalone -a 127.0.0.1 -p 9000 -C 8 -u www-data -g www-data -f /usr/local/php/bin/php-cgi -P /var/run/fastcgi-php.pid

2./usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

附上解压的shell命令

#!/bin/bash

cd /opt/Linux

ls *.tar.gz > file_name

for TAR in `cat file_name`

do

tar -xvf $TAR -C /opt/build_lamp

done

rm file_name
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: