lamp部署
Posted 卑微小胡
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lamp部署相关的知识,希望对你有一定的参考价值。
lamp
lamp简介
有了前面学习的知识的铺垫,今天可以来学习下第一个常用的web架构了。
所谓lamp,其实就是由Linux+Apache+mysql/MariaDB+php/Perl/Python的一组动态网站或者服务器的开源软件,除Linux外其它各部件本身都是各自独立的程序,但是因为经常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。
LAMP指的是Linux(操作系统)、Apache(HTTP服务器)、MySQL(也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python)的第一个字母,一般用来建立web应用平台。
web服务器工作流程
在说lamp架构平台的搭建前,我们先来了解下什么是CGI,什么是FastCGI,什么是…
web服务器的资源分为两种,静态资源和动态资源
- 静态资源就是指静态内容,客户端从服务器获得的资源的表现形式与原文件相同。可以简单的理解为就是直接存储于文件系统中的资源
- 动态资源则通常是程序文件,需要在服务器执行之后,将执行的结果返回给客户端
那么web服务器如何执行程序并将结果返回给客户端呢?下面通过一张图来说明一下web服务器如何处理客户端的请求
如上图所示
阶段①显示的是httpd服务器(即apache)和php服务器通过FastCGI协议进行通信,且php作为独立的服务进程运行
阶段②显示的是php程序和mysql数据库间通过mysql协议进行通信。php与mysql本没有什么联系,但是由Php语言写成的程序可以与mysql进行数据交互。同理perl和python写的程序也可以与mysql数据库进行交互
cgi与fastcgi
上图阶段①中提到了FastCGI,下面我们来了解下CGI与FastCGI。
CGI(Common Gateway Interface,通用网关接口),CGI是外部应用程序(CGI程序)与WEB服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI将web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。
FastCGI(Fast Common Gateway Interface)是CGI的改良版,CGI是通过启用一个解释器进程来处理每个请求,耗时且耗资源,而FastCGI则是通过master-worker形式来处理每个请求,即启动一个master主进程,然后根据配置启动几个worker进程,当请求进来时,master会从worker进程中选择一个去处理请求,这样就避免了重复的生成和杀死进程带来的频繁cpu上下文切换而导致耗时
httpd与php结合的方式
httpd与php结合的方式有以下三种:
- modules:php将以httpd的扩展模块形式存在,需要加载动态资源时,httpd可以直接通过php模块来加工资源并返回给客户端
- httpd prefork:libphp5.so(多进程模型的php)
- httpd event or worker:libphp5-zts.so(线程模型的php)
- CGI:httpd需要加载动态资源时,通过CGI与php解释器联系,获得php执行的结果,此时httpd负责与php连接的建立和断开等
- FastCGI:利用php-fpm机制,启动为服务进程,php自行运行为一个服务,https通过socket与php通信
较于CGI方式,FastCGI更为常用,很少有人使用CGI方式来加载动态资源
web工作流程
通过上面的图说明一下web的工作流程:
- 客户端通过http协议请求web服务器资源
- web服务器收到请求后判断客户端请求的资源是静态资源或是动态资源
- 若是静态资源则直接从本地文件系统取之返回给客户端。
- 否则若为动态资源则通过FastCGI协议与php服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,取之而后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。
lamp平台构建
环境说明:
系统平台 | IP | 需要安装的服务 |
---|---|---|
centos8 | 192.168.96.129 | httpd-2.4 mysql-5.7 php php-mysql |
lamp平台软件安装次序:
httpd --> mysql --> php
注意:php要求httpd使用prefork MPM
安装httpd
[root@localhost ~]# dnf -y groups mark install "Development Tools"
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
[root@localhost ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make bzip2 openssl
[root@localhost ~]# tar xf apr-1.7.0.tar.bz2
[root@localhost ~]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost ~]# tar xf httpd-2.4.43.tar.bz2
[root@localhost ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.bz2
apr-1.7.0 httpd-2.4.43
apr-1.7.0.tar.bz2 httpd-2.4.43.tar.bz2
apr-util-1.6.1 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# cd apr-1.7.0
[root@localhost apr-1.7.0]# ls
apr-config.in build-outputs.mk helpers misc strings
apr.dep CHANGES include mmap support
apr.dsp CMakeLists.txt libapr.dep network_io tables
apr.dsw config.layout libapr.dsp NOTICE test
apr.mak configure libapr.mak NWGNUmakefile threadproc
apr.pc.in configure.in libapr.rc passwd time
apr.spec docs LICENSE poll tools
atomic dso locks random user
build emacs-mode Makefile.in README
build.conf encoding Makefile.win README.cmake
buildconf file_io memory shmem
[root@localhost apr-1.7.0]# vim configure
$RM "$cfgfile" #删除或注释此行
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make
[root@localhost apr-1.7.0]# make install
[root@localhost apr-1.7.0]# 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]# make
[root@localhost apr-util-1.6.1]# make install
[root@localhost apr-util-1.6.1]cd ../httpd-2.4.43
[root@localhost httpd-2.4.43]# ./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.43]# make
[root@localhost httpd-2.4.43]# make install
#安装后配置
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
[root@localhost ~]# apachectl start
[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 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
安装MySQL
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.bz2
apr-1.7.0 httpd-2.4.43
apr-1.7.0.tar.bz2 httpd-2.4.43.tar.bz2
apr-util-1.6.1 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C
/usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache bin include libexec share
apr etc lib mysql-5.7.33-linux-glibc2.12-x86_64 src
apr-util games lib64 sbin
[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
apache apr-util etc include lib64 mysql share
apr bin games lib libexec sbin src
[root@localhost local]# chown -R mysql.mysql mysql/
[root@localhost local]# ll
total 0
......
drwxr-xr-x. 9 mysql mysql 129 May 13 11:06 mysql
......
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# source /etc/profile.d/mysql.sh
[root@localhost ~]# which mysql
/usr/local/mysql/bin/mysql
[root@localhost ~]# ln -s /usr/local/mysql/include/ /usr/include/mysql/
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
#添加以下内容
/usr/local/mysql/lib
[root@localhost ~]# ldconfig
[root@localhost ~]# vim /etc/man_db.conf
#添加以下内容
MANDATORY_MANPATH /usr/local/mysql/man
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data
[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data
2021-05-13T03:19:11.590073Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-13T03:19:11.958371Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-13T03:19:12.017848Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-13T03:19:12.029743Z 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: fcf64184-b399-11eb-b2ac-000c29a69e07.
2021-05-13T03:19:12.030827Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-13T03:19:12.557394Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-13T03:19:12.810124Z 1 [Note] A temporary password is generated for root@localhost: 6m+#in.%uGi+
[root@localhost ~]# echo '6m+#in.%uGi+' > pass
[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
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql //程序位置
datadir = /opt/mysql_data //数据存放位置
socket = /tmp/mysql.sock //文件套接字位置
port = 3306 //端口
pid-file = /opt/mysql_data/mysql.pid //进程文件位置
user = mysql //用户
skip-name-resolve //跳过域名解析,即直接在内网使用ip连接数据库
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# vim /etc/init.d/mysqld
#找到这两行并添加如下
basedir=/usr/local/mysql
datadir=/opt/data
[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
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 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
[root@localhost ~]# dnf -y install ncurses-compat-libs
[root@localhost ~]# cat pass
6m+#in.%uGi+
[root@localhost ~]# mysql -uroot -p'6m+#in.%uGi+'
mysql> set password = password('bwxh');
Query OK, 0 rows affected, 1 warning (0.00 sec)
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# 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
[root@localhost ~]# 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
[root@localhost ~]# dnf -y install php*
[root@localhost ~]# systemctl start php-fpm
[root@localhost ~]# systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
#修改如下
listen = 0.0.0.0:9000
[root@localhost ~]# systemctl restart php-fpm
[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 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
配置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
[root@localhost ~]# vim /etc/httpd24/httpd.conf
#取消下面两行注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
配置虚拟主机
[root@localhost ~]# cd /usr/local/apache/
[root@localhost apache]# ls
bin cgi-bin htdocs include man modules
build error icons logs manual
[root@localhost apache]# cd htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# mkdir bwxh
root@localhost htdocs]# cd bwxh
[root@localhost bwxh]# vim index.php
#添加如下
<?php
phpinfo();
?>
[root@localhost bwxh]# chown -R apache.apache /usr/local/apache/htdocs/
[root@localhost bwxh]# ll /usr/local/apache/
total 36
......
drwxr-xr-x. 3 apache apache 36 May 13 11:59 htdocs
......
[root@localhost bwxh]# cd /etc/httpd24
[root@localhost httpd24]# ls
extra httpd.conf magic mime.types original
[root@localhost httpd24]# vim httpd.conf
#修改如下
Include /etc/httpd24/extra/vhosts.conf
[root@localhost extra]# vim vhosts.conf
#添加如下
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/bwxh"
ServerName www.hyh.com
ProxyRequests Off
ProxyPassMatch ^/(.*\\.php)$ fcgi://0.0.0.0:9000/usr/local/apache/htdocs/bwxh/$1
<Directory "/usr/local/apache/htdocs/bwxh">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
[root@localhost httpd24]# vim httpd.conf
#添加如下
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
[root@localhost ~]# apachectl stop
[root@localhost ~]# /usr/local/apache/bin/apachectl start
[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 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
分离部署
apache
安装epel-release vim
[root@localhost ~]# dnf -y install gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel make expat-devel libtool
[root@localhost ~]# dnf -y install epel-release vim
安装开发工具包
[root@localhost ~]# dnf -y groups mark install "Development Tools"
给apache创建用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
[root@localhost httpd-2.4.43]# chown -R apache.apache /usr/local/apache/
安装依赖包
[root@localhost ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
安装bzip2并解压
[root@localhost ~]# dnf -y install bzip2
[root@localhost ~]# tar xf apr-1.6.3.tar.bz2
[root@localhost ~]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost ~]# tar xf httpd-2.4.43.tar.bz2
[root@localhost ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.bz2
apr-1.6.3 httpd-2.4.43
apr-1.6.3.tar.bz2 httpd-2.4.43.tar.bz2
apr-util-1.6.1
修改configure
[root@localhost apr-1.6.3]# vim configure
cfgfile=${ofile}T
trap "$RM \\"$cfgfile\\"; exit 1" 1 2 15
安装apr
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.3]# make
[root@localhost apr-1.6.3]# make install
安装apr-utl
[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
[root@localhost apr-util-1.6.1]# make install
安装httpd
[root@localhost httpd-2.4.43]# ./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.43]# make
[root@localhost httpd-2.4.43]# make install
配置httpd
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
配置帮助文档
[root@localhost ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
取消ServerName的注释
[root@localhost ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
写apache的service文件
[root@localhost extra]# cat /etc/systemd/system/httpd.service
Description=Start httpd
[Service]
Type=simple
EnvironmentFile=/etc/httpd24/httpd.conf
ExecStart=/usr/local/apache/bin/httpd -k start -DFOREGROUND
ExecReload=/usr/local/apache/bin/httpd -k graceful
ExecStop=/bin/kill -WINCH
[Install]
WantedBy=multi-user.target
开启并关闭防火墙
[root@localhost ~]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
mysql
安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
创建mysql用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
解压并放到指定位置
[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# mv mysql-5.7.33-linux-glibc2.12-x86_64 /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache etc lib64 share
apr games libexec src
apr-util include mysql-5.7.33-linux-glibc2.12-x86_64
bin lib sbin
[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
apache apr-util etc include lib64 mysql share
apr bin games lib libexec sbin src
修改权限
[root@localhost local]# chown -R mysql.mysql mysql/
[root@localhost local]# ll
total 0
drwxr-xr-x. 13 root root 152 May 12 21:50 apache
drwxr-xr-x. 6 root root 58 May 12 21:44 apr
drwxr-xr-x. 5 root root 43 May 12 21:45 apr-util
drwxr-xr-x. 2 root root 6 May 19 2020 bin
drwxr-xr-x. 2 root root 6 May 19 2020 etc
drwxr-xr-x. 2 root root 6 May 19 2020 games
drwxr-xr-x. 2 root root 6 May 19 2020 include
drwxr-xr-x. 2 root root 6 May 19 2020 lib
drwxr-xr-x. 3 root root 17 Mar 24 09:08 lib64
drwxr-xr-x. 2 root root 6 May 19 2020 libexec
drwxr-xr-x. 9 mysql mysql 129 May 12 22:08 mysql
drwxr-xr-x. 2 root root 6 May 19 2020 sbin
drwxr-xr-x. 5 root root 49 Mar 24 09:08 share
drwxr-xr-x. 2 root root 6 May 19 2020 src
添加环境变量并读取
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh
做软连接
[root@localhost local]# ln -s /usr/local/mysql/include/ /usr/include/mysql/
lib
[root@localhost local]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost local]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost local]# ldconfig
添加帮助文档
[root@localhost local]# 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
MANDATORY_MANPATH /usr/local/mysql/man
创建数据库存放目录并授权
[root@localhost local]# mkdir /opt/data
[root@localhost local]# chown -R mysql.mysql /opt/data/
初始化数据库
[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
qaSU!&qXe9p3
FiE15gq,6XoE
生成配置文件
[root@localhost local]# 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
[root@localhost local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost local]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/data
登录mysql并修改密码
[root@localhost local]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 2
Server version: 5.7.33
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> set password=password('bwxh');
Query OK, 0 rows affected, 1 warning (0.00 sec)
开机启动
[root@localhost local]# chkconfig --add mysqld
[root@localhost local]# 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
[root@localhost local]# 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 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
PHP
安装依赖包
[root@localhost local]# 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
[root@localhost local]# dnf -y install php*
启动php
[root@localhost local]# systemctl start php-fpm
设置开机启动
[root@localhost local]# systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
修改并重启php-fpm
[root@localhost php-fpm]# vim /etc/php-fpm.d/www.conf
;listen = /run/php-fpm/www.sock
listen = 0.0.0.0:9000
[root@localhost php-fpm]# systemctl restart php-fpm
[root@localhost php-fpm]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0: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 [::]:*
修改httpd.conf
[root@localhost ~]# vim /etc/httpd24/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
创建htdocs目录
root@localhost ~]# mkdir /usr/local/apache/htdocs/hyh
[root@localhost ~]# cd /usr/local/apache/htdocs/hyh
[root@localhost hyh]# cd ..
[root@localhost htdocs]# ls
hyh index.html
创建php页面
[root@localhost htdocs]# vim index.php
[root@localhost htdocs]# cat index.php
<?php
phpinfo();
?>
[root@localhost htdocs]# mv index.php hyh/
[root@localhost htdocs]# ls
hyh index.html
[root@localhost htdocs]# cd hyh/
[root@localhost hyh]# ls
index.php
修改权限
[root@localhost htdocs]# chown -R apache.apache /usr/local/apache/htdocs/
配置虚拟主机设置
[root@localhost httpd24]# vim httpd.conf
Include /etc/httpd24/extra/vhosts.conf
[root@localhost extra]# vim vhosts.conf
[root@localhost extra]# cat vhosts.conf
lHost *:80>
DocumentRoot "/usr/local/apache/htdocs/hyh"
ServerName www.hyh.com
ProxyRequests Off
ProxyPassMatch ^/(.*\\.php)$ fcgi://0.0.0.0:9000/usr/local/apache/htdocs/hyh/$1
<Directory "/usr/local/apache/htdocs/hyh">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
[root@localhost httpd24]# vim httpd.conf
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
用源码安装的apache启动
[root@localhost httpd24]# apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@localhost httpd24]# /usr/local/apache/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@localhost httpd24]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0: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 [::]:*
以上是关于lamp部署的主要内容,如果未能解决你的问题,请参考以下文章