手动搭建lamp架构

#lamp平台搭建:
*环境说明:

系统平台 ip地址 需要安装的服务
centos7 192.168.110.128 httpd-2.4 mysql-5.7 php php-mysql

一.安装httpd:
#安装开发工具:

[[email protected] ~]# yum groups mark install ‘Development Tools‘
安装过程已省略

#创建apache用户和组:

[[email protected] ~]# groupadd -r apache
[[email protected] ~]# useradd -r -M -s /sbin/nologin -g apache apache 

#安装依赖包:

[[email protected] ~]# yum -y install openssl-devel pcre-devel expat-devel lib tool
安装过程已省略。

#下载和安装arp和arp-util:

[[email protected] ~]# cd /usr/src/
[[email protected] src]wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.
tar.bz2

下载过程已省略

[[email protected] src]#wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1
.6.1.tar.bz2

下载过程已省略
#解压apr和apr-util:

[[email protected] src]# ls
apr-1.6.3.tar.bz2 apr-util-1.6.1.tar.bz2 debug kernels
[[email protected] src]# tar xf apr-1.6.3.tar.bz2
[[email protected] src]# tar xf apr-util-1.6.1.tar.bz2
[[email protected] src]# ls
apr-1.6.3 apr-1.6.3.tar.bz2 apr-util-1.6.1 apr-util-1.6.1.tar.bz2 debug
 kernels
[[email protected] src]# cd apr-1.6.3
[[email protected] apr-1.6.3]# vim configure
 cfgfile="${ofile}T"
 trap "$RM \"$cfgfile\"; exit 1" 1 2 15
 #$RM "$cfgfile"       #将此行加上注释或者删除此行

#配置编译apr和apr-util:

[[email protected] apr-1.6.3]# ./configure --prefix=/usr/local/apr
配置过程省略
[[email protected] apr-1.6.3]# make && make install
编译过程省略
[[email protected] apr-1.6.3]# cd /usr/src/apr-util-1.6.1
[[email protected] apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util -
-with-apr=/usr/local/apr
配置过程略
[[email protected] apr-util-1.6.1]# make && make install
编译过程略

#下载编译安装httpd:

[[email protected] ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.3
4.tar.bz2
下载过程略
[[email protected] ~]# ls
httpd-2.4.34.tar.bz2
[[email protected] ~]# tar xf httpd-2.4.34.tar.bz2
[[email protected] ~]# cd httpd-2.4.34
[[email protected] httpd-2.4.34]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[[email protected] httpd-2.4.34]# make && make install
编译过程略

#安装后配置:

[[email protected] ~]# echo ‘PATH=/usr/local/apache/bin:$PATH‘ > /etc/profile.
d/httpd.sh
[[email protected] ~]# source /etc/profile.d/httpd.sh
[[email protected] ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[[email protected] ~]# echo ‘MANPATH /usr/local/apache/man‘ >> /etc/man.config

#在主配置文件取消ServerName的注释?:

[[email protected] ~]#sed -i ‘/#ServerName/s/#//g‘ /etc/httpd24/httpd.conf 

#关闭防火墙,启动apache:

[[email protected] ~]#systemctl stop firewalld
[[email protected] ~]#setenforce 0
[[email protected] ~]# apachectl start

二.安装mysq:
#安装依赖包:

[[email protected] ~]# yum -y install ncurses-devel openssl-devel openssl cmak
e mariadb-devel

#创建用户和组:

[[email protected] src]# groupadd -r -g 306 mysql
[[email protected] src]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql

#下载二进制格式的mysql软件包:

[[email protected] ~]# cd /usr/src/
[[email protected] src]# wget https://downloads.mysql.com/archives/get/file/my
sql-5.7.22-linux-glibc2.12-x86_64.tar.gz    下载过程略

#解压至/usr/local/

[[email protected] src]# ls
debug kernels mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[[email protected] src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C
/usr/local/
[[email protected] ~]# ls /usr/local/
bin games lib libexec sbin src

#做一个软连接:

[[email protected] local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
‘mysql’ -> ‘mysql-5.7.22-linux-glibc2.12-x86_64/’

#修改/usr/local/my属主属组:

[[email protected] ~]# chown -R mysql.mysql /usr/local/mysql
[[email protected] ~]# ll /usr/local/mysql -d
lrwxrwxrwx 1 mysql mysql 36 Aug 14 16:00 /usr/local/mysql -> mysql-5.7.22-l
inux-glibc2.12-x86_64/

#添加环境变量:

[[email protected] ~]# ls /usr/local/mysql
bin COPYING docs include lib man README share support-files
[[email protected] ~]# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/pr
ofile.d/mysql.sh
[[email protected] ~]# . /etc/profile.d/mysql.sh
[[email protected] ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/roo
t/bin

#建立数据库存放目录:

[[email protected] mysql]# mkdir /opt/data
[[email protected] mysql]# chown -R mysql.mysql /[[email protected] mysql]# ll /opt/
total 0
drwxr-xr-x 2 mysql mysql 6 Aug 14 16:54 data

#初始化数据库:

[[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
[[email protected] src]# echo ‘ri9woXLadi,G‘ >/root/a

#配置mysql并生成配置文件:

[[email protected] ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[[email protected] ~]# echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf
[[email protected] ~]# ldconfig -v

#生成配置文件:

[[email protected] ~]# cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF

#配置服务启动脚本:

[[email protected] ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~]# sed -ri ‘s#^(basedir=).*#\1/usr/local/mysql#g‘ /etc/init.d/mysqld
[[email protected] ~]# sed -ri ‘s#^(datadir=).*#\1/opt/data#g‘ /etc/init.d/mysqld

#启动mysql服务:

[[email protected] ~]# service mysqld start
Starting MySQL.. SUCCESS!
[[email protected] ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port
LISTEN      0      128          *:22                       *:*
LISTEN      0      100    127.0.0.1:25                       *:*
LISTEN      0      128         :::80                      :::*
LISTEN      0      128         :::22                      :::*
LISTEN      0      100        ::1:25                      :::*
LISTEN      0      80          :::3306                    :::*  

#登入mysql修改密码:

[[email protected] local]# mysql -uroot -p‘ri9woXLadi,G‘
mysql> set password=password(‘123.com‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)

三.安装php:
#安装依赖包:

[[email protected] ~]# yum -y install libxml2 libxml2-devel openssl openssl-de
vel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng li
bpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel
readline readline-devel libxslt libxslt-devel mhash mhash-devel
安装过程略

#下载php:

[[email protected] ~]# cd /usr/src/
[[email protected] src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz

#编译安装php:

[[email protected] src]# tar xf php-7.2.8.tar.xz
[[email protected] src]# cd php-7.2.8
[[email protected] php-7.2.8]# ./configure --prefix=/usr/local/php7 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir=/usr --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-jpeg-dir --with-png-dir --with-xmlrpc --with-xsl --with-zlib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
[[email protected] php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc
-l)
编译过程略
[[email protected] php-7.2.8]# make install
安装过程略
#安装后配置:
[[email protected] ~]# echo ‘export PATH=/usr/local/php7/bin:$PATH‘ > /etc/profile.d/php7.sh
[[email protected] ~]# source /etc/profile.d/php7.sh
[[email protected] php-7.2.8]# which php
/usr/local/php7/bin/php
[[email protected] php-7.2.8]# php -v
PHP 7.2.8 (cli) (built: Aug 16 2018 13:27:30) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

#配置php-fpm:

[[email protected] php-7.2.8]# cp php.ini-production /etc/php.ini
[[email protected] php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[[email protected] php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /us
r/local/php7/etc/php-fpm.conf
[[email protected] php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.defau
lt /usr/local/php7/etc/php-fpm.d/www.conf

#编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf)
配置fpm的相关选项为你所需要的值:

[[email protected] ~]# vim /usr/local/php7/etc/php-fpm.conf
pm.max_children = 50   /最多同时提供50个进程提供50个并发服务
pm.start_servers = 5               //启动时启动5个进程
pm.min_spare_servers =2      //最小空闲进程数
pm.max_spare_servers = 8    //最大空闲进程数
[[email protected] ~]# tail /usr/local/php7/etc/php-fpm.conf
; file.
; Relative path can also be used. They will be prefixed by:
; - the global prefix if it‘s been set (-p argument)
; - /usr/local/php7 otherwise
include=/usr/local/php7/etc/php-fpm.d/*.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8

#启动php服务:

[[email protected] ~]# service php-fpm start
Starting php-fpm done
[email protected] src]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port
LISTEN     0      128       127.0.0.1:9000                          *:*
LISTEN     0      128               *:22                            *:*
LISTEN     0      100       127.0.0.1:25                            *:*
LISTEN     0      80               :::3306                         :::*
LISTEN     0      128              :::80                           :::*
LISTEN     0      128              :::22                           :::*
LISTEN     0      100             ::1:25                           :::*
[[email protected] ~]# ps -ef | grep php
root      67777      1  0 09:32 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody    67778  67777  0 09:32 ?        00:00:00 php-fpm: pool www
nobody    67779  67777  0 09:32 ?        00:00:00 php-fpm: pool www
nobody    67780  67777  0 09:32 ?        00:00:00 php-fpm: pool www
nobody    67781  67777  0 09:32 ?        00:00:00 php-fpm: pool www
nobody    67782  67777  0 09:32 ?        00:00:00 php-fpm: pool www
root      67785   2020  0 09:32 pts/2    00:00:00 grep --color=auto php

四.配置虚拟主机:
#启动ttpd相关的模块:

[[email protected] ~]# sed -i ‘/proxy_module/s/#//g‘ /etc/httpd24/httpd.conf
[[email protected] ~]# sed -i ‘/proxy_fcgi_module/s/#//g‘ /etc/httpd24/httpd.conf

#在需要使用的cfgi的虚拟主机中添加如下两行:

ProxyRequests Off       //关闭正向代理
ProxyPassMatch ^/(.*\.php)$fcgi://127.0.0.1:9000/var/www/html/idfsoft.com/
$1

#创建虚拟主机目录并生成php测试页面:

[[email protected] ~]# mkdir /usr/local/apache/htdocs/wuzhiyong.com

localhost ~]# cat > /usr/local/apache/htdocs/wangqing.com/index.php <<EOF
<?php
 phpinfo();
?>
EOF
[[email protected] ~]# chown -R apache.apache /usr/local/apache/htdocs/
[[email protected] ~]# ll /usr/local/apache/htdocs/ -d
drwxr-xr-x 3 apache apache 44 Aug 16 14:50 /usr/local/apache/htdocs/

#在配置文件最后加入以下内容:

[[email protected] ~]# vim /etc/httpd24/httpd.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/wuzhiyong.com"
    ServerName www.wuzhiyong.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/wuzhiyong.com/$1
    <Directory "/usr/local/apache/htdocs/wuzhiyong.com">
       Options none
       AllowOverride none
       Require all granted
    </Directory>
</VirtualHost>

#搜索AddType,添加以下内容:

[[email protected] ~]# vim /etc/httpd24/httpd.conf

 #If the AddEncoding directives above are commented-out, then you
 #probably should define those extensions to indicate media types:

 AddType application/x-compress .Z
 AddType application/x-gzip .gz .tgz
 AddType application/x-httpd-php .php    //添加此行内容
 AddType application/x-httpd-php-source .phps   //添加此行内容
[[email protected] ~]# sed -i ‘/ DirectoryIndex/s/index.html/index.php inde
x.html/g‘ /etc/httpd24/httpd.conf

#重启apache服务:

[[email protected] ~]# apachectl stop
[[email protected] ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port
LISTEN      0      128          *:22                       *:*
LISTEN      0      100    127.0.0.1:25                       *:*
LISTEN      0      128    127.0.0.1:9000                     *:*
LISTEN      0      128         :::80                      :::*
LISTEN      0      128         :::22                      :::*
LISTEN      0      100        ::1:25                      :::*
LISTEN      0      80          :::3306                    :::*

#修改 host 文件,添加域名与IP的映射
#在windows客户机上增加环境变量,让虚拟域名和虚拟主机ip对照
#在浏览器上使用域名访问,若看到以下界面则表示lamp架构搭建成功
![]

原文地址:http://blog.51cto.com/13945839/2287372

时间: 2024-11-08 09:39:57

手动搭建lamp架构的相关文章

linux搭建LAMP架构服务

实验环境以及目标:一台Rad Hat linux 6.5-64位操作系统作为服务器,搭建LAMP架构,搭建动态PHP以及BBS论坛.一台windows 7-32位虚拟机作为客户端能够正常访问linux服务器所搭建的服务. 实验步骤总体分为:1.使用linux先搭建apache网站服务:然后搭建MySQL数据库用来存放论坛文件:然后是搭建PHP服务,用于加载论坛动态模块:最后是BBS论坛.最最后再搭建一个DNS服务用来解析域名服务. 下面是详细操作过程,由于前面已经写了关于apache和MySQL

搭建Lamp架构之一,apache搭建。

一:实验要求1:学会编译安装httpd服务器2:熟悉httpd服务的部署过程及常见配置3:学会构建AWStats日志分析系统4:httpd服务的访问控制客户机的地址限制用户授权限制5:构建虚拟WEB主机基于域名的虚拟主机基于IP地址.端口的虚拟主机二:实验环境1.安装包apr-util-1.4.1.tarapr-1.4.6.tarhttpd-2.4.2.tar2.服务器Linux6.5yum仓库三:实验步骤 卸载原先的httpd服务yum remove httpd2.共享宿主机文件夹3.挂载共享

ansible深入理解和操作——03(roles详解+搭建LAMP架构)

ansible roles 在实际的工作当中,一个完整的项目实际上是很多功能体的组合,如果将所有的功能写在一个playbook中会存在如代码耦合程度高.playbook长而维护成本大.灵活性低等一系列的问题.使用roles能巧妙的解决这一系列的问题.roles是ansible1.2版本后加入的新功能,适合于大项目playbook的编排架构. ansible roles目录结构 roles能够根据层次型结构自动装载变量文件.task以及handlers等.简单来讲,roles就是通过分别将变量.文

Linux手动搭建LAMP环境

当你看到标题里的“手动搭建”,你是不是会想,难不成还有“自动搭建”?当然......不是,这里的“手动搭建”是指按部就班的搭建Apache.MySQL.PHP环境,是相对于集成软件包而言的.所以你是不是能够猜到,我后续还会整理一篇通过集成软件包搭建LAMP环境的文章呢? 其实关于LAMP环境,我到现在都没有用过,好多东西也都不懂为什么要这么做,当初只是心血来潮,想自己搭建一个wiki,所以才着手研究的.我不是搞PHP的,也不是搞后端的,额......是不是暴露的太多了,仅仅是为了搭建环境而搭建环

搭建LAMP架构

环境:linux.httpd-2.2.mysql-5.5.php-5.3 1.源码包编译安装需要的包: [[email protected]_158_68_centoshttpd-2.2.17]# yum -y install gcc gcc-c++ make zlib-devel 2.检查系统有没有装httpd  rpm包: [[email protected]_158_68_centos ~]# rpm -qa|grep httpd [[email protected]_158_68_cen

Linux中详细搭建lamp架构

1.LAMP架构介绍 LAMP是Linux+Apache(httpd)+MySQL+PHP的简写,即把Apache.MySQL以及PHP安装在linux系统上,组成一个运行环境来运行PHP脚本语言,通常是网站.比如Google.淘宝.百度.51cto博客.猿课论坛等就是用PHP语言写出来的. 2.web服务器工作流程 在说lamp架构平台的搭建前,我们先来了解下什么的CGI,什么是FastCGI,什么是 web服务器的资源分为两种,静态资源和动态资源.静态资源就是指静态内容,客户端从服务器获得的

搭建LAMP架构— 2、手工编译安装MySQL

在上一篇文档中,我们介绍了手工编译安装APache,本次,让我们继续完成MySQL的手工编译安装. MySQL数据库是C/S架构的,既有客户端又有服务器端,MySQL客户端的安装非常简单,上一篇文档中已经向大家分享了LAMP架构的所有软件包,我们只需要挂载到Linux系统目录底下,使用tar命令解压即可. tar zxvf /opt/lamp/mysql-5.5.24.tar.gz -C /opt/ //把lamp目录中的软件包解压到opt目录下 现在我们先来完成环境包的安装: yum inst

Ansible---Roles简单搭建LAMP架构案例

Roles介绍 roles能够根据层次型结构自动装载变量文件.task以及handlers等.简单来讲,roles就是通过分别将变量.文件.任务.模块及处理器放置于单独的目录中,并可以便捷地include它们,roles一般用于基于主机构建服务的场景中,但也可以用于构建守护进程等场景中. 针对roles中各个不同执行操作需要建立单独目录. 例如: roles/ httpd/ files/ templates/ tasks/ handlers/ vars/ defaults/ meta/ role

源码编译搭建LAMP架构

前述: 本次源码编译安装LAMP平台架构在一台CentOs 7虚拟机完成(穿插叙述叙述mariadb在另一台主机上配置方法),php5以模块形式编译安装到httpd服务器上,httpd服务器Apace多路处理模块(MPM)采用prefork机制. 下面为安装所用的的以下软件叙述: CentOS  7 IP:172.16.49.2:Kernel:3.10.0-229.el7.x86_64 MariaDB 通用二进制格式mariadb-5.5.46-linux-x86_64.tar httpd 编译