lamp平台构建
lamp平台构建
环境说明:
系统平台 | IP | 需要安装的服务 |
---|---|---|
centos7,redhat7 | 172.16.12.128 | httpd-2.4,mysql-5.7,php,php-mysql |
lamp平台软件安装次序:
httpd --> mysql --> php
注意:php要求httpd使用prefork MPM
安装httpd
删除本地仓库
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf myrepo.repo
在阿里云镜像下载centos8
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo
安装开发工具包
[root@localhost yum.repos.d]# yum groups mark install 'Development Tools'
创建apache服务的用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
[root@localhost ~]# id apache
uid=994(apache) gid=991(apache) groups=991(apache)
安装依赖包
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
下载和安装apr以及apr-util
[root@localhost ~]# yum -y install bzip2
[root@localhost ~]# ls
anaconda-ks.cfg apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.54.tar.bz2
解压apr-1.6.5.tar.bz2
[root@localhost ~]# tar xf apr-1.6.5.tar.bz2
[root@localhost ~]# cd apr-1.6.5
[root@localhost apr-1.6.5]# vim configure
# $RM "$cfgfile" //将此行加上注释,或者删除此行
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.5]# make && make install
解压apr-util-1.6.1.tar.bz2
[root@localhost ~]# ls
anaconda-ks.cfg apr-1.6.5.tar.bz2 httpd-2.4.54.tar.bz2
apr-1.6.5 apr-util-1.6.1.tar.bz2
[root@localhost ~]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost ~]# cd apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make && make install
解压httpd-2.4.54.tar.bz2
[root@localhost ~]# ls
anaconda-ks.cfg apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2
apr-1.6.5 apr-util-1.6.1 httpd-2.4.54.tar.bz2
[root@localhost ~]# tar xf httpd-2.4.54.tar.bz2
[root@localhost httpd-2.4.54]# ./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
[root@localhost httpd-2.4.54]# make && make install
安装后配置
[root@localhost ~]# echo 'export PATH=$PATH:/usr/local/apache/bin' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# which httpd
/usr/local/apache/bin/httpd
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/local/apache/man
[root@localhost ~]# vim /etc/httpd24/httpd.conf
ServerName www.example.com:80 去掉前面的#或删除整行
启动apache
[root@localhost ~]# which apachectl
/usr/local/apache/bin/apachectl
[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service httpd.service
[root@localhost system]# vim httpd.service
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl status httpd
● httpd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: >
Active: inactive (dead)
[root@localhost system]# systemctl stop firewalld
[root@localhost system]# systemctl disable firewalld
安装mysql
创建用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# id mysql
uid=993(mysql) gid=990(mysql) groups=990(mysql)
下载二进制格式的mysql软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug kernels mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
解压软件至/usr/local/
[root@localhost src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
做一个软链接
[root@localhost src]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# chown -R mysql.mysql mysql*
配置环境变量
[root@localhost local]# cd mysql
[root@localhost mysql]# ls
bin docs include lib LICENSE man README share support-files
[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@localhost mysql]# source /etc/profile.d/mysql.sh
[root@localhost mysql]# which mysql
添加配置include
[root@localhost mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql
添加配置lib
[root@localhost mysql]# echo '/usr/local/mysql/lib/' > /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# ldconfig
添加配置man
[root@localhost mysql]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/local/mysql/man
建立数据存放目录
[root@localhost mysql]# mkdir /opt/data
[root@localhost mysql]# chown -R mysql.mysql /opt/data/
[root@localhost mysql]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Aug 2 16:19 data
初始化数据库
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/
2022-08-02T08:21:05.817290Z 1 [Note] A temporary password is generated for root@localhost: y-reJSy8abGj
[root@localhost ~]# echo 'y-reJSy8abGj' > password
[root@localhost ~]# cat password
y-reJSy8abGj
生成配置文件
[root@localhost ~]# vim /etc/my.cnf.d/my.cnf
[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
配置服务启动脚本
[root@localhost ~]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql/
datadir=/opt/data/
启动mysql
[root@localhost ~]# service mysqld start
Starting MySQL.. SUCCESS!
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
使用临时密码登录
[root@localhost ~]# vim /etc/init.d/mysqld
[root@localhost ~]# mysql -uroot -p'y-reJSy8abGj'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.37
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
设置新密码
mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
[root@localhost ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.37 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
安装php
下载epel镜像
[root@localhost src]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
安装依赖包
[root@localhost src]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel --allowerasing --nobest
下载php
[root@localhost src]# ls
debug mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz php-7.4.30.tar.gz
kernels php-7.4.30
编译安装php
[root@localhost src]#./configure --prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-json \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
[root@localhost src]#make && make install
出现错误
configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met:No package 'libxml-2.0' found 解决办法:yum install -y libxml2-devel
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:No package 'sqlite3' found 解决办法:yum install libsqlite3x-devel -y
configure: error: Package requirements (libcurl >= 7.15.5) were not met:
解决方法:yum install -y libcurl-devel.x86_64
configure: error: Package requirements (libjpeg) were not met: 解决方法:yum -y install libjpeg-devel
安装后配置
[root@localhost php-7.4.30]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost php-7.4.30]# source /etc/profile.d/php7.sh
[root@localhost php-7.4.30]# which php
/usr/local/php7/bin/php
[root@localhost php-7.4.30]# php -v
PHP 7.4.30 (cli) (built: Aug 2 2022 23:06:10) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
配置php-fpm
[root@localhost php-7.4.30]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@localhost php-7.4.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.30]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-7.4.30]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.4.30]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
//启动php-fpm
[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service php-fpm.service
[root@localhost system]# vim php-fpm.service
https://blog.csdn.net/qq_65441164/article/details/126131525
[Unit]
Description=php-fpm server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/etc/init.d/php-fpm start
ExecStop=/etc/init.d/php-fpm stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@localhost system]# systemctl daemon-reload
[root@localhost php-7.4.30]# systemctl start php-fpm
[root@localhost php-7.4.30]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost php-7.4.30]# systemctl stop firewalld
[root@localhost php-7.4.30]# setenforce 0
[root@localhost php-7.4.30]# systemctl enable php-fpm
Synchronizing state of php-fpm.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
配置apache
启用代理模块
在apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩展,因此,这两个模块都要加载,编辑httpd.conf文件,取消以下两行内容的注释:
- LoadModule proxy_module modules/mod_proxy.so
- LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
启用httpd的相关模块
[root@localhost ~]# vim /etc/httpd24/httpd.conf
119 LoadModule proxy_module modules/mod_proxy.so
123 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
配置虚拟主机
启用代理模块
在需要使用fcgi的虚拟主机中添加类似如下两行:
ProxyRequests Off //关闭正向代理
ProxyPassMatch^/(.*.php)$fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
例如
ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/var/www/html/idfsoft.com/$1
以上设置表示把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://127.0.0.1:9000后指明了这两个参数,其它参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。
注意:
这里写的/var/www/html/是yum源安装方式生成的网页存放目录,这里必须改成你编译安装指定的网页存放路径,禁止直接复制我这里的路径
这里的idfsoft.com是域名,你必须改成你所使用的域名,禁止直接复制此处的域名
这里的$1表示匹配所有以.php结尾的http请求
创建虚拟主机目录并生成php测试页面
[root@localhost php-7.4.30]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# rm -rf index.html
[root@localhost htdocs]# mkdir laji
[root@localhost htdocs]# vim /usr/local/apache/htdocs/laji/index.php
[root@localhost ~]# chown -R apache.apache /usr/local/apache/htdocs/
[root@localhost ~]# ll -d /usr/local/apache/htdocs/
drwxr-xr-x. 3 apache apache 18 Aug 2 23:54 /usr/local/apache/htdocs/
[root@localhost ~]# vim /etc/httpd24/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/laji"
ServerName www.ljl.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/laji/$1
<Directory "/usr/local/apache/htdocs/laji">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
[root@localhost ~]# vim /etc/httpd24/httpd.conf
搜索AddType
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php 添加这行
AddType application/x-httpd-php-source .phps 添加这行
Include /etc/httpd24/extra/proxy-html.conf 删除前面的#
Include /etc/httpd24/extra/httpd-vhosts.conf 删除前面的#
[root@localhost ~]# sed -i '/ DirectoryIndex/s/index.html/index.php index.html/g' /etc/httpd24/httpd.conf
重启apache服务
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
验证
修改/etc/hosts文件,添加域名与IP的映射
在c盘下的c:/Windows/system32/drivers/etc/hosts添加以下数据
192.168.203.137 www.ljl.com
浏览器上使用域名访问,若看到以下界面则表示lamp架构搭建成功,否则请检查你的操作
lamp平台构建的更多相关文章
- LAMP平台部署及应用
环境:http://www.cnblogs.com/zzzhfo/p/5925786.html http://www.cnblogs.com/zzzhfo/p/5934630.html 1.LAMP ...
- 基于LAMP平台的网站架构(或Web系统架构)
1.网站架构的前提(或者说需求) 我们公司是一电子商务的网站,因为线下家具建材项目的推广需求,从而有了我们公司的这个线上网站,在这里我贴一张公司的网站架构图. 总体来说网站规模不是太大,注册人数在15 ...
- LAMP平台部署(转)
LAMP平台的概述 LAMP环境脚本部署:https://github.com/spdir/ShellScripts/tree/master/lamp LAMP的介绍:百度百科 LAMP平台的构成组件 ...
- LAMP平台部署
LAMP平台的概述 LAMP环境脚本部署:https://github.com/spdir/ShellScripts/tree/master/lamp LAMP的介绍:百度百科 LAMP平台的构成组件 ...
- Centos7下搭建LAMP平台环境 (转载)
1.启用Apache(httpd) Centos7默认已经安装httpd服务,只是没有启动.如果你需要全新安装,可以yum install -y httpd 启动服务:systemctl start ...
- LAMP平台搭建菜鸟入门级实验
LAMP平台搭建(菜鸟入门级) mysql 安装: (1)二进制安装 二进制安装 ,执行解压配置即可.无须执行三布安装. (2)源码编译安装 安装准备工作: (1)查看系统配置:#uname -a/ ...
- Unity跨平台C/CPP动态库编译---可靠UDP网络库kcp基于CMake的各平台构建实践
1.为什么需要动态库 a)提供原生代码(native code)的支持,也叫原生插件,但是我实践的是c/cpp跨平台动态库,这里不具体涉及安卓平台java库和ios平台的objectc库构建. b)某 ...
- 我发起了一个 用 物理服务器 和 .Net 平台 构建云平台 的 .Net 开源项目
大家好 , 我发起了一个 用 物理服务器 和 .Net 平台 构建云平台 的 .Net 开源项目 . 对 , 用 物理服务器 和 .Net 平台 构建 云平台 . 通过 .Net 构建 分布式 计算集 ...
- SharpGL学习笔记(一) 平台构建与Opengl的hello World
(一)平台构建与Opengl的hello World OpenGL就是3d绘图的API,微软针和它竞争推出D3D,也就是玩游戏时最常见的DirectorX组件中的3d功能. 所以不要指望windows ...
随机推荐
- 用python实现输入三边判断能否组成三角形
# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'sanjiaoxing.py'## Creat ...
- 141_Power Query之获取钉钉审批流自动刷新Power BI报告
博客:www.jiaopengzi.com 焦棚子的文章目录 请点击下载附件 一.背景 钉钉办公给很多企业带来了很多方便,比如审批流线上化,通用化.线上化填写后,数据自动获取又是一个硬伤了,虽然数据可 ...
- Redis快速度特性及为什么支持多线程及应用场景
转载请注明出处: 目录 1.Redis 访问速度快特性 2.Redis 6.0 为什么支持多线程? 3.Redis可以做什么 3.1.缓存 3.2.排行榜系统 3.3.计数器应用 3.4.社交网络 3 ...
- 『忘了再学』Shell基础 — 20、Shell中的运算符
目录 1.Shell常用运算符 2.Shell中数值运算的方法 (1)方式一 (2)方式二 (3)方式三(推荐) 1.Shell常用运算符 Shell中常用运算符如下表: 优先级数值越大优先级越高,具 ...
- 一些实验中用过的python函数/方法(持续更新)
衡量运行时间 很多时候你需要计算某段代码执行所需的时间,可以使用 time 模块来实现这个功能. import time startTime = time.time() # write your co ...
- 《Effective C++》阅读总结(二):类的构造、析构和赋值
今天是周六早上,但很不幸待会儿还是要去公司,本月kpi还剩一些工作要做,这个月计划的Effective C++学习,也基本完成了,最后一章节模板相关那部分还看不太懂,就大概过了一遍.现在是收尾总结阶段 ...
- uniapp项目vue2升级vue3简单记录
看到好多开源项目都升级了vue3,看文章说vue3性能升级很多,而且组合式api很香,遂把最近开发的自助洗车app升级下,在此记录下出现的问题. uniapp升级vue3官方指南 我是先去vue官网看 ...
- 21.LVS负载均衡群集-DR群集
LVS负载均衡群集-DR群集 目录 LVS负载均衡群集-DR群集 数据包流向分析 DR模式的特点 LVS-DR中的ARP问题 IP地址冲突 解决办法 路由根据ARP表项,会将新来的请求报文转发给Rea ...
- 说什么也要脱单——Python WEB开发:用Tornado框架制作简易【表白墙】网站
先来哔哔两句:(https://jq.qq.com/?_wv=1027&k=QgGWqAVF) 今天我们要用Python做Web开发,做一个简单的[表白墙]网站.众所周知表白墙的功能普遍更多的 ...
- Python列表解析式的正确使用方式(二)
高级解析式 条件逻辑早些时候,我向您展示了这个公式: python学习交流群:660193417### new_list = [expression for member in iterable] 公 ...