lamp配置

lamp独立配置

httpd安装

安装依赖
[root@host ~]# yum -y install openssl-devel pcre-devel expat-devel libtool wget make

解压安装包
[root@host src]# wget https://mirrors.bfsu.edu.cn/apache/apr/apr-1.7.0.tar.gz
[root@host src]# wget https://mirrors.bfsu.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[root@host src]# wget https://mirrors.bfsu.edu.cn/apache/httpd/httpd-2.4.46.tar.gz
[root@host src]# tar xf apr-1.7.0.tar.gz 
[root@host src]# tar xf apr-util-1.6.1.tar.gz 
[root@host src]# tar xf httpd-2.4.46.tar.gz 
  • 编译,配置,安装
[root@host src]#cd apr-1.7.0/
[root@host apr-1.7.0]# vim configure
# $RM "$cfgfile"  //将此行加上注释,或者删除此行

配置
[root@host apr-1.7.0]# ./configure --prefix=/usr/local/apr
安装
[root@host apr-1.7.0]# make && make install
[root@host apr-1.7.0]# cd /usr/src/apr-util-1.6.1/
配置
[root@host apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
安装
[root@host apr-util-1.6.1]# make && make install
编译安装apache
[root@host src]# cd  httpd-2.4.46 
[root@host httpd-2.4.46]# ./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@host httpd-2.4.46]# make && make install
  • 关闭防火墙
[root@host httpd-2.4.46]# systemctl stop firewalld
[root@host httpd-2.4.46]# setenforce 0
  • 启动apache
[root@host httpd-2.4.46]# /usr/local/apache/bin/apachectl start
  • 测试
    lamp配置

  • 安装工具包

[root@host ~]# yum groups mark install 'Development Tools'
  • 安装后的配置
[root@host ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@host ~]# source /etc/profile.d/httpd.sh
[root@host ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@host ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
  • 取消ServerName前的注释
[root@host ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
[root@host ~]# ss -antl
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@host ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

[root@host ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
  • 创建用户
[root@host ~]# useradd -r -M -s /sbin/nologin mysql
  • 解压软件至/usr/local/
[root@host ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local
  • 修改目录名
[root@host local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[root@host local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src
  • 修改目录/usr/local/mysql的属主属组
[root@host local]# chown -R mysql.mysql /usr/local/mysql/
[root@host local]# ll
总用量 0
drwxr-xr-x. 13 root  root  152 5月  12 18:39 apache
drwxr-xr-x.  6 root  root   58 5月  12 18:34 apr
drwxr-xr-x.  5 root  root   43 5月  12 18:36 apr-util
drwxr-xr-x.  2 root  root    6 5月  19 2020 bin
drwxr-xr-x.  2 root  root    6 5月  19 2020 etc
drwxr-xr-x.  2 root  root    6 5月  19 2020 games
drwxr-xr-x.  2 root  root    6 5月  19 2020 include
drwxr-xr-x.  2 root  root    6 5月  19 2020 lib
drwxr-xr-x.  3 root  root   17 3月  29 10:43 lib64
drwxr-xr-x.  2 root  root    6 5月  19 2020 libexec
drwxr-xr-x.  9 mysql mysql 129 5月  12 19:08 mysql
drwxr-xr-x.  2 root  root    6 5月  19 2020 sbin
drwxr-xr-x.  5 root  root   49 3月  29 10:43 share
drwxr-xr-x.  2 root  root    6 5月  19 2020 src
  • 添加环境变量
[root@host local]# vim /etc/profile.d/mysql.sh
[root@host local]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@host local]# . /etc/profile.d/mysql.sh
[root@host local]# which mysql
/usr/local/mysql/bin/mysql
  • 建议数据存放路径
[root@host ~]# mkdir /opt/mysql-data
[root@host ~]# chown -R mysql.mysql /opt/mysql-data/
[root@host ~]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 5月  12 20:57 mysql-data
  • 初始化
[root@host ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/mysql-data/
2021-05-12T12:58:03.278874Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-12T12:58:04.125188Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-12T12:58:04.270664Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-12T12:58:04.351540Z 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: b0a03970-b321-11eb-ae24-000c2941ee19.
2021-05-12T12:58:04.352956Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-12T12:58:05.496781Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-12T12:58:05.701902Z 1 [Note] A temporary password is generated for root@localhost: Hh_u;fud3yep
  • 编写配置文件
[root@host local]# vim /etc/my.cnf
[root@host ~]# cat /etc/my.cnf
[mysqld]
datadir = /opt/mysql-data
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@host mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@host mysql]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@host mysql]# sed -ri 's#^(datadir=).*#\1/opt/mysql-data#g' /etc/init.d/mysqld
[root@host mysql]# head -47 /etc/init.d/mysqld |tail -2
basedir=/usr/local/mysql
datadir=/opt/mysql-data
[root@host mysql]# service mysqld start
Starting MySQL. SUCCESS!
  • 开机自启
[root@host ~]# chkconfig  mysqld on
[root@host ~]# 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@host ~]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@host ~]# vim /etc/ld.so.conf.d/mysql.conf
[root@host ~]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@host ~]# ldconfig      重新读取
  • 启动并设置密码
[root@host ~]# 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('xialuo123!');         设置新密码
Query OK, 0 rows affected, 1 warning (0.00 sec)

php配置

[root@host ~]# yum -y install php*
启动服务
[root@host ~]# service php-fpm start
  • 监听端口并重启服务
[root@host ~]# vim /etc/php-fpm.d/www.conf
......
;listen = /run/php-fpm/www.sock
listen = 0.0.0.0:9000
......
[root@host ~]# systemctl restart php-fpm.service 
[root@host ~]# 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: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                        [::]:*

apache配置

[root@host ~]# vim /etc/httpd24/httpd.conf
将下列两条取消注释
......
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@host ~]# mkdir /usr/local/apache/htdocs/xialuo
[root@host ~]# cd /usr/local/apache/htdocs/xialuo
[root@host xialuo]# ls
[root@host xialuo]# vim index.php
[root@host xialuo]# cat index.php
<?php
       phpinfo();
?>

更改属主
[root@host ~]# chown -R apache.apache /usr/local/apache/htdocs/
[root@host ~]# ll /usr/local/apache/
总用量 36
drwxr-xr-x.  2 root   root    262 5月  12 18:39 bin
drwxr-xr-x.  2 root   root    167 5月  12 18:39 build
drwxr-xr-x.  2 root   root     78 5月  12 18:39 cgi-bin
drwxr-xr-x.  3 root   root   4096 5月  12 18:39 error
drwxr-sr-x.  3 apache apache   38 5月  12 22:23 htdocs
drwxr-xr-x.  3 root   root   8192 5月  12 18:39 icons
drwxr-xr-x.  2 root   root   4096 5月  12 18:39 include
drwxr-xr-x.  2 root   root     58 5月  12 18:41 logs
drwxr-xr-x.  4 root   root     30 5月  12 18:39 man
drwxr-sr-x. 14 root   root   8192 8月   1 2020 manual
drwxr-xr-x.  2 root   root   4096 5月  12 18:39 modules
  • 配置虚拟主机
[root@host ~]# cd /etc/httpd24/
[root@host httpd24]# ls
extra  httpd.conf  magic  mime.types  original
[root@host httpd24]# vim httpd.conf 
......
#Include /etc/httpd24/extra/httpd-default.conf
Include /etc/httpd24/extra/vhosts.conf     (将httpd-default改为vhosts.conf)

# Configure mod_proxy_html to understand HTML4/XHTML1
<IfModule proxy_html_module>
Include /etc/httpd24/extra/proxy-html.conf
......

[root@host extra]# vim vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/xialuo"
    ServerName www.memory.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/xialuo/$1
    <Directory "/usr/local/apache/htdocs/xialuo">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

[root@host httpd24]# vim httpd.conf 
......
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz(在下面添加以下两条代码)    
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
......
重启apache
[root@host extra]# apachectl restart
[root@host extra]# 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: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                        [::]:*  

测试
![](https://www.icode9.com/i/ll/?i=20210512230057646.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0JfbWVtb3J5,size_16,color_FFFFFF,t_70)

有mysqlnd的页面就代表可以使用MySQL

上一篇:2021-06-26进程的优先级与LAMP项目部署实战


下一篇:Linux内核分析学习总结