lamp

安装apache
安装编译器和所需要的工具等

[root@localhost ~]# dnf -y install gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel make expat-devel libtool
[root@localhost ~]# dnf -y groups mark install 'Development Tools'

解压安装包

[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
Desktop    Pictures   anaconda-ks.cfg    apr-util-1.6.1.tar.bz2
Documents  Public     apr-1.7.0          httpd-2.4.43
Downloads  Templates  apr-1.7.0.tar.bz2  httpd-2.4.43.tar.bz2
Music      Videos     apr-util-1.6.1     initial-setup-ks.cfg
[root@localhost ~]# 

编译安装
因为httpd依赖apr-util-1.6.1,而apr-util-1.6.1又依赖apr-1.7.0所以安装顺序为apr-1.7.0,apr-util-1.6.1,httpd-2.4.43
将apr-1.7.0下的configure中的RM "$cfgfile"删除或者注释掉

编译按装apr-1.7.0

[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

编译安装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

检测apache的编译环境并且配置所需要的功能并安装

[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 httpd-2.4.43]# useradd -r -M -s /sbin/nologin -g apache apache
[root@localhost httpd-2.4.43]# chown -R apache.apache /usr/local/apache/

配置环境变量帮助文档和头文件

[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 httpd-2.4.43]# cat << EOF >> /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 ${MAINPID}
> [Install]
> WantedBy=multi-user.target
> EOF

启动

[root@localhost httpd-2.4.43]# systemctl start httpd
[root@localhost httpd-2.4.43]# systemctl status httpd
● httpd.service
   Loaded: loaded (/etc/systemd/system/httpd.service; bad; vendor preset: disable>
   Active: active (running) since Wed 2021-05-12 20:55:58 CST; 3s ago
 Main PID: 63498 (httpd)
    Tasks: 6 (limit: 11070)
   Memory: 10.4M
   CGroup: /system.slice/httpd.service
           ├─63498 /usr/local/apache/bin/httpd -k start -DFOREGROUND
           ├─63499 /usr/local/apache/bin/httpd -k start -DFOREGROUND
           ├─63500 /usr/local/apache/bin/httpd -k start -DFOREGROUND
           ├─63501 /usr/local/apache/bin/httpd -k start -DFOREGROUND
           ├─63502 /usr/local/apache/bin/httpd -k start -DFOREGROUND
           └─63503 /usr/local/apache/bin/httpd -k start -DFOREGROUND

May 12 20:55:58 localhost.localdomain systemd[1]: Started httpd.service.
May 12 20:56:01 localhost.localdomain systemd[1]: /etc/systemd/system/httpd.servi>
lines 1-16/16 (END)

关闭防火墙

[root@localhost httpd-2.4.43]#  systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost httpd-2.4.43]# systemctl stop firewalld
[root@localhost httpd-2.4.43]# setenforce 0

查看80端口

[root@localhost ~]# ss -anlt
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port   Process   
LISTEN   0        128              0.0.0.0:111           0.0.0.0:*                
LISTEN   0        32         192.168.122.1:53            0.0.0.0:*                
LISTEN   0        128              0.0.0.0:22            0.0.0.0:*                
LISTEN   0        5              127.0.0.1:631           0.0.0.0:*                
LISTEN   0        128                 [::]:111              [::]:*                
LISTEN   0        128                    *:80                  *:*                
LISTEN   0        128                 [::]:22               [::]:*                
LISTEN   0        5                  [::1]:631              [::]:*      

安装mysql

安装依赖包

[root@localhost ~]# dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

创建用户

[root@localhost ~]# mkdir mysql
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql

解压至指定目录

[root@localhost mysql]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local

创建软链接或者修改目录名

[root@localhost ~]# cd /usr/local
[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src

修改属主和属组

[root@localhost local]# chown -R mysql.mysql /usr/local/mysql/
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 13 root  root  152 4月  27 04:44 apache
drwxr-xr-x.  6 root  root   58 4月  27 04:38 apr
drwxr-xr-x.  5 root  root   43 4月  27 04:40 apr-util
drwxr-xr-x.  2 root  root    6 5月  18 2020 bin
drwxr-xr-x.  2 root  root    6 5月  18 2020 etc
drwxr-xr-x.  2 root  root    6 5月  18 2020 games
drwxr-xr-x.  2 root  root    6 5月  18 2020 include
drwxr-xr-x.  2 root  root    6 5月  18 2020 lib
drwxr-xr-x.  3 root  root   17 4月  23 04:55 lib64
drwxr-xr-x.  2 root  root    6 5月  18 2020 libexec
drwxr-xr-x.  9 mysql mysql 129 5月   5 06:00 mysql
drwxr-xr-x.  2 root  root    6 5月  18 2020 sbin
drwxr-xr-x.  5 root  root   49 4月  23 04:55 share
drwxr-xr-x.  2 root  root    6 5月  18 2020 src

设置环境变量(因为不是用yum装的,找不到mysql程序)

[root@localhost mysql]# vim /etc/profile.d/mysql.sh
[root@localhost mysql]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost mysql]# . /etc/profile.d/mysql.sh
[root@localhost mysql]# which mysql
/usr/local/mysql/bin/mysql

创建存放数据的目录并修改属主属组
需要一个空间大的目录,或者将目录创建后将硬盘设备挂载在此目录上

[root@localhost mysql]# mkdir /opt/mysql_data
[root@localhost mysql]# chown -R mysql.mysql /opt/mysql_data/
[root@localhost mysql]# ll /opt
总用量 0
drwxr-xr-x. 2 mysql mysql 6 5月   5 06:11 mysql_data

初始化并保存密码

[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/mysql_data/
2021-05-05T10:12:31.870885Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-05T10:12:32.084213Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-05T10:12:32.114750Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-05T10:12:32.170393Z 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: 67b16796-ad8a-11eb-a539-000c2951a382.
2021-05-05T10:12:32.171487Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-05T10:12:32.702774Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-05T10:12:32.767933Z 1 [Note] A temporary password is generated for root@localhost: 8?oTP!:G#iWh
[root@localhost mysql]# vim password
[root@localhost mysql]# cat password
8?oTP!:G#iWh

写配置文件

[root@localhost mysql]#  vim /etc/my.cnf
[root@localhost mysql]# 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

配置启动脚本和开机自启

[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(datadir=).*#\1/opt/mysql_data#g' /etc/init.d/mysqld
[root@localhost ~]# cd mysql
[root@localhost mysql]#  head -47 /etc/init.d/mysqld |tail -2
basedir=/usr/local/mysql
datadir=/opt/mysql_data
[root@localhost mysql]# service mysqld start
Starting MySQL.Logging to '/opt/mysql_data/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost mysql]# chkconfig  mysqld on
[root@localhost mysql]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysqld          0:关    1:关    2:开    3:开    4:开    5:开    6:关
[root@localhost mysql]#  ss -anlt
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     Process     
LISTEN      0           128                    0.0.0.0:111                 0.0.0.0:*                    
LISTEN      0           32               192.168.122.1:53                  0.0.0.0:*                    
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*                    
LISTEN      0           5                    127.0.0.1:631                 0.0.0.0:*                    
LISTEN      0           80                           *:3306                      *:*                    
LISTEN      0           128                       [::]:111                    [::]:*                    
LISTEN      0           128                          *:80                        *:*                    
LISTEN      0           128                       [::]:22                     [::]:*                    
LISTEN      0           5                        [::1]:631                    [::]:*        


头文件和库文件配置

[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib

[root@localhost mysql]# ldconfig         //重新读取数据文件

启动并设置密码


[root@localhost mysql]# cd /usr/local
[root@localhost local]#  mysql -uroot -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

[root@localhost local]# dnf provides libncurses.so.5
上次元数据过期检查:0:02:46 前,执行于 2021年05月05日 星期三 06时18分44秒。
ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
仓库        :baseos
匹配来源:
提供    : libncurses.so.5

[root@localhost local]# dnf -y install ncurses-compat-libs
上次元数据过期检查:0:02:55 前,执行于 2021年05月05日 星期三 06时18分44秒。
软件包 ncurses-compat-libs-6.1-7.20180224.el8.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
                                                       
[root@localhost local]#  mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
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 for root@localhost = password('root');          //修改MySQL密码为root
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> quit
Bye
[root@localhost ~]# mysql -uroot -proot
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 8
Server version: 5.7.33 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@localhost ~]# dnf -y install php*

启动php-fpm

[root@localhost ~]# service php-fpm start

监听端口并重启服务

[root@localhost ~]# vim /etc/php-fpm.d/www.conf 
[root@localhost ~]# head -38 /etc/php-fpm.d/www.conf |tail -2
; Note: This value is mandatory.
listen = /run/php-fpm/www.sock
[root@localhost ~]# service php-fpm restart
[root@localhost ~]# ss -anlt
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:111           0.0.0.0:*                
LISTEN   0        32         192.168.122.1:53            0.0.0.0:*                
LISTEN   0        128              0.0.0.0:22            0.0.0.0:*                
LISTEN   0        5              127.0.0.1:631           0.0.0.0:*                
LISTEN   0        80                     *:3306                *:*                
LISTEN   0        128                 [::]:111              [::]:*                
LISTEN   0        128                 [::]:22               [::]:*                
LISTEN   0        5                  [::1]:631              [::]:*                

配置apache

配置apache
在apache的主配置文件中取消以下注释即可配置虚拟主机

[root@localhost ~]# vim /etc/http24/http.cnf
Include /etc/httpd24/extra/httpd-vhosts.conf

在apache的主配置文件中取下以下两行注释开启apache的代理模块

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

在apache的主配置文件中找到以下代码,在index.html前面添加index.php使apaache服务能够第一个找到php的初始页面

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

创建php页面的初始页面的根目录,并且写一个php测试页

[root@localhost ~]# mkdir /usr/local/apache/htdocs/huang
[root@localhost ~]# cd /usr/local/apache/htdocs/huang
[root@localhost hanao]# vim index.php
<?php
        phpinfo();
?>
[root@localhost ~]# vim /etc/httpd24/extra/httpd-vhosts.conf 
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/huang"
    ServerName www.huang.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/huang/$1
    <Directory "/usr/local/apache/htdocs/huang">
        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>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值