搭建lamp架构

搭建lamp架构

环境说明

系统IP需要安装的服务
Redhat192.168.244.133/24httpd-2.4
mysql-5.7
php
php-mysql

lamp平台软件安装次序:

 httpd --> mysql --> php

安装httpd

安装开发工具包

[root@server4 ~]# yum groups mark install 'Development Tools' -y
Failed to set locale, defaulting to C.UTF-8
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:30:19 ago on Thu Sep 23 16:24:06 2021.
Dependencies resolved.
====================================================
 Package    Arch      Version      Repository  Size
====================================================
Installing Groups:
 Development Tools
                                                   

Transaction Summary
====================================================

Complete!

创建用户

[root@server4 ~]# useradd -r -M -s /sbin/nologin  apache 
[root@server4 ~]# id apache
uid=993(apache) gid=990(apache) groups=990(apache)

安装依赖包

[root@server4 ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make

下载httpd,apr,par-util包

[root@server4 src]# wget https://dlcdn.apache.org/httpd/httpd-2.4.49.tar.gz

[root@server4 src]# wget https://dlcdn.apache.org/apr/apr-1.7.0.tar.gz

[root@server4 src]# wget https://dlcdn.apache.org/apr/apr-util-1.6.1.tar.gz

[root@server4 src]# ls
apache                 debug                kernels
apr-1.7.0.tar.gz       epel
apr-util-1.6.1.tar.gz  httpd-2.4.49.tar.gz

解压下载的包

[root@server4 src]# tar xf httpd-2.4.49.tar.gz 
[root@server4 src]# tar xf apr-util-1.6.1.tar.gz 
[root@server4 src]# tar xf apr-1.7.0.tar.gz 
[root@server4 src]# ls
apache                 debug
apr-1.7.0              epel
apr-1.7.0.tar.gz       httpd-2.4.49
apr-util-1.6.1         httpd-2.4.49.tar.gz
apr-util-1.6.1.tar.gz  kernels

修改apr包里面的配置文件

[root@server4 src]# cd apr-1.7.0
[root@server4 apr-1.6.5]# ls
CHANGES         build-outputs.mk  memory
CMakeLists.txt  build.conf        misc
LICENSE         buildconf         mmap
Makefile.in     config.layout     network_io
Makefile.win    configure 
.........
[root@server4 apr-1.7.0]# vim  configure
.......
.......
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
$RM "$cfgfile"    #删除此行
.......
.......

配置编译apr

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

配置编译apr-util

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

配置编译httpd

[root@server4 src]# cd httpd-2.4.49
[root@server4 httpd-2.4.49]# ./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@server4 httpd-2.4.49]# make && make install
......

配置环境变量

[root@server4 apache]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@server4 apache]# cat /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH

[root@server4 apache]# source /etc/profile.d/httpd.sh 
[root@server4 apache]# which  httpd
/usr/local/apache/bin/httpd



配置文件

[root@server4 apache]# ln -s /usr/local/apache/include/ /usr/include/apache

[root@server4 apache]# cat /etc/man_db.conf
.......
#MANDATORY_MANPATH                      /usr/src/pvm3/man
#
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man   #添加这一行
........
[root@server4 apache]# vim  /usr/local/apache/conf/httpd.conf 
......
ServerName www.example.com:80  把前面的注释取消掉
......

启动

[root@server4 ~]# apachectl start
[root@server4 ~]# ss -antl
State    Recv-Q   Send-Q       Local Address:Port                     Peer Address:Port                 
LISTEN   0        128                0.0.0.0:22                            0.0.0.0:*                    
LISTEN   0        128                      *:80                                  *:*                    
LISTEN   0        128                   [::]:22                               [::]:*                    
[root@server4 ~]# 

编写service文件让它能够开机自启

[root@server4 ~]# cat  /usr/lib/systemd/system/httpd.service 
[Unit]
Description=Httpd server daemon
After=network.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@server4 ~]# systemctl  start httpd
[root@server4 ~]# systemctl enable httpd
[root@server4 ~]# ss -antl
State    Recv-Q   Send-Q       Local Address:Port                     Peer Address:Port                 
LISTEN   0        128                0.0.0.0:22                            0.0.0.0:*                    
LISTEN   0        128                      *:80                                  *:*                    
LISTEN   0        128                   [::]:22                               [::]:*                    
[root@server4 ~]# 

如果要访问网页(最简单的方法关闭一手防火墙)

[root@server4 ~]# systemctl  disable --now  firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@server4 ~]# 
[root@server4 ~]# setenforce 0

安装mysql

安装依赖包

[root@server4 ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

创建用户

[root@server4 ~]# useradd -r -M -s /sbin/nologin mysql
[root@server4 ~]# id mysql
uid=991(mysql) gid=988(mysql) groups=988(mysql)
 

下载二进制包

https://downloads.mysql.com/archives/community/
[root@server4 ~]# ls
anaconda-ks.cfg
mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
[root@server4 local]# mv  mysql-5.7.34-linux-glibc2.12-x86_64/ mysql
[root@server4 local]# ls
........
drwxr-xr-x.  9 root root 129 Sep 23 21:36 mysql
........

修改属主和属组

[root@server4 local]# chown -R mysql:mysql mysql/

配置环境变量

[root@server4 local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@server4 local]# source  /etc/profile.d/mysql.sh
[root@server4 local]# which  mysql
/usr/local/mysql/bin/mysql

创建连接

[root@server4 ~]# ln -s /usr/local/mysql/include/ /usr/include/mysql/

修改文档

[root@server4 ~]# vim   /etc/man_db.conf 
......
MANDATORY_MANPATH                       /usr/local/mysql/man   #添加此行
......

[root@server4 ~]# cat  /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@server4 ~]# ldconfig

创建数据存放目录

[root@server4 ~]# mkdir  /opt/data
[root@server4 ~]# 
[root@server4 ~]# chown -R mysql.mysql /opt/data
[root@server4 opt]# ll
total 0
drwxr-xr-x. 2 mysql mysql 6 Sep 23 22:07 data
[root@server4 opt]# bash

初始化mysql

[root@server4 ~]# mysqld --initialize-insecure --user mysql --datadir /opt/data
2021-09-23T14:11:26.044439Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-23T14:11:26.567824Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-23T14:11:26.635754Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-23T14:11:26.697486Z 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: 23fb6700-1c78-11ec-b15e-000c295e1eda.
2021-09-23T14:11:26.699150Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-23T14:11:27.807485Z 0 [Warning] CA certificate ca.pem is self signed.
2021-09-23T14:11:28.176486Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

生成配置文件

[root@localhost ~]# 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

编写mysql的service文件

[root@server4 system]# cat mysqld.service
[Unit]
Description=Mysql server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target


配置服务启动脚本

[root@server4 ~]# vim /usr/local/mysql/support-files/mysql.server 
.......
basedir=/usr/local/mysql  #找到这两行添加文本
datadir=/opt/data
.......

[root@server4 ~]# systemctl  daemon-reload #重新加载service文件


启动服务

[root@server4 ~]# systemctl  enable --now  mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@server4 ~]# mysql
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@server4 ~]# ss -antl
State    Recv-Q   Send-Q       Local Address:Port                     Peer Address:Port                 
LISTEN   0        128                0.0.0.0:22                            0.0.0.0:*                    
LISTEN   0        128                      *:80                                  *:*                    
LISTEN   0        128                   [::]:22                               [::]:*                    
LISTEN   0        80                       *:3306                                *:*   

需要下载依赖包

[root@server4 ~]# yum  whatprovides libncurses.so.5
Failed to set locale, defaulting to C.UTF-8
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 3:00:36 ago on Thu Sep 23 19:28:16 2021.
ncurses-compat-libs-6.1-7.20180224.el8.i686 :
     ...: Ncurses compatibility libraries
Repo        : base
Matched from:
Provide    : libncurses.so.5

#要下载这个包
#[root@server4 ~]# yum -y install ncurses-compat-libs 
Failed to set locale, defaulting to C.UTF-8
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 3:01:03 ago on Thu Sep 23 19:28:16 2021.
Dependencies resolved.
====================================================
 Package       Arch   Version            Repo  Size
====================================================
Installing:
 ncurses-compat-libs
               x86_64 6.1-7.20180224.el8 base 331 k

Transaction Summary
====================================================
Install  1 Package

Total download size: 331 k
Installed size: 1.2 M
Downloading Packages:
ncurses-compat-libs 900 kB/s | 331 kB     00:00    
----------------------------------------------------
Total               886 kB/s | 331 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                            1/1 
  Installing       : ncurses-compat-libs-6.1-   1/1 
  Running scriptlet: ncurses-compat-libs-6.1-   1/1 
  Verifying        : ncurses-compat-libs-6.1-   1/1 
Installed products updated.

Installed:
  ncurses-compat-libs-6.1-7.20180224.el8.x86_64     

Complete!

进入数据库

[root@server4 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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('123');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit
Bye
[root@server4 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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

下载php包

[root@server4 ~]# wget https://www.php.net/distributions/php-8.0.10.tar.xz
[root@server4 ~]# ls
php-8.0.10.tar.xz

解压

anaconda-ks.cfg
mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
php-8.0.10.tar.gz
[root@server4 ~]# tar -xf  php-8.0.10.tar.gz 

下载epel源

[root@server4 yum.repos.d]# wget http://mirrors.aliyun.com/repo/epel-7.repo

安装依赖包

[root@server4 yum.repos.d]#  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-deve

[root@server4 ~]# yum -y install php-mysqlnd

[root@server4 ~]# yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

[root@server4 php-8.0.10]# yum -y install libsqlite3x-devel  

[root@server4 php-8.0.10]# yum -y install libzip-devel

编译安装

[root@server4 php-8.0.10]# ./configure --prefix=/usr/local/php8  --with-config-file-path=/etc --enable-fpm --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-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
......
......
......
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

+--------------------------------------------------------------------+
| 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@server4 php-8.0.10]# make
.......
.......
.......
invertedregexiterator.inc
pharcommand.inc
phar.inc

Build complete.
Don't forget to run 'make test'.

[root@server4 php-8.0.10]# make install
......
......
/root/php-8.0.10/build/shtool install -c ext/phar/phar.phar /usr/local/php8/bin/phar.phar
ln -s -f phar.phar /usr/local/php8/bin/phar
Installing PDO headers:           /usr/local/php8/include/php/ext/pdo/

配置环境变量

[root@server4 php-8.0.10]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh
[root@server4 php-8.0.10]# cat /etc/profile.d/php.sh
export PATH=/usr/local/php8/bin:$PATH
[root@server4 php-8.0.10]# source /etc/profile.d/php.sh
[root@server4 php-8.0.10]# which php
/usr/local/php8/bin/php

比较两个文件有什么不同

[root@server4 php-8.0.10]# vimdiff php.ini-production  /etc/php.ini 

配置php-fpm

[root@server4 php-8.0.10]# ls /etc/php.ini 
/etc/php.ini
[root@server4 php-8.0.10]# cp /etc/php.ini /opt/
[root@server4 php-8.0.10]# cp php.ini-production /etc/php.ini 
cp: overwrite '/etc/php.ini'? y
[root@server4 php-8.0.10]# cd  sapi/
[root@server4 sapi]# cp fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@server4 sapi]# chmod +x /etc/init.d/php-fpm
[root@server4 sapi]# 

[root@server4 ~]# cd  /usr/local/php8/
[root@server4 php8]# ls
bin  etc  include  lib  php  sbin  var
[root@server4 php8]# cd  etc/
[root@server4 etc]# ls
pear.conf  php-fpm.conf.default  php-fpm.d
[root@server4 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server4 etc]# ls
pear.conf     php-fpm.conf.default
php-fpm.conf  php-fpm.d
[root@server4 etc]# cd  php-fpm.d/
[root@server4 php-fpm.d]# ls
www.conf.default
[root@server4 php-fpm.d]# cp www.conf.default www.conf
[root@server4 php-fpm.d]# ls
www.conf  www.conf.default
[root@server4 php-fpm.d]# 

启动服务

[root@server4 php-fpm.d]# service php-fpm start
Starting php-fpm  done
[root@server4 php-fpm.d]# ss -antl
State    Recv-Q   Send-Q       Local Address:Port                     Peer Address:Port                 
LISTEN   0        128                0.0.0.0:22                            0.0.0.0:*                    
LISTEN   0        128              127.0.0.1:9000                          0.0.0.0:*                    
LISTEN   0        128                      *:80                                  *:*                    
LISTEN   0        128                   [::]:22                               [::]:*                    
LISTEN   0        80                       *:3306                                *:*      

配置php的service文件


配置apache

取消httpd.server

[root@server4 ~]# vim /usr/local/apache/conf/httpd.conf 
......
LoadModule proxy_module modules/mod_proxy.so
.......
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
.......
#取消这两行注释

配置虚拟主机

[root@server4 ~]# cd /usr/local/apache/
[root@server4 apache]# ls
bin      conf    icons    logs    modules
build    error   include  man
cgi-bin  htdocs  lib      manual
[root@server4 apache]# ls htdocs/
index.html
[root@server4 apache]# mkdir htdocs/test
[root@server4 apache]# vim htdocs/test
[root@server4 apache]# vim htdocs/test/index.php
[root@server4 apache]# cat htdocs/test/index.php
<?php
   phpinfo();
?>

[root@server4 apache]# chown -R apache.apache /usr/local/apache/htdocs/

[root@server4 apache]# vim /usr/local/apache/conf/httpd.conf 

#在末尾加入
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/test"
    ServerName www.wangsky.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test/$1
    <Directory "/usr/local/apache/htdocs/test">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

#匹配前两行添加后两行
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php        
    AddType application/x-httpd-php-source .phps

#加入index.php
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

重启httpd服务

[root@server4 ~]# systemctl  restart httpd

查看网页

在这里插入图片描述

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值