天天看點

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