LAMP 架构介绍及环境搭建

LAMP 架构介绍及环境搭建


LAMP分别代表什么?

  • L代表服务器操作系统使用Linux
  • A代表网站服务使用的是Apache软件基金会中的httpd软件
  • M代表网站后台使用的数据库是MySQL数据库
  • P代表网站是使用PHP/Perl/Python等语言开发

LAMP平台构建

环境说明:

系统平台IP需要安装的服务
Centos8192.168.174.164httpd-2.4
mysql-5.7
php
php-mysql

lamp平台软件安装次序:

httpd–>mysql–>php

注意:php要求httpd使用prefork MPM

安装httpd
//配置yum源
[root@192 ~]# cd /etc/yum.repos.d/
[root@192 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0  12230      0 --:--:-- --:--:-- --:--:-- 12230
[root@192 yum.repos.d]# ls
CentOS-Base.repo
[root@192 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@192 yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@192 yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@192 yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

//安装开发工具包
[root@192 ~]#  yum groups mark install 'Development Tools'

//创建apache服务的用户和组
[root@192 ~]# useradd -r -M -s /sbin/nologin apache
[root@192 ~]# id apache
uid=995(apache) gid=992(apache) groups=992(apache)

//安装依赖包
[root@192 ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++

//安装vim编辑工具、make、wgte。
[root@192 ~]# dnf -y install vim make wget

//下载和安装apr以及apr-util和httpd
[root@192 ~]# cd /usr/src/
[root@192 src]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
[root@192 src]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  debug  httpd-2.4.54.tar.gz  kernels

[root@192 src]# tar xf apr-1.7.0.tar.gz 
[root@192 src]# tar xf apr-util-1.6.1.tar.gz 
[root@192 src]# cd apr-1.7.0/
[root@192 apr-1.7.0]# vim configure   
 cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    #$RM "$cfgfile"  //将此行加上注释,或者删除此行  

[root@192 apr-1.7.0]# ./configure --prefix=/usr/local/apr  //配置

[root@192 apr-1.7.0]# make && make install    //编译安装

[root@192 apr-1.7.0]# cd /usr/src/apr-util-1.6.1/
[root@192 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@192 apr-util-1.6.1]# make && make install

[root@192 src]# tar xf httpd-2.4.54.tar.gz 
[root@192 src]# cd httpd-2.4.54/
[root@192 httpd-2.4.54]# ./configure --prefix=/usr/local/apache \
> --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@192 httpd-2.4.54]# make && make install

[root@192 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@192 ~]# source /etc/profile.d/httpd.sh
[root@192 ~]# ln -s /usr/local/apache/include/ /usr/include/apache
[root@192 ~]#  vim /etc/man_db.conf 
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man
 
[root@192 ~]# cd /usr/lib/systemd/system/
[root@192 system]# cp sshd.service httpd.service
[root@192 system]# vim httpd.service 
[root@192 system]# cat httpd.service 
[Unit]
Description=web server daemon
Documentation=man:sshd(5)
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@192 system]# cd
[root@192 ~]# systemctl daemon-reload 
[root@192 ~]# systemctl start httpd.service 
[root@192 ~]# systemctl enable httpd.service 
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@192 ~]# ss -anlt
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                            *:80                          *:*                       
LISTEN       0            128                         [::]:22                       [::]:* 
安装mysql
//安装依赖包
[root@192 ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

//创建用户和组
[root@192 ~]# useradd -r -M -s /sbin/nologin mysql
[root@192 ~]# id mysql
uid=994(mysql) gid=991(mysql) groups=991(mysql)

//下载或导入mysql二进制软件包
[root@192 ~]# cd /usr/src   
[root@192 src]# ls
mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz

//解压软件至/usr/local/
[root@192 src]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[root@192 src]#  cd /usr/local/
[root@192 local]# ls
apache  apr-util  etc    include  lib64    mysql-5.7.38-linux-glibc2.12-x86_64  share
apr     bin       games  lib      libexec  sbin                                 src

//建立软链接
[root@192 local]# ln -sv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.38-linux-glibc2.12-x86_64/'
[root@192 local]# ll mysql
lrwxrwxrwx. 1 root root 36 Aug  2 20:53 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/

//修改目录/usr/local/mysql的属主属组
[root@192 local]# chown -R mysql.mysql mysql*
[root@192 local]# ll | grep mysql
lrwxrwxrwx.  1 mysql mysql  36 Aug  2 20:53 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/
drwxr-xr-x.  9 mysql mysql 129 Aug  2 20:46 mysql-5.7.38-linux-glibc2.12-x86_64 


[root@192 local]# ls /usr/local/mysql
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@192 local]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@192 local]# echo '/usr/local/mysql/lib/' > /etc/ld.so.conf.d/mysql.conf
[root@192 local]# vim /etc/man_db.conf 
[root@192 local]# 
MANDATORY_MANPATH                       /usr/local/mysql/man

//添加环境变量
[root@192 ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile
[root@192 ~]# source /etc/profile.d/mysql.sh
-bash: /etc/profile.d/mysql.sh: No such file or directory
[root@192 ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@192 ~]# source /etc/profile.d/mysql.sh
[root@192 ~]# which mysql
/usr/local/mysql/bin/mysql

//建立数据存放目录
[root@192 ~]# mkdir /opt/data
[root@192 ~]# chown -R mysql.mysql /opt/data/
[root@192 ~]# ll /opt
total 0
drwxr-xr-x. 2 mysql mysql 6 Aug  2 21:05 data

//初始化数据库
[root@192 ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2022-08-02T13:07:22.622685Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-02T13:07:25.503595Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-02T13:07:26.430364Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-02T13:07:26.507494Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0e58aa9b-1264-11ed-b6e8-000c2988ffe9.
2022-08-02T13:07:26.559894Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-02T13:07:26.944837Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T13:07:26.944863Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T13:07:26.945180Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-02T13:07:27.061506Z 1 [Note] A temporary password is generated for root@localhost: WoAndh!lY32#

//保存临时密码,方便后面使用
[root@192 ~]# echo 'WoAndh!lY32#' > pass

//生成配置文件
[root@192 ~]#  vim /etc/my.cnf
[root@192 ~]# cat /etc/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@192 ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@192 ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@192 ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld

//启动mysql
[root@192 ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/192.168.174.164.err'.
. SUCCESS! 
[root@192 ~]# ss -anlt
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            80                             *:3306                        *:*                       
LISTEN       0            128                            *:80                          *:*                       
LISTEN       0            128                         [::]:22                       [::]:*                       

//服务开机自启
[root@192 ~]# chkconfig --add mysqld

//修改密码
//使用临时密码登录
[root@192 ~]# mysql -uroot -p'WoAndh!lY32#'
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.38

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> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye
[root@192 ~]
安装php
//下载php
[root@192 ~]# cd /usr/src/
[root@192 src]# wget https://www.php.net/distributions/php-7.4.30.tar.xz

//安装依赖包
[root@192 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 php-mysqlnd

//编译安装php
[root@192 src]# tar xf php-7.4.30.tar.xz 
[root@192 src]# cd php-7.4.30/
[root@192 php-7.4.30]# ./configure --prefix=/usr/local/apache \
> --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@192 php-7.4.30]# make && make install

//安装后配置
[root@192 php-7.4.30]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@192 php-7.4.30]# source /etc/profile.d/php7.sh 
[root@192 php-7.4.30]# which php
/usr/local/php7/bin/php
[root@192 php-7.4.30]# php -v
PHP 7.4.30 (cli) (built: Aug  2 2022 22:25:01) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

//配置php-fpm
[root@192 php-7.4.30]# cd sapi/
[root@192 sapi]# cd fpm/
[root@192 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@192 fpm]# chmod +x /etc/init.d/php-fpm 
[root@192 fpm]# cd /usr/local/php7/etc/
[root@192 etc]# cp php-fpm.conf.default php-fpm.conf
[root@192 etc]# cd php-fpm.d/
[root@192 php-fpm.d]# cp www.conf.default www.conf

//启动php-fpm
[root@192 php-fpm.d]# service php-fpm start
[root@192 ~]# 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@192 ~]# chkconfig --add php-fpm 
[root@192 ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
php-fpm        	0:off	1:off	2:on	3:on	4:on	5:on	6:off

   systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
php-fpm        	0:off	1:off	2:on	3:on	4:on	5:on	6:off

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值