1. 程式人生 > >CenOS 7 rpm包安裝lamp

CenOS 7 rpm包安裝lamp

for go it!

CentOS 7 LAMP

vhost1: phpMyadmin 布署pma.mykernel.cn https

vhost2: wordpress 布署wp.mykernel.cn

vhost3: Discuz 布署dz.mykernel.cn

實驗環境

技術分享

關閉防火墻: iptables -F

搭建LAMP環境

  • 準備虛擬主機的DocumentRoot

      # mkdir -pv /web/vhosts
      # chcon -t httpd_sys_content_t /web/vhosts
      # mkdir /web/vhosts/{pma,wp,dz}
  • 準備虛擬主機

    • 安裝程序包和備份配置文件

        # yum -y install apr apr-util httpd
        # cp -v /etc/httpd/conf/httpd.conf{,.bak}
    • 在主配置文件中,註釋中心主機

        配置文件: /etc/httpd/conf/httpd.conf
        #DocumentRoot "/var/www/html"
    • 在conf.d/*.conf添加虛擬主機

        # vim /etc/httpd/conf.d/virtualhost.conf
            #phpMyadmin
            <VirtualHost *:80>
              DocumentRoot /web/vhosts/pma
              ServerName pma.mykernel.cn
              CustomLog logs/pma_access.log combined
              ErrorLog  logs/pma_error.log
              <Directory "/web/vhosts/pma">
                Options FollowSymLinks
                AllowOverride None
                Require all granted
              </Directory>
            </VirtualHost>
            #wordpress
            <VirtualHost *:80>
              DocumentRoot /web/vhosts/wp
              ServerName wp.mykernel.cn
              CustomLog logs/wp_access.log combined
              ErrorLog  logs/wp_error.log
              <Directory "/web/vhosts/wp">
                 Options FollowSymLinks
                AllowOverride None
                Require all granted
              </Directory>
            </VirtualHost>
            #disscuzz
            <VirtualHost *:80>
              DocumentRoot /web/vhosts/dz
              ServerName dz.mykernel.cn
              CustomLog logs/dz_access.log combined
              ErrorLog  logs/dz_error.log
              <Directory "/web/vhosts/dz">
                Options FollowSymLinks
                AllowOverride None
                Require all granted
              </Directory>
            </VirtualHost>
    • 測試語法

        # httpd -t
    • 啟動web服務

        # systemctl start httpd.service
    • 測試是否能訪問

        1.windows
            在C:\Windows\System32\drivers\etc\hosts文件中添加如下內容(用於解析域名)
                192.168.3.186           pma.mykernel.cn
                192.168.3.186           wp.mykernel.cn
                192.168.3.186           dz.mykernel.cn
            打開Google瀏覽器,分別輸入: pma.mykernel.cn wp.mykernel.cn dz.mykernel.cn,都將顯示: Testing 123..
      
        2.linux
            在/etc/hosts文件中添加如下內容(用於解析域名)
                192.168.3.186           pma.mykernel.cn
                192.168.3.186           wp.mykernel.cn
                192.168.3.186           dz.mykernel.cn
            安裝可訪問文件協議的客戶端工具
                # yum -y install telnet curl elinks
            測試訪問
                # curl http://192.168.3.186
                # elinks --dump http://192.168.3.186     
      
                # telnet 192.168.3.186 80
                Escape character is ‘^]‘.
                HEAD / HTTP/1.1
                Host:192.168.3.186
  • 安裝php作為httpd的模塊而存在: libphp5.so(prefork) libphp5-zts.so(work, event)

      # yum -y install php
      # rpm -ql php
      /etc/httpd/conf.d/php.conf               //為libphp5.so提供的配置
      /etc/httpd/conf.modules.d/10-php.conf    //裝載此模塊
      /usr/lib64/httpd/modules/libphp5.so      //提供給httpd的php模塊,僅能用於prefork模型
      # systemctl restart httpd                //基於module需要重啟web讀取php配置
    • 查看當前mpm

        # httpd -M
    • 測試能否運行php程序

        # for i in wp dz pma; do echo -e "<?php\nphpinfo();\n?>" > /web/vhosts/$i/index.php ; done
    • 在windows瀏覽器中測試

  • 安裝php-mysql和mariadb-server用於提供應用程序服務器中運行中的程序需要用到後端mysql提供的數據時,php-mysql用於封裝和解析請求,mariadb-server用於存儲數據.

      # yum -y install php-mysql mariadb-server
    • 啟動mariadb(mysql分支的開源實現)

        # systemctl start mariadb.service
        # ss -tunl                          //觀察3306端口
        # systemctl reload httpd.service    //重載web服務
    • 測試連接MariaDB

        # mysql
    • 在各個虛擬主機中添加以下內容,並在windows主機中測試用php-mysql的函數庫連接mysql

        <?php
          $link=mysql_connect(‘localhost‘,‘root‘,‘‘);
          if($link)
            echo ok;
          else
            echo failure;
          mysql_close();
          phpinfo();
        ?>

一、布署phpMyadmin(MariaDB webGUI)

  • 安裝依賴:

      # yum -y install php-mbstring
      # systemctl restart httpd.service
  • 下載phpMyadmin

      https://files.phpmyadmin.net/phpMyAdmin/4.0.10.20/phpMyAdmin-4.0.10.20-all-languages.zip
  • 展開至DocumentRoot

      # cd /web/vhosts/pma
      # unzip ~/phpMyAdmin-4.0.10.20-all-languages.zip
      # ln -sv phpMyAdmin-4.0.10.20-all-languages pma   //便於版本升級
  • 配置

      # cp pma/config.sample.inc.php pma/config.inc.php 
      # openssl rand -base64 32
      ZAN6DZ6ov68hG0PIKIiXUukwWaoqPYvmzOQ1UnlqQcQ=
      # vim pma/config.inc.php  //在YOU MUST FILL IN THIS FOR COOKIE AUTH! */ 前修改隨機數為生成的隨機數
      $cfg[‘Servers‘][$i][‘AllowNoPassword‘] = false;  //表示不能空密碼登入phpMyadmin
  • 給root用戶添加密碼

      # mysql
      MariaDB [(none)]> set password for ‘root‘@‘127.0.0.1‘=PASSWORD(‘123‘);
      MariaDB [(none)]> set password for ‘root‘@‘localhost‘=PASSWORD(‘123‘);
      MariaDB [(none)]> FLUSH PRIVILEGES;
      MariaDB [(none)]> quit
      # mysql -uroot -p123
  • 在windows主機上測試連接phpMyadmin

      http://pma.mykernel.cn/pma
  • 配置https

    • 建立ca <192.168.3.193>

        # openssl version
        # dir=/etc/pki/CA
        # touch $dir/index.txt
        # echo "01" > $dir/serial
        # (umask 077;openssl genrsa -out $dir/private/cakey.pem 4096)
        # openssl req -new -x509 -key $dir/private/cakey.pem -out $dir/cacert.pem -days 7300
            (SC, ChengDu, ChengDu, MageEdu Ltd, Ops, ca.mykernel.cn, [email protected])
    • 申請請求 <192.168.3.186>

        # install -d /etc/httpd/ssl
        # cd /etc/httpd/ssl
        # (umask 077;openssl genrsa -out httpd.key 4096)
        # openssl req -new -key httpd.key -out httpd.csr -days 7300
            (SC, ChengDu, ChengDu, MageEdu Ltd, Ops, pma.mykernel.cn, [email protected])
    • 提交請求 <192.168.3.186>

        # scp httpd.csr [email protected]:/tmp
    • 簽證 <192.168.3.193>

        # openssl ca -in /tmp/httpd.csr -out $dir/certs/pma.mykernel.cn.crt -days 365
    • 獲取證書 <192.168.3.193>

        # scp $dir/certs/pma.mykernel.cn.crt [email protected]:/etc/httpd/ssl
    • 安裝mod_ssl (SSL/TLS module for the Apache HTTP Server) <192.168.3.186>

        # yum -y install mod_ssl
    • 配置使用ssl <192.168.3.186>

        # rpm -qc mod_ssl
        /etc/httpd/conf.d/ssl.conf
        /etc/httpd/conf.modules.d/00-ssl.conf
        # cp -v /etc/httpd/conf.d/ssl.conf{,.bak}
        # vim /etc/httpd/conf.d/ssl.conf
            <VirtualHost *:443>
            DocumentRoot "/web/vhosts/pma/"
            ServerName pma.mykernel.cn
            SSLEngine on
            SSLCertificateFile /etc/httpd/ssl/pma.mykernel.cn.crt
            SSLCertificateKeyFile /etc/httpd/ssl/httpd.key
            <Directory "/web/vhosts/pma">
              Options None
              AllowOverride FollowSymLinks
              Require all granted
            </Directory>
        # systemctl restart httpd.service      //需要重新監聽更多的端口
        # ss -tnl

二、布署wordpress

  • 下載wordpress

      https://cn.wordpress.org/wordpress-4.8.1-zh_CN.zip
  • 展開至DocumentRoot

       # cd /web/vhosts/pma
      # unzip ~/wordpress-4.8.1-zh_CN.zip
      # ln -sv wordpress wp
  • 配置

      # cp wp/wp-config-sample.php wp/wp-config.php
      /** WordPress數據庫的名稱 */
      define(‘DB_NAME‘, ‘wpdb‘);
      /** MySQL數據庫用戶名 */
      define(‘DB_USER‘, ‘wpuser‘);
      /** MySQL數據庫密碼 */
      define(‘DB_PASSWORD‘, ‘[email protected]‘);
  • 添加一個管理wordpress數據庫"wpdb"的用戶"wpuser"

      # mysql -uroot -p123
      MariaDB [(none)]> CREATE DATABASE wpdb;
      MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘wpuser‘@‘localhost‘ IDENTIFIED BY ‘[email protected]‘;
      MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘wpuser‘@‘127.0.0.1‘ IDENTIFIED BY ‘[email protected]‘;
      MariaDB [(none)]> FLUSH PRIVILEGES;
      MariaDB [(none)]> quit
      # mysql -uwpuser [email protected]
  • 在windows主機上測試連接wordpress

      http://wp.mykernel.cn/wp

    三、布署disscuzz

  • 下載disscuzz

      http://download.comsenz.com/DiscuzX/2.5/Discuz_X2.5_SC_UTF8.zip
  • 展開至DocumentRoot

      # cd /web/vhosts/dz
      # unzip ~/Discuz_X2.5_SC_UTF8.zip
  • 配置

      # setenforce 0
      # cd upload       
      # setfacl -R -m u:apache:rwx config data uc_client uc_server
  • 添加一個管理disscuzz數據庫"dzdb"的用戶"dzuser"

      # mysql -uroot -p123
      MariaDB [(none)]> CREATE DATABASE dzdb;
      MariaDB [(none)]> GRANT ALL ON dzdb.* TO ‘dzuser‘@‘localhost‘ IDENTIFIED BY ‘[email protected]‘;
      MariaDB [(none)]> GRANT ALL ON dzdb.* TO ‘dzuser‘@‘127.0.0.1‘ IDENTIFIED BY ‘[email protected]‘;
      MariaDB [(none)]> FLUSH PRIVILEGES;
      MariaDB [(none)]> quit
      # mysql -udzuser [email protected]
  • 在windows主機上測試連接disscuzz

      http://dz.mykernel.cn/upload

感激

  • QQ: 2580259468

  • 博客

  • 技術分享


本文出自 “Reading” 博客,請務必保留此出處http://sonlich.blog.51cto.com/12825953/1970609

CenOS 7 rpm包安裝lamp