Java教程

lamp

本文主要是介绍lamp,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

目录
  • lamp平台构建
    • 安装httpd
    • 安装mysql
    • 安装php
  • 安装报错问题

lamp平台构建

lamp平台软件安装次序:httpd --> mysql --> php

注意:php要求httpd使用prefork MPM

安装httpd

//YUM源配置
[root@z1 yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@z1 yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@z1 yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@z1 yum.repos.d]# ls
CentOS-Base.repo   epel.repo                  epel-testing.repo
epel-modular.repo  epel-testing-modular.repo
[root@z1 yum.repos.d]# dnf clean all
18 files removed
[root@z1 yum.repos.d]# dnf makecache

//创建apache服务的用户和组
[root@z1 ~]# useradd -r -M -s /sbin/nologin apache

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

//下载和安装apr以及apr-util
[root@z1 ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@z1 ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@z1 ~]# ls
anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz
[root@z1 ~]# tar xf apr-1.7.0.tar.gz 
[root@z1 ~]# tar xf apr-util-1.6.1.tar.gz 
[root@z1 ~]# ls
anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz
apr-1.7.0        apr-util-1.6.1
[root@z1 ~]# cd apr-1.7.0
[root@z1 apr-1.7.0]# vim configure
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    $RM "$cfgfile"    //将此行加上注释,或者删除此行
[root@z1 apr-1.7.0]# ./configure --prefix=/usr/local/apr
配置过程略...
[root@z1 apr-1.7.0]# make 
[root@z1 apr-1.7.0]# make install
编译安装过程略...

[root@z1 apr-1.7.0]# cd ../apr-util-1.6.1
[root@z1 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
配置过程略...
[root@z1 apr-util-1.6.1]# make
[root@z1 apr-util-1.6.1]# make install
编译安装过程略...

//编译安装httpd
[root@z1 ~]# wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
[root@z1 ~]# tar xf httpd-2.4.54.tar.gz 
[root@z1 ~]# cd httpd-2.4.54
[root@z1 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@z1 httpd-2.4.54]# make && make install
编译安装过程略...

//安装后配置
[root@z1 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@z1 ~]# source /etc/profile.d/httpd.sh
[root@z1 ~]# which httpd
/usr/local/apache/bin/httpd
[root@z1 ~]# ln -s /usr/local/apache/include/ /usr/include/apache
[root@z1 ~]# 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  //添加这行


//启动apache并设置开机自启
[root@z1 ~]# cd /usr/lib/systemd/system
[root@z1 system]# cp sshd.service httpd.service
[root@z1 system]# vim httpd.service 
[Unit]
Description=web server daemon
Documentation=man:httpd(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@z1 ~]# systemctl daemon-reload
[root@z1 ~]# systemctl start httpd
[root@z1 ~]# 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@z1 ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@z1 ~]# systemctl status httpd
● httpd.service - web server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor pr>
   Active: active (running) since Wed 2022-08-03 08:54:31 CST; 38s ago
     Docs: man:httpd(5)
 Main PID: 48142 (httpd)
    Tasks: 6 (limit: 4744)
   Memory: 5.0M
   CGroup: /system.slice/httpd.service
           ├─48142 /usr/local/apache/bin/httpd -k start
           ├─48148 /usr/local/apache/bin/httpd -k start
           ├─48149 /usr/local/apache/bin/httpd -k start
           ├─48150 /usr/local/apache/bin/httpd -k start
           ├─48151 /usr/local/apache/bin/httpd -k start
           └─48152 /usr/local/apache/bin/httpd -k start

Aug 03 08:54:16 z1 systemd[1]: Starting web server daemon...
Aug 03 08:54:31 z1 apachectl[48139]: AH00558: httpd: Could not reliably dete>
Aug 03 08:54:31 z1 systemd[1]: Started web server daemon.

安装mysql

//安装依赖包
[root@z1 ~]# dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

//创建用户和组
[root@z1 ~]# useradd -r -M -s /sbin/nologin mysql

//下载二进制格式的mysql软件包
[root@z1 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz


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

//修改目录/usr/local/mysql的属主属组
[root@z1 local]# chown -R mysql.mysql mysql
[root@z1 local]# ll
total 0
drwxr-xr-x. 14 root  root  164 Aug  3 08:41 apache
drwxr-xr-x.  6 root  root   58 Aug  3 08:20 apr
drwxr-xr-x.  5 root  root   43 Aug  3 08:24 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 Aug  3 04:02 lib64
drwxr-xr-x.  2 root  root    6 May 19  2020 libexec
drwxr-xr-x.  9 mysql mysql 129 Aug  3 09:07 mysql
drwxr-xr-x.  2 root  root    6 May 19  2020 sbin
drwxr-xr-x.  5 root  root   49 Aug  3 04:02 share
drwxr-xr-x.  2 root  root    6 May 19  2020 src

//配置mysql
[root@z1 local]# ls /usr/local/mysql/
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@z1 local]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@z1 local]# echo '/usr/local/mysql/lib/' > /etc/ld.so.conf.d/mysql.conf
[root@z1 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@z1 ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@z1 ~]# source /etc/profile.d/mysql.sh 
[root@z1 ~]# which mysql
/usr/local/mysql/bin/mysql


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


//初始化数据库
[root@z1 ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2022-08-03T01:19:59.639725Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-03T01:19:59.640021Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-03T01:19:59.713231Z 1 [Note] A temporary password is generated for root@localhost: 2!>srargX1nU   
[root@z1 ~]# echo '2!>srargX1nU' > pass

//卸载mariadb的所有包
[root@z1 ~]# dnf -y remove mariadb*

//生成配置文件
[root@z1 ~]# vim /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@z1 ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@z1 ~]# vi /etc/init.d/mysqld
basedir=/usr/local/mysql    
datadir=/opt/data
[root@z1 ~]# chmod +x /etc/init.d/mysqld 

//启动mysql 并设置开机自启
[root@z1 ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/z1.err'.
 SUCCESS! 
[root@z1 ~]# 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               [::]:*  
[root@z1 ~]# chkconfig --add mysqld
[root@z1 ~]# 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@z1 ~]# cat pass 
2!>srargX1nU
[root@z1 ~]# mysql -uroot -p'2!>srargX1nU'
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 2
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)

安装php

//下载php
[root@z1 ~]# wget https://www.php.net/distributions/php-7.4.30.tar.xz

//安装依赖包
[root@z1 ~]# dnf -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@z1 ~]# tar xf php-7.4.30.tar.xz 
[root@z1 ~]# cd php-7.4.30
[root@z1 php-7.4.30]# ./configure --prefix=/usr/local/php7  --with-config-file-path=/etc --enable-fpm --enable-inline-optimization --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-json --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
[root@z1 php-7.4.30]# make
编译过程略
[root@z1 php-7.4.30]# make install
安装过程略


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

//配置php-fpm
[root@z1 php-7.4.30]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@z1 php-7.4.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@z1 php-7.4.30]# chmod +x /etc/init.d/php-fpm 
[root@z1 ~]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

//启动php-fpm
[root@z1 ~]# service php-fpm start
Starting php-fpm  done

//默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验证其是否已经监听在相应的套接字
[root@z1 ~]# 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           127.0.0.1:9000          0.0.0.0:*              
LISTEN  0       128                   *:80                  *:*              
LISTEN  0       128                [::]:22               [::]:*              
LISTEN  0       80                    *:3306                *:*  

//设置开机自启
[root@z1 ~]# chkconfig --add php-fpm
[root@z1 ~]# 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

安装报错问题

//登录mysql报错
[root@z1 ~]# mysql -uroot -p'2!>srargX1nU'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@z1 ~]# dnf -y install ncurses-compat-libs    //安装这个包
//编译安装php报错
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:

Package 'sqlite3', required by 'virtual:world', not found
[root@z1 php-7.4.30]# dnf -y install libsqlite3x-devel  //安装这个包
//编译安装php报错
configure: error: Package requirements (oniguruma) were not met:

Package 'oniguruma', required by 'virtual:world', not found
[root@z1 php-7.4.30]# dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
//安装这个包

//编译安装php报错
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
Package 'libzip', required by 'virtual:world', not found
[root@z1 ~]# dnf -y install libzip-devel   //安装这个包


这篇关于lamp的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!