2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > LNMP和LAMP的编译安装

LNMP和LAMP的编译安装

时间:2023-01-15 15:49:18

相关推荐

LNMP和LAMP的编译安装

为什么80%的码农都做不了架构师?>>>

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

Shell>sudoapt-getinstallbuild-essentia;

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

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

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

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

4.安装,使用makeinstall

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

安装libxml2

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

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

2.使用make编译

3.使用makeinstall安装

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

安装libmcrypt

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

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

2.使用make编译

3.使用makeinstall安装

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

安装zlib

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

安装libpng

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

安装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;makeinstall

安装freetype

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

安装autoconf

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

Shell>apt-getinstallm4

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

安装gd

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

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

安装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;makeinstall

检测是否安装成功,启动apache:/usr/local/apache/bin/apachectlstart查找进程,如果有则安装成功psaux|grephttpd

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

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

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

安装mysql

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

安装ncurses

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

2.创建用户和用户组

Shell>groupaddmysql

Shell>useradd-gmysqlmysql

3.开始安装mysql

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

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

Shell>cpmy-f/etc/f

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

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

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

Shell>chown-Rroot/usr/local/mysql

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

Shell>chgrp-Rmysql/usr/local/mysql

7.启动mysql

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

8.检查是否启动了

Shell>psaux|grepmysql

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

Shell>./mysqladminvariables

然后设置密码

Shell>./mysqladmin-urootpasswordxiaozhe

9.设置开机自动启动

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

echo"/usr/local/apache2/bin/apachectlstart">>/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>chownroot.root/etc/rc.d/init.d/mysqld

Shell>chmod755/etc/rc.d/init.d/mysqld

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

chkconfig--addmysqld

chkconfig--listmysqld

修改运行的等级

chkconfig--levels245mysqldoff

安装php

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

Shell>gzip-cdphp-fpm.gz|patch-dphp-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;makeinstall

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

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

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

Shell>vim/etc/httpd/httpd.conf

添加AddTypeapplication/x-httpd-php.php.phtml

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

Shell>/usr/local/apache2/bin/apachectlrestart

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

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

安装zend加速器

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

后面一切按配置自己修改

安装phpMyadmin

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

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

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

Shell>cpconfig.sample.inc.phpconfig.inc.php

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

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

LNMP的安装

安装nginx

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

Shell>sudoapt-getinstallzlib1gopenssllibssl-devlibpcre3libpcre3-dev

2.编译安装nginx:

Shell>./configure\

--prefix=/usr/local/nginx\

--with-http_stub_status_module\

--with-http_ssl_module

Shell>make

Shell>makeinstall

3.启动nginx:

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

4.测试nginx:

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

显示“Welcometonginx!”表示nginx安装成功

安装spawn-fcgi

1.Shell>sudoapt-getinstallspawn-fcgi

2.执行spawn-fcgi

shell>/usr/bin/spawn-fcgi.standalone-a127.0.0.1-p9000-C8-uwww-data-gwww-data-f/usr/local/php/bin/php-cgi-P/var/run/fastcgi-php.pid

Nginx和php的整合:

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

添加index.php

location/{

roothtml;

indexindex.htmlindex.htmindex.php;

}

2.开启fastcgi执行php文件

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

roothtml;

fastcgi_pass127.0.0.1:9000;

fastcgi_indexindex.php;

#fastcgi_paramSCRIPT_FILENAMEhtml$fastcgi_script_name;

#includefastcgi_params;

includefastcgi.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-a127.0.0.1-p9000-C8-uwww-data-gwww-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

forTARin`catfile_name`

do

tar-xvf$TAR-C/opt/build_lamp

done

rmfile_name

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。