LAMP搭建

#Apache安装步骤

        1、检查是否已经安装rpm包httpd

                        rpm -q httpd         \\查看是否已经安装

                        rpm -e httpd --nodeps        \\卸载已安装的程序

        2、安装前提软件

            下载软件光盘:

    链接:https://pan.baidu.com/s/17O_CdGupHSGdqO6-NxIqLw 
        提取码:bel1

        把软件镜像内容复制到系统的/usr/src/目录下或直接下载到虚拟机

        如果编译安装无法执行,可能是开发软件工具没有安装,需要先安装开发软件:

        yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel

进入/usr/src/目录下

cd /usr/src
tar zxf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr && make && make install

cd ..
tar zxf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install

cd ..
yum -y install zlib-*

tar zxf pcre-8.39.tar.gz
cd pcre-8.39
./configure --prefix=/usr/local/pcre && make && make install

cd ..
tar zxf openssl-1.0.1u.tar.gz
cd openssl-1.0.1u
./config -fPIC --prefix=/usr/local/openssl enable-shared && make && make install

                                            ------安装顺序依次执行安装
.安装Apache主程序
cd /sh
vim httpd.sh
添加:
#!/bin/bash
cd /usr/src
tar zxf httpd-2.4.25.tar.gz
cd httpd-2.4.25
./configure --prefix=/usr/local/httpd --enable-so --enable-cgi --enable-cgid --enable-ssl --with-ssl=/usr/local/openssl --enable-rewrite --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event --enable-proxy --enable-proxy-fcgi --enable-expires --enable-deflate && make && make install

优化连接:

ln -s /usr/local/httpd/bin/* /usr/local/bin

添加系统服务
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
vim /etc/init.d/httpd
定位到第二行:修改为
# chkconfig: 35 85 15            \\声明服务启动级别,开机启动顺序,关机关闭顺序
# description: apache 2.4.25    \\服务声明,简要信息
保存退出
chkconfig --add httpd            \\添加httpd到系统服务
chkconfig httpd on                \\设置服务开机自启(等同于:systemctl enable httpd)
systemctl start httpd            \\开启服务(等同于:service httpd start)

查看httpd模块
httpd -V    \\查看版本和已装模块
httpd -l    \\只查看静态编译模块
httpd -M     \\查看所有模块

MPM(Multi Process Modules):多进程处理模块
    负责实现网络监听、请求的处理等功能,目的为了在不同的平台上实现最优化的性能和稳定性。
    操作系统平台            MPM
        BeOS                beos
        NetWare                mpm_netware
        OS/2                mpm_os2
        linux                prefork、worker、event
        Windows                mpm_winnt
    
prefork模式:
    非线程、预生成进程型MPM,一个子进程同一时间点仅能处理一个用户请求,根据并发请求数动态调整子进程
  worker模式:
    线程化、多进程型MPM,每个进程可生成多个线程,每个线程处理一个请求,缺点:长连接,资源容易被占用
  event模式:
    worker的改进版,使用监控线程处理长连接出现的资源占用问题

修改mpm配置文件
vim /usr/local/httpd/conf/extra/httpd-mpm.conf
<IfModule mpm_event_module>
StartServers 3                 #apache 启动时候默认开始的子进程数
MinSpareThreads 75            #最小空闲数量的工作线程
MaxSpareThreads 250            #最大空闲数量的工作线程
ThreadsPerChild 25            #每个子进程产生的线程数量
MaxRequestWorkers 400        #允许同时的最大接入请求数量
MaxConnectionsPerChild 0    #每个子进程可处理的请求数
</IfModule>

#企业推荐参数
<IfModule mpm_worker_module>
StartServers          2 #推荐设置:小=默认 中=3~5 大=5~10
MaxClients          150 #推荐设置:小=500 中=500~1500 大型=1500~3000
MinSpareThreads      25 #推荐设置:小=默认 中=50~100 大=100~200
MaxSpareThreads      75 #推荐设置:小=默认 中=80~160 大=200~400 ThreadsPerChild      25 #推荐设置:小=默认 中=50~100 大型=100~200
MaxRequestsPerChild   0 #推荐设置:小=10000 中或大=10000~50000(此外,如果MaxClients/ThreadsPerChild大于16,还需额外设置ServerLimit参数,ServerLimit必须大于等于 MaxClients/ThreadsPerChild 的值。)
</IfModule>

9.使用ab命令进行压力测试
yum -y install httpd-tools
ab -c 160 -n 10000 http://192.168.1.102/index.html   
使用ab压力测试命令进行160人并发访问,发出10000个请求。

二、安装mysql
1.复制mysql5.6-rpm到虚拟机/root
cd /root/mysql5.6-rpm
yum -y localinstall *.rpm
systemctl start mysqld
systemctl enable mysqld

三、安装php
1.安装前提软件
 yum -y install epel-release
 yum -y install gcc gcc-c++ libxml2-devel lzip2-devel libcurl-devel libmcrypt-devel openssl-devel bzip2-devel

2.复制libmcrpt和php包到/usr/src,安装libmcrypt加密工具
cd /usr/src
tar zxf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7/
./configure --prefix=/usr/local/libmcrypt && make && make install

3.安装php
cd /usr/src
tar zxf php-5.6.27.tar.gz 
cd php-5.6.27/
./configure --prefix=/usr/local/php5.6 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts && make && make install

4.提供 php 配置文件
cp /usr/src/php-5.6.27/php.ini-production /etc/php.ini

5.为 php-fpm 提供脚本
cd /usr/src/php-5.6.27/
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm 
chkconfig --add php-fpm
chkconfig php-fpm on

6.提供 php-fpm 配置文件并编辑
cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf


7.启动php-fpm服务
systemctl start php-fpm

四.测试Apache与php的静/动分离
1.启用Apache服务的代理转发
vim /usr/local/httpd/conf/httpd.conf
找到下面三行,去除#号:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
Include conf/extra/httpd-vhosts.conf

找到AddType所在行,添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

定位至 DirectoryIndex,改为:
DirectoryIndex index.php index.htm
保存退出
systemctl restart httpd

2.配置虚拟主机文件
 vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
改为:
<VirtualHost *:80>
 ServerAdmin webmaster@benet.com
 DocumentRoot "/var/www/benet"
 ServerName www.benet.com
 ServerAlias benet.com
 ErrorLog "logs/benet.com-error_log"
 CustomLog "logs/benet.com-access_log" common
 ProxyRequests Off
 ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/benet/$1

<Directory "/var/www/benet">
 Options FollowSymLinks
 AllowOverride None
 Require all granted
</Directory>
</VirtualHost>
保存退出

3.测试
(1)mysql服务器,创建测试数据库用户
mysql    \\登录数据库命令
grant all on *.* to testuser@'%' identified by '123456';

(2)在 php 服务器上的/var/www/benet 目录下创建.php 的测试页:
vim  /var/www/benet/index.php 
添加:
<?php
phpinfo();
?>
保存退出

vim /var/www/benet/test1.php 
添加:
<?php
$link=mysql_connect('192.168.1.102','testuser','123456');
if ($link)echo "connection success......";
mysql_close();
?>
保存退出

(3)在mysql服务器上测试访问Apache,会出现php内容

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值