天天看点

linux yum 搭建 apache+php+mysql 环境

1. 安装apache

安装apache

yum -y install httpd

安装apache扩展

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

apache 常用指令
  1. 启动apache

    service httpd start

  2. 停止apache

    service httpd stop

  3. 重启apache

    service httpd restart

2. 安装php

安装php

yum -y install php php-mysql

安装php扩展

yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc

注意: 安装指定版本php请按照如下步骤

不同的系统安装不同的PHP需要先更新包,下面三个地址根据情况去选择

CentOS/RHEL 7.x:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

CentOS/RHEL 6.x:

rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

  1. 卸载php

    yum remove php

    yum remove php-*

  2. 安装php7

    yum install php70w php70w-opcache php70w-mysql php70w-mcrypt php70w-mbstring

  3. 安装其他插件(选装)

    php70w

    php70w-bcmath

    php70w-cli

    php70w-common

    php70w-dba

    php70w-devel

    php70w-embedded

    php70w-enchant

    php70w-fpm

    php70w-gd

    php70w-imap

    php70w-interbase

    php70w-intl

    php70w-ldap

    php70w-mbstring

    php70w-mcrypt

    php70w-mysql

    php70w-mysqlnd

    php70w-odbc

    php70w-opcache

    php70w-pdo

    php70w-pdo_dblib

    php70w-pear

    php70w-pecl-apcu

    php70w-pecl-imagick

    php70w-pecl-xdebug

    php70w-pgsql

    php70w-phpdbg

    php70w-process

    php70w-pspell

    php70w-recode

    php70w-snmp

    php70w-soap

    php70w-tidy

    php70w-xml

    php70w-xmlrpc

3. 安装mysql

安装mysql

yum -y install mysql mysql-server

安装mysql扩展

yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

注意: 如果想要安装指定版本mysql请按照如下步骤

  1. 卸载以前安装的mysql

    yum remove mysql

  2. 查看mysql可用版本

    yum repolist enabled | grep “mysql.-community.”

  3. 安装指定版本mysql

    yum仓库下载MySQL

    sudo yum localinstall https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm

    https://repo.mysql.com/ (这个域名下面有很多mysql版本可以选择)

  4. yum安装MySQL:

    sudo yum install mysql-community-server

mysql 常用指令
  1. 检查mysql 服务状态

    sudo service mysqld status

  2. 启动mysql

    service mysqld start

  3. 重启mysql

    service mysqld restart

  4. 停机mysql服务

    service mysqld stop

报错解决方案:
 -  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
启动mysql : service mysqld start

 - ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
登录mysql需要密码: mysql -uroot -proot

查看mysql初始密码步骤:
 - 1. more  /etc/my.cnf (查看log-error=/var/log/mysqld.log 的配置路径)
 - 2. more /var/log/mysqld.log |grep 'temporary password'
 - 2019-07-20T10:00:51.966304Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: 3Dl#nl,/wa.y
 - 3Dl#nl,/wa.y   就是初始密码(特别注意:如果查看密码为空,需要先启动mysql才会生成哟)

 命令行连接mysql:  mysql -uroot -p3Dl#nl,/wa.y
           
  1. 重置mysql密码
  • use mysql

    update user set password = password(“root”) where user =

    “root”;

    flush privileges;

  • alter user ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password

    by ‘你的mysql密码’;

报错解决方案:

 - ERROR 1820 (HY000): You must reset your password using ALTER USER
   statement before executing this statement.
 - ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

设置策略:set global validate_password.policy=0;
然后使用:alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '你的mysql密码';  修改密码
           

配置apache

  1. cd /etc/httpd/conf.d
  2. 新建一个文件 vi test.conf
<VirtualHost *:80>
        AddDefaultCharset UTF-8
        ServerAdmin [email protected]
        DocumentRoot "/home/www/test"
        ServerName www.huaban1314.com
        php_admin_value open_basedir .:/home/www/:/home/data:/home/logs:/home/www/test/logs/*:/var/tmp:/tmp:
        
        ErrorLog logs/test_error_log
        TransferLog logs/test_access_log
    
        CustomLog logs/test \
              "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    
        <Directory "/home/www/test">
            AllowOverride None
            Options None
            Order allow,deny
            Allow from all
        </Directory>
    
    </VirtualHost>
           
  1. 重启apache

    service httpd restart