zoukankan      html  css  js  c++  java
  • CentOS7利用yum搭建LAMP平台

    本人使用的是云主机,并非在本地搭建LAMP,但过程步骤也是大同小异,记录一下第一次搭建LAMP所踩的坑

    实验环境:

    [root@han01 ~]# cat  /etc/redhat-release
    CentOS Linux release 7.9.2009 (Core)
    [root@han01 ~]#  uname -a
    Linux han01 3.10.0-957.27.2.el7.x86_64 #1 SMP Mon Jul 29 17:46:05 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

    1.安装Apache

    1.1 安装Apache

    [root@han01 ~]# yum install httpd httpd-devel

    1.2 修改Apache监听端口(如果没有修改的必要,可以跳过此步骤)

    按照公司规定不能打开80端口,而Apache配置文件中默认的监听端口为80,出于安全保护,改为22222端口(随意挑选)

    etc/httpd/conf/httpd.conf文件中,改为listen 22222

    1.3 启动Apache服务 

    [root@han01 ~]# systemctl start httpd

    1.4 设置httpd服务开机启动

    [root@han01 ~]# systemctl enable  httpd
    Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

    1.5 查看服务状态

    [root@han01 /]# systemctl status httpd
     httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
       Active: active (running) since Thu 2021-01-14 09:48:29 CST; 1min 44s ago
         Docs: man:httpd(8)
               man:apachectl(8)
     Main PID: 15662 (httpd)
       Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
       CGroup: /system.slice/httpd.service
               ├─15662 /usr/sbin/httpd -DFOREGROUND
               ├─15663 /usr/sbin/httpd -DFOREGROUND
               ├─15664 /usr/sbin/httpd -DFOREGROUND
               ├─15665 /usr/sbin/httpd -DFOREGROUND
               ├─15666 /usr/sbin/httpd -DFOREGROUND
               └─15667 /usr/sbin/httpd -DFOREGROUND
    
    Jan 14 09:48:29 hanjuru-01 systemd[1]: Starting The Apache HTTP Server...
    Jan 14 09:48:29 hanjuru-01 httpd[15662]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::f816:3...s message
    Jan 14 09:48:29 hanjuru-01 systemd[1]: Started The Apache HTTP Server.
    Hint: Some lines were ellipsized, use -l to show in full.

    解决Apache AH00558问题方法:在上述etc/httpd/conf/httpd.conf配置文件中#ServerName www.example.com:80改为ServerName localhost:22222

    [root@hanjuru-01 /]# systemctl status httpd
     httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
       Active: active (running) since Thu 2021-01-14 10:21:39 CST; 41s ago
         Docs: man:httpd(8)
               man:apachectl(8)
     Main PID: 22537 (httpd)
       Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
       CGroup: /system.slice/httpd.service
               ├─22537 /usr/sbin/httpd -DFOREGROUND
               ├─22538 /usr/sbin/httpd -DFOREGROUND
               ├─22539 /usr/sbin/httpd -DFOREGROUND
               ├─22540 /usr/sbin/httpd -DFOREGROUND
               ├─22541 /usr/sbin/httpd -DFOREGROUND
               └─22542 /usr/sbin/httpd -DFOREGROUND
    
    Jan 14 10:21:39 hanjuru-01 systemd[1]: Stopped The Apache HTTP Server.
    Jan 14 10:21:39 hanjuru-01 systemd[1]: Starting The Apache HTTP Server...
    Jan 14 10:21:39 hanjuru-01 systemd[1]: Started The Apache HTTP Server

    1.6 开启防火墙

    [root@han01 ~]# systemctl start firewalld

    1.7 防火墙设置开启22222端口

    [root@hanjuru-01 /]# firewall-cmd --permanent --zone=public --add-port=22222/tcp
    success
    [root@hanjuru-01 /]# firewall-cmd --permanent --zone=public  --add-service=http
    success
    [root@hanjuru-01 /]# firewall-cmd --permanent --zone=public  --add-service=https
    success
    [root@hanjuru-01 /]# firewall-cmd --reload
    success

    1.8 确认端口监听中

    [root@han01 /]# netstat -tulp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:italk           0.0.0.0:*               LISTEN      20305/docker-proxy
    tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN      3801/sshd
    tcp6       0      0 [::]:22222              [::]:*                  LISTEN      22537/httpd
    tcp6       0      0 [::]:ftp                [::]:*                  LISTEN      9802/vsftpd
    tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      3801/sshd
    udp        0      0 0.0.0.0:bootpc          0.0.0.0:*                           3640/dhclient

    1.9 浏览器登录

    使用云主机的公网ip+端口号登录Apache进程

    2. 安装MySQL

    2.1 安装MySQL模块

    [root@hanjuru-01 /]# yum install mariadb mariadb-server mariadb-libs mariadb-devel

    查看已存在的mariadb

    [root@han01 /]# rpm -qa |grep maria
    mariadb-5.5.68-1.el7.x86_64
    mariadb-server-5.5.68-1.el7.x86_64
    mariadb-libs-5.5.68-1.el7.x86_64
    mariadb-devel-5.5.68-1.el7.x86_64

    2.2 开启mysql服务,并设置开机启动,检查mysql状态

    [root@han01 ~]# systemctl start  mariadb 
    [root@han01 ~]# systemctl enable  mariadb 
    Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
    [root@han01 ~]# systemctl status  mariadb 
    mariadb.service - MariaDB database server
    Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
    Active: active (running) since Thu 2021-01-14 15:15:19 CST; 11min ago
    Main PID: 7859 (mysqld_safe)
    CGroup: /system.slice/mariadb.service
    ├─7859 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
    └─8025 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log...
    Jan 14 15:15:16 hanjuru-01 mariadb-prepare-db-dir[7743]: MySQL manual for more instructions.
    Jan 14 15:15:16 hanjuru-01 mariadb-prepare-db-dir[7743]: Please report any problems at http://mariadb.org/jira
    Jan 14 15:15:16 hanjuru-01 mariadb-prepare-db-dir[7743]: The latest information about MariaDB is available at http://mariadb.org/.
    Jan 14 15:15:16 hanjuru-01 mariadb-prepare-db-dir[7743]: You can find additional information about the MySQL part at:
    Jan 14 15:15:16 hanjuru-01 mariadb-prepare-db-dir[7743]: http://dev.mysql.com
    Jan 14 15:15:16 hanjuru-01 mariadb-prepare-db-dir[7743]: Consider joining MariaDB's strong and vibrant community:
    Jan 14 15:15:16 hanjuru-01 mariadb-prepare-db-dir[7743]: https://mariadb.org/get-involved/
    Jan 14 15:15:17 hanjuru-01 mysqld_safe[7859]: 210114 15:15:17 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
    Jan 14 15:15:17 hanjuru-01 mysqld_safe[7859]: 210114 15:15:17 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
    Jan 14 15:15:19 hanjuru-01 systemd[1]: Started MariaDB database server.
    [root@han01 /]# netstat -tulp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:italk           0.0.0.0:*               LISTEN      20305/docker-proxy
    tcp        0      0 0.0.0.0:mysql           0.0.0.0:*               LISTEN      8025/mysqld
    tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN      3801/sshd
    tcp6       0      0 [::]:22222              [::]:*                  LISTEN      22537/httpd
    tcp6       0      0 [::]:ftp                [::]:*                  LISTEN      9802/vsftpd
    tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      3801/sshd
    udp        0      0 0.0.0.0:bootpc          0.0.0.0:*                           3640/dhclient

    2.3 数据库安全设置

    [root@han01 /]# mysql_secure_installation
    
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    
    Enter current password for root (enter for none):
    OK, successfully used password, moving on...
    
    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorisation.
    
    Set root password? [Y/n] y
    New password:
    Re-enter new password:
    Password updated successfully!
    Reloading privilege tables..
     ... Success!
    
    
    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.
    
    Remove anonymous users? [Y/n] y
     ... Success!
    
    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.
    
    Disallow root login remotely? [Y/n] n
     ... skipping.
    
    By default, MariaDB comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.
    
    Remove test database and access to it? [Y/n] y
     - Dropping test database...
     ... Success!
     - Removing privileges on test database...
     ... Success!
    
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    
    Reload privilege tables now? [Y/n] y
     ... Success!
    
    Cleaning up...
    
    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.
    
    Thanks for using MariaDB!

    2.4 登录数据库测试

    [root@han01 /]# mysql -uroot -p
    Enter password:
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 9
    Server version: 5.5.68-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.00 sec)

     3. 安装PHP

    3.1 安装php

    [root@han01 /]# yum -y install php
    [root@han01 /]# rpm -ql php
    /etc/httpd/conf.d/php.conf
    /etc/httpd/conf.modules.d/10-php.conf
    /usr/lib64/httpd/modules/libphp5.so
    /usr/share/httpd/icons/php.gif
    /var/lib/php/session

    3.2 将php与MySQL关联起来

    [root@han01 /]# yum install php-mysql
    [root@han01 /]# rpm -ql php-mysql
    /etc/php.d/mysql.ini
    /etc/php.d/mysqli.ini
    /etc/php.d/pdo_mysql.ini
    /usr/lib64/php/modules/mysql.so
    /usr/lib64/php/modules/mysqli.so
    /usr/lib64/php/modules/pdo_mysql.so

    3.3 安装常用PHP模块

    [root@han01 /]# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath

     3.4 新建PHP文件准备测试

    [root@han01 ~]# cd  /var/www/html/
    [root@han01 html]# ls
    [root@han01 html]# pwd
    /var/www/html
    [root@han01 html]# vi info.php
    <?php
            phpinfo();
    ?>

    3.5 重启apache服务

    [root@han01 ~]# systemctl restart httpd

    3.6 测试PHP

    输入网址/info.php看是否能看到已安装的模块,发现空白显示,检查了很长时间发现,原来是文件没有授予权限 

  • 相关阅读:
    Linux文件系统_每一个的意义
    Linux启动的流程
    Linux
    awk编程
    Junit测试Controller(MockMVC使用),传输@RequestBody数据解决办法
    spring boot get和post请求,以及requestbody为json串时候的处理
    Spring Boot快速入门
    Spring Boot 实用MyBatis做数据库操作
    极简操作无需root隐藏S8导航栏和状态栏
    springboot(三):Spring boot中Redis的使用
  • 原文地址:https://www.cnblogs.com/hhhhan1025/p/14276956.html
Copyright © 2011-2022 走看看