加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

超详细LAMP环境手动编译安装实例

发布时间:2022-03-14 19:05:29 所属栏目:编程 来源:互联网
导读:LAMP编译安装实例: 一: HTTPD编译安装: 下载软件包: # wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.gz http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.1.tar.gz http://mirrors.shu.edu.cn/apache//httpd/httpd-2.4.29.tar.gz 需
         LAMP编译安装实例:
 
   一: HTTPD编译安装:
 
        下载软件包:
 
      
# wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.gz http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.1.tar.gz http://mirrors.shu.edu.cn/apache//httpd/httpd-2.4.29.tar.gz
            需要依赖最新版apr和apr-util
 
            apr:Apache Porttable Runtime:
 
            可移植Apache运行环境,用于把C语言编写的Apache程序运行在不同的操作系统上,即有Windows版本也有Linux版本
 
            apr-util:apr工具
 
        安装开发环境,确保Development tools
 
# yum grouplist # 查看是否安装
# yum groupinstall "Development Tools"
        安装apr:
 
# tar xf apr-1.6.3.tar.gz
# cd apr-1.6.3
# ./configure --prefix=/usr/local/apr
# make
# make install
        安装apr-util:
 
# tar xf apr-util-1.5.1.tar.gz # 1.6的会报错,用1.5.1的
# cd apr-util-1.5.1
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr # 需要指定刚才安装的apr的路径
# make
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/lee/software/apr-util-1.5.1'
make: *** [all-recursive] Error 1
            若报以上错误安装下面的devel包
 
# yum install expat-devel
# make&make install
        安装httpd:
 
            # ./configure --hlep 查看常用选项:
 
                 --sysconfdir=DIR//指定配置文件路径
 
                 --enable-so//支持动态共享模块,必加项,用于以模块的方式让php与apache结合工作
 
                 --enable-proxy-fcgi//用于以fcgi(fastcgi)的方式让php与apache结合工作
 
                 --enable-cgi //用于以cgi的方式让php与apache结合工作
 
                            apache与php结合工作的几种方式:
 
                            模块:php以模块的形式集成在httpd中,httpd和php一个进程
 
                            CGI:httpd用CGI和php交互,php独立创建进程(好像是tcp9000),由httpd创建、管理php的进程
 
                            FCGI:php完全独立了,自己单独的服务器,自己预先创建进程,自己管理进程
 
                --enable-ssl//支持ssl,用于需要启用https的站点
 
                --enable-deflate//支持压缩,即压缩后发送给客户端浏览器,浏览器再解压缩,节省流量
 
                --enable-mpms-shared=MPM-LIST//定义要启用的httpd支持的MPM模式(多道处理模块)event|worker|prefork|winnt|all
 
                --with-mpm=MPM //定义MPM后设定默认的MPM模式(MPM={event|worker|prefork|winnt}),2.4默认event
 
                            MPM的几种模式:
 
                            event:一个进程(内部生成多个线程)来响应多个请求,进程通过事件驱动(轮询和通知)的机制来确定内部线程的处理状态
 
                            worker:一个进程生成多个子进程(线程)来响应多个请求
 
                            prefork:一个进程响应一个请求
 
                --enable-cgid//CGI scripts. Enabled by default with threaded MPMs(线程方式event|worker的MPM模式时必须启用)
 
                --enable-rewrite//支持URL重写,就是重定向啦
 
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewirte --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
        
报错:configure: error: pcre-config for libpcre not found. PCRE is required and available from   # 缺少pcre-devel
# yum -y install pcre-devel
# make
# make install
        Apache编译安装默认的目录:
 
            bin:二进制文件(启动脚本是此目录下的apachectl)    
 
            cgi-bin:CGI程序的存放目录
 
            htdocs:网页的存放目录
 
            man:帮助文档
 
            modules:模块目录
 
            error:错误信息
 
            icons:图标  
 
            logs:日志文件
 
            manual:官方手册
 
        编译安装的默认pid文件放在了/usr/local/apache/logs下了,最好改一下位置:
 
# vim /etc/httpd/httpd.conf
PidFile "/var/run/httpd.pid" # 加这一行内容
# /usr/local/apache/apachectl start # 启动服务
        可选配置:
 
        让service命令识别启动脚本:
 
 # ln -s /usr/local/apache/bin/apachectl /etc/init.d/httpd
        让系统能够直接识别/usr/local/apache/bin/下的命令:
 
            方法一:
 
# ln -s /usr/local/apache/bin/* /usr/bin # 软链接到某一个PATH变量目录中
            方法二:
 
# vim /etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/apache/bin # 编辑一个开机启动脚本,追加PATH变量
        加入开机自启动:
 
            方法一:
 
# vim /etc/rc.d/rc.local
/usr/local/apache/bin/apachectl start # 开机启动
            方法二:让chkconfig识别(略)
 
    二:MYSQL(通用二进制包)安装:
 
        下载软件包:
 
# wget https://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.58-linux-glibc2.12-i686.tar.gz
        解压:
 
# tar xf mysql-5.5.58-linux-glibc2.12-i686.tar.gz
        复制到想要安装的目录并重命名:
 
# cp -rf mysql-5.5.58-linux-glibc2.12-i686/* /usr/local/mysql/
# cd /usr/local/mysql/
        具体安装方法在这个文件中有说明:
 
# more INSTALL-BINARY
        创建系统用户mysql:
 
# useradd -r mysql
        将mysql目录所有文件改变属主和属组为mysql
 
# chown -R mysql.mysql /usr/local/mysql/
        手动执行初始化脚本:
 
        # /usr/local/mysql/scripts/mysql_install_db  --help # 初始化脚本配置文件主要选项
 
            --user=user_name:以哪个用户的身份进行初始化
 
            --datadir=path:数据存放目录,默认就在安装目录下的data目录
 
# /usr/local/mysql/scripts/mysql_install_db --user=mysql # 初始化
        服务启动脚本:
 
# cp support-files/mysql.server /etc/init.d/mysqld # 复制到service管理目录下并重命名
# chkconfig --add mysqld
# chkconfig mysqld on
        MYSQL配置文件:
 
            mysql/support-files/目录下有多个针对实际硬件情况的配置文件可选:
 
# ls /usr/local/mysql/support-files/
my-huge.cnfmy-large.cnfmy-small.cnf
# more my-large.cnf
# Example MySQL config file for large systems.
#
# This is for a large system with memory = 512M where the system runs mainly # 内存512左右可以选这个配置文件
# MySQL.
datadir=YOURPATH # 注意,如果在初始化时指定了data目录,这里要加这个参数
# cp support-files/my-large.cnf /etc/my.cnf # 复制配置文件并重命名,mysql默认在这个目录下找my.cnf的配置文件
        启动mysqld服务:
 
# service mysqld start
        照例追加mysql/bin到PATH,让系统识别命令:
 
# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin # 追加变量
        非必须选项:
 
# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib # 输出库文件,让系统读取mysql的库文件
# ldconfig -v # 重新读取库文件
# ln -sv /usr/local/mysql/include /usr/include/mysql # 输出头文件,让系统读取mysql的头文件
  
 
    三:编译安装PHP:
 
        下载软件包并解压:
 
# wget http://cn2.php.net/distributions/php-5.6.33.tar.gz
# tar xf php-5.6.33.tar.gz
# cd /lee/software/php-5.6.33
        编译:
 
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts
            #--with-apxs2=/usr/local/apache/bin/apxs:其中这一项是以模块的方式与apche工作,如果要以fcgi方式则用:--enable-fpm(注意两项不能共存)
 
            ./configure时报错yum安装对应的软件包和devel包一般可以解决,但有些软件包yum是没有的,需要手动下载rpm包安装:
 
# wget http://rpmfind.net/linux/dag/redhat/el6/en/i386/dag/RPMS/libmcrypt-2.5.7-1.2.el6.rf.i686.rpm
# rpm -ivh libmcrypt-2.5.7-1.2.el6.rf.i686.rpm
# wget http://rpmfind.net/linux/dag/redhat/el6/en/i386/dag/RPMS/libmcrypt-devel-2.5.7-1.2.el6.rf.i686.rpm
# rpm -ivh libmcrypt-devel-2.5.7-1.2.el6.rf.i686.rpm
# make
# make install
        复制配置文件到刚才configure时指定的配置文件目录:
 
# cp php.ini-production /etc/php.ini
        编辑Apache的配置文件,让apache能支持php(PHP以apache模块的方式工作):
 
# vim /etc/httpd/httpd.conf
             1、添加如下二行
 
               AddType application/x-httpd-php  .php
 
               AddType application/x-httpd-php-source  .phps
 
             2、定位至DirectoryIndex index.html
 
               修改为:
 
            DirectoryIndex  index.php  index.html
 
# httpd -t # 修改完检查下语法
# service httpd restart # 重启服务重读配置文件
    
 
    四:测试PHP和Apache工作情况:
 
# mv index.html index.html.bak//让默认的html主页失效
# vim index.php
<html><title>鄂C王思聪PHP测试</title> <body><h2>PHP TEST</h2></body></html>
<?php
phpinfo();
?> # 这个是PHP内置函数,用于测试PHP
        完成后可以在浏览器中打开测试一下了
 
   
 
    五:测试MYSQL和PHP工作情况:
 
# vim mysql.php
<html><title>鄂C王思聪MYSQL测试</title> <body><h2>MYSQL TEST</h2></body></html>
<?php
$conn=mysql_connect(`localhost`,`root`,``);
if ($conn)
echo "SUCCESS";
else
echo "FAILURE";
?>
        完成后浏览器中打开mysql.php测试下,显示SUCCESS表示成功。

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读