zoukankan      html  css  js  c++  java
  • centos7 用yum快速搭建LAMP环境


    注:按照步骤一步步走,亲测成功
    先查看试验环境

    1.[root@localhost ~]# cat /etc/redhat-release
    CentOS Linux release 7.8.2003 (Core)
    2.[root@localhost ~]# uname -a
    Linux localhost 3.10.0-1127.8.2.el7.x86_64 #1 SMP Tue May 12 16:57:42 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

    1、安装apache
    1.1 安装apache

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

    1.2 启动apache服务

    [root@localhost ~]# systemctl start httpd

    1.3 设置httpd服务开机启动

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

    1.4 查看服务状态
    命令:[root@localhost ~]# systemctl status httpd

    1.5 防火墙设置开启80端口

    1.[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=http
    success
    2.[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=https
    success
    3.[root@localhost ~]# firewall-cmd --reload
    success

     注:如果出现FirewallD is not running,表示防火墙未运行,需要启动防火墙,

    启动命令:systemctl start firewalld ,查看状态:systemctl status firewalld

    1.6确认80端口监听中

    [root@localhost ~]# netstat -nltp

     

     1.8 查服务器IP

    [root@localhost ~]# ip a

     1.9 浏览器登陆

     2、安装mysql

    [root@localhost ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel

    [root@localhost ~]# rpm -qa |grep maria
    mariadb-libs-5.5.52-1.el7.i686
    mariadb-5.5.52-1.el7.i686
    mariadb-server-5.5.52-1.el7.i686
    mariadb-devel-5.5.52-1.el7.i686

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

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

    [root@localhost ~]# netstat -nltp

     

    注:如果输入 netstat -tulp没有此命令可以自行去yum下载netstat
     2.3 数据库安全设置

    [root@localhost ~]# 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.

    是否设置root用户密码,输入y并回车或直接回车

    Set root password? [Y/n]

    设置root用户的密码
    New password: 123123

    确认root用户密码
    Re-enter new password: 123123
    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.

    是否禁止root远程登录

    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.

    是否删除test数据库

    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@localhost ~]# mysql -uroot -p  (密码:123123)

     3、安装PHP

    [root@localhost ~]# yum -y install php

    [root@localhost ~]# rpm -ql php
    /etc/httpd/conf.d/php.conf
    /etc/httpd/conf.modules.d/10-php.conf
    /usr/lib/httpd/modules/libphp5.so
    /usr/share/httpd/icons/php.gif
    /var/lib/php/session

    3.2 将php与mysql关联起来

    [root@localhost ~]# yum install php-mysql
    [root@localhost ~]# rpm -ql php-mysql
    /etc/php.d/mysql.ini
    /etc/php.d/mysqli.ini
    /etc/php.d/pdo_mysql.ini
    /usr/lib/php/modules/mysql.so
    /usr/lib/php/modules/mysqli.so
    /usr/lib/php/modules/pdo_mysql.so
    3.3 安装常用PHP模块

    [root@localhost ~]# 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

    [root@localhost ~]# cd /var/www/html/
    [root@localhost html]# ll
    [root@localhost html]# pwd
    /var/www/html
    [root@localhost html]# vim info.php

    <?php
    phpinfo();
    ?>
    ~
    wq!

    3.5重启apache服务器

    [root@localhost html]#  systemctl restart httpd

    3.6测试PHP

    在自己电脑浏览器输入 192.168.0.205/info.php,你可以看到已经安装的模块。

  • 相关阅读:
    浏览器的渲染与小优化
    css3 贝塞尔曲线理解
    mac下配置汇编环境
    报错 net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)
    vue中使用iframe,加载完成的onload事件偶尔不触发
    nrm的使用
    js原生实现元素跟随鼠标拖动
    webpack多页面打包笔记
    关于React的组件优化笔记
    React生成器
  • 原文地址:https://www.cnblogs.com/yangzp/p/13040193.html
Copyright © 2011-2022 走看看