基于CentOS7實現LAMP(上)

基于CentOS7實現LAMP(上)

 

情景模式:

1php以模塊方式運行

 提供兩個虛擬主機;

                                     web1: phpMyAdmin, 同時提供ssl;

                                     web2: wordpress;

                                    

限于篇幅,本文的php采用模塊方式運行于httpd中,在下一篇博文:基于CentOS7實現LAMP(下),我會再介紹phpfpm方式,即fastCGI方式運行的實現,敬請期待。

為便于理解,文中##處均是我的注解

 

##首先安裝基礎軟件工具包                  

[root@localhost yum.repos.d]# yum groupinstall  "Development Tools" -y

 

##然后安裝httpd服務

[root@localhost yum.repos.d]# yum install httpd -y

 

##安裝mariadb

[root@localhost yum.repos.d]# yum install -y mariadb-server mariadb-devel mairadb

 

##安裝php,以httpd模塊方式

[root@localhost yum.repos.d]# yum install -y php php-devel php-mysql

yum install php php-devel php-mysql

 

##修改httpd.conf文件,配置兩個虛擬主機站點

#vim /etc/httpd/conf/httpd.conf

 

         ServerName web.test.net:80

         ##DocumentRoot "/var/www/html"

 

#cd /etc/httpd/conf.modules.d

#vim 00-mpm.conf

         LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

 

 

##添加對php網頁的支持    

#cd /etc/httpd/conf.d

#[root@web conf.d]# vim php.conf

       

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

 

DirectoryIndex index.php

 

<Directory "/www/web1">

  options none

  allowoverride none

  require all granted

</Directory>

 

<Directory "/www/web2">

  options none

  allowoverride none

  require all granted

</Directory>

 

 

[root@web conf.d]# vim vhosts.conf

<VirtualHost *:80>

  ServerName web1.test.net

  DocumentRoot /www/web1/

</VirtualHost>

 

<VirtualHost *:80>

  ServerName web2.test.net

  DocumentRoot /www/web2/

</VirtualHost>

 

##啟動httpd

[root@web conf]# httpd -t

Syntax OK

[root@web conf]#

[root@web conf]# systemctl start httpd.service

 

[root@web conf]# ss -ntlp | grep httpd

LISTEN     0      128         :::80                      :::*                   users:(("httpd",pid=9

2530,fd=4),("httpd",pid=92529,fd=4),("httpd",pid=92528,fd=4),("httpd",pid=92527,fd=4),("httpd",pid=92

526,fd=4),("httpd",pid=92524,fd=4))

[root@web conf]#

 

 

##實驗環境為避免影響,關閉本機的selinux及防火墻服務

[root@web /]# getenforce

Enforcing

[root@web /]# setenforce 0

[root@web /]#

[root@web /]# systemctl stop firewalld.service

 

[root@web /]# systemctl disable firewalld.service

Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

[root@web /]#

[root@web /]# vim /etc/selinux/config

SELINUX=disabled

##檢查網頁正常否

web1html.jpg

 

web2php.jpg

##安裝phpMyAdmin

[root@web setup]# tar xzvf phpMyAdmin-4.4.15.7-all-languages.tar.gz -C /www/web1/

[root@web web1]# mv phpMyAdmin-4.4.15.7-all-languages pma

[root@web pma]# cp config.sample.inc.php config.inc.php

[root@web pma]# vim config.inc.php

 

[root@web pma]# vim /etc/httpd/conf/httpd.conf

<Directory "/www/web1/pma">

  options none

  allowoverride none

  require all granted

</Directory>

 

[root@web pma]# systemctl reload httpd.service

 

 

[root@web modules]# systemctl start mariadb

 

##修改mysqlroot密碼為'redhat'

[root@web modules]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.50-MariaDB MariaDB Server

 

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]> use mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

 

Database changed

MariaDB [mysql]> update user set password=password('redhat');

Query OK, 6 rows affected (0.01 sec)

Rows matched: 6  Changed: 6  Warnings: 0

 

MariaDB [mysql]> flush privileges;

Query OK, 0 rows affected (0.01 sec)

 

MariaDB [mysql]> bye

    -> quit

    -> quit

    -> ;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'bye

quit

quit' at line 1

MariaDB [mysql]> quit

Bye

[root@web modules]#

 

##安裝wordpress

[root@web LAMP]# unzip wordpress-4.5.3-zh_CN.zip

[root@web LAMP]# cd wordpress/

[root@web wordpress]#

[root@web LAMP]# mv wordpress /www/web2/

[root@web LAMP]# cd /www/web2/wordpress

[root@web wordpress]# cp wp-config-sample.php wp-config.php

[root@web wordpress]# vim wp-config.php

 

##mysql創建wordpress的連接帳號

[root@web wordpress]# mysql -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 6

Server version: 5.5.50-MariaDB MariaDB Server

 

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]> use mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

 

Database changed

MariaDB [mysql]> create database wpdb;

Query OK, 1 row affected (0.01 sec)

MariaDB [mysql]> grant all on wpdb.* to 'wpuser'@'localhost' identified by 'redhat';

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [mysql]> flush privileges;

Query OK, 0 rows affected (0.01 sec)

 

MariaDB [mysql]> quit

Bye

 

##按上述創建的帳號信息,修改wordpressconfig文件

[root@web wordpress]# vim wp-config.php

// ** MySQL 設置具體信息來自您正在使用的主機 ** //

/** WordPress數據庫的名稱 */

define('DB_NAME', 'wpdb');

 

/** MySQL數據庫用戶名 */

define('DB_USER', 'wpuser');

 

/** MySQL數據庫密碼 */

define('DB_PASSWORD', 'redhat');

 

/** MySQL主機 */

define('DB_HOST', 'localhost');

 

/** 創建數據表時默認的文字編碼 */

define('DB_CHARSET', 'utf8');

 

 

##測試

http://web2.test.net/wordpress/wp-admin/install.php

wordpress1.png

 

 wordpress3.png

 

##以下為為web1.test.net站點提供ssl功能,簡單起建,將自建的證書服務器都放在本臺機器上了。

因為搭建自建證書及https站點不是本文重點,所以只是簡單show一下操作步驟,有興趣了解詳細內容的同學,請移步到我的另一篇博文:自建CA搭建SSL加密網站

 

##自建證書

[root@web wordpress]# cd /etc/pki/CA

You have new mail in /var/spool/mail/root

[root@web CA]# ls

certs  crl  newcerts  private

[root@web CA]# (umask 077; openssl genrsa -out private/cakey.pem 2048)

Generating RSA private key, 2048 bit long modulus

………………………………………………………………………………………………………+++

………………..+++

e is 65537 (0x10001)

[root@web CA]# touch index.txt

[root@web CA]# echo 01 > serial

[root@web CA]#

[root@web CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 7300

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

—–

Country Name (2 letter code) [XX]:CN

State or Province Name (full name) []:NanHai  

Locality Name (eg, city) [Default City]:NanHai

Organization Name (eg, company) [Default Company Ltd]:MageEdu Ltd

Organizational Unit Name (eg, section) []:IT

Common Name (eg, your name or your server's hostname) []:ca.test.net

Email Address []:caadmin@test.net

[root@web CA]#

 

 

[root@web CA]# cd /etc/httpd

[root@web httpd]# ls

conf  conf.d  conf.modules.d  logs  modules  run

[root@web httpd]# mkdir ssl

[root@web httpd]# cd ssl

[root@web ssl]# (umask 077; openssl genrsa -out httpd.key 1024)

Generating RSA private key, 1024 bit long modulus

……++++++

………………..++++++

e is 65537 (0x10001)

[root@web ssl]# openssl req -new -key httpd.key -out httpd.csr

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

—–

Country Name (2 letter code) [XX]:CN

State or Province Name (full name) []:NanHai

Locality Name (eg, city) [Default City]:NanHai

Organization Name (eg, company) [Default Company Ltd]:MageEdu Ltd

Organizational Unit Name (eg, section) []:IT

Common Name (eg, your name or your server's hostname) []:web1.test.net

Email Address []:webadmin@test.net

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

[root@web ssl]#

[root@web ssl]# cd /etc/pki/CA/

[root@web CA]# openssl ca -in /etc/httpd/ssl/httpd.csr -out certs/web1.test.net.crt -days 365

Using configuration from /etc/pki/tls/openssl.cnf

Check that the request matches the signature

Signature ok

Certificate Details:

        Serial Number: 1 (0x1)

        Validity

            Not Before: Aug 15 17:04:05 2016 GMT

            Not After : Aug 15 17:04:05 2017 GMT

        Subject:

            countryName               = CN

            stateOrProvinceName       = NanHai

            organizationName          = MageEdu Ltd

            organizationalUnitName    = IT

            commonName                = web1.test.net

            emailAddress              = webadmin@test.net

        X509v3 extensions:

            X509v3 Basic Constraints:

                CA:FALSE

            Netscape Comment:

                OpenSSL Generated Certificate

            X509v3 Subject Key Identifier:

                A7:03:2F:F2:3D:9A:10:9D:4E:00:D7:01:F9:36:83:77:CA:77:04:BA

            X509v3 Authority Key Identifier:

                keyid:02:80:D4:1C:8D:69:7D:2B:1B:71:44:63:8B:51:DC:EE:2D:71:54:3E

 

Certificate is to be certified until Aug 15 17:04:05 2017 GMT (365 days)

Sign the certificate? [y/n]:y

 

 

1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

[root@web CA]#

[root@web CA]# cd certs/

[root@web certs]# ls

web1.test.net.crt

[root@web certs]# pwd

/etc/pki/CA/certs

[root@web certs]# cp web1.test.net.crt  /etc/httpd/ssl/

[root@web certs]#

 

##為站點添加mod_ssl模塊,以便支持ssl訪問

[root@web certs]# httpd -M | grep ssl

[root@web certs]# yum install mod_ssl

[root@web certs]# httpd -M | grep ssl

 ssl_module (shared)

[root@web certs]#

 

 

[root@web certs]# cd /etc/httpd/conf.d/

[root@web conf.d]# ls

autoindex.conf  php.conf  README  ssl.conf  userdir.conf  vhosts.conf  welcome.conf

[root@web conf.d]# cp ssl.conf{,.bak}

[root@web conf.d]# vim ssl.conf

 

##添加ssl站點設置

<VirtualHost 172.16.10.1:443>

SSLEngine on

##SSLCertificateFile /etc/pki/tls/certs/localhost.crt

SSLCertificateFile /etc/httpd/ssl/web1.test.net.crt

 

##SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

SSLCertificateKeyFile /etc/httpd/ssl/httpd.key

 

DocumentRoot "/www/web1"

ServerName web1.test.net

 

 

<Directory "/www/web1/">

   require all granted

</Directory>

 

<Directory "/www/web1/pma/">

    require all granted

</Directory>

 

 

##重啟服務

[root@web conf.d]# httpd -t

Syntax OK

[root@web conf.d]# systemctl restart httpd.service

[root@web conf.d]#

 

[root@web conf.d]# ss -ntlp  | grep 443

LISTEN     0      128         :::443                     :::*                   users:(("httpd",pid=7621,fd=6),("httpd",pid=7620,fd=6),("httpd",pid=7619,fd=6),("httpd",pid=7618,fd=6),("httpd",pid=7617,fd=6),("httpd",pid=7615,fd=6))

[root@web conf.d]#

 

 

##檢查網站

證書信息.png

##證書并未在客戶端導入,所以會有出錯的警示信息,請忽略,呵呵。重點是已經能夠以https訪問站點了。。。

##至此,網站創建完畢,測試使用正常。

 

 

 

 

原創文章,作者:馬哥Net19_小斌斌,如若轉載,請注明出處:http://www.www58058.com/36261

(0)
馬哥Net19_小斌斌馬哥Net19_小斌斌
上一篇 2016-08-22 09:29
下一篇 2016-08-22 09:29

相關推薦

  • 系統自動化安裝和SELinux

    一、知識整理 1、anaconda系統安裝程序:默認圖形啟動; 使用光盤啟動,在選擇模式界面tab鍵在后面增加text或按下ESC鍵,輸入lnux text進入字符界面安裝。 2、創建kickstart文件: 直接手動編輯:依據模板修改,/root目錄下的anaconda.cfg 使用創建工具創建:system-config-kickstart,圖形化工具:…

    Linux干貨 2016-09-26
  • ssh登陸與端口轉發

    ssh: secure shell, protocol, 22/tcp,  安全的遠程登錄     具體的軟件實現:OpenSSH  : ssh 協議的開源實現,CentOS 默認安裝dropbear :另一個開源實現SSH      協議版本   …

    Linux干貨 2017-04-13
  • gawk基礎及進階

    GUN awk: 文本處理三工具:grep,sed,awd grep,egrep,fgrep:文本過濾工具:pattern sed:行編輯器 模式空間、保持空間 awk:報告生成器,格式化文本輸出; AWK:Aho,Weinberger,Kernighan –> New AWK,NAWK GNU awk,gawk gawk – …

    Linux干貨 2017-05-22
  • Linux運維學習歷程-第六天-Linux重定向和管道

    Linux運維學習歷程-第六天-Linux重定向和管道 2 本章內容我們將學習linux中的重定向和管道兩大用法   I/O輸入與輸出設備   重定向   管道   tee命令與tr命令 一、I/O設備   1、什么是I/O設備   管理和控制計算機的所有輸入/輸出(I/O)設備是操作系統…

    Linux干貨 2016-08-03
  • 馬哥教育網絡班21期+第一周課程練習

    一、計算機的組成及其功能 自上個世紀40年代開始截止到目前,我們所有的計算機包括手持的智能終端設備,它們整個組織體系設備都是遵循馮諾依曼體系結構。 現代計算機設備的組成部分: 運算器、控制器、存儲器、輸入設備、輸出設備 控制器:控制器是整個計算機的樞紐,一般是控制計算機整個部件之間協調的,比如運算器要想運算的話,首先得從存儲器中取出數值。或者輸入設備輸入數。…

    Linux干貨 2016-07-07
  • 腳本又見腳本,作業又是作業_第七周

    1、創建一個10G分區,并格式為ext4文件系統; (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl; (2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳; [root@centos ~]# fdisk -l &n…

    Linux干貨 2016-12-30
欧美性久久久久