LAMP環境部署

LAMP架構:

Linux+Apache+Mysql+PHP

httpd # web服務器
mariadb-server #mysql數據庫
mariadb # mysql服務器linux下客戶端
php #php相關文件
php-mysql #??? #php程序連接mysql使用的模塊

官方網站:
http://www.mysql.com/
http://dev.mysql.com/downloads/mysql/
CentOS 7.0中,已經使用MariaDB替代了MySQL數據庫,原因你懂的,MYSQL被Oracle收購以後,前景堪憂,所以MYSQL兄弟MariaDB就出來了,繼續開源事業。

MySQL服務概述:
MySQL是一個關係型數據庫管理系統,由瑞典MySQL AB公司開發,目前屬於Oracle公司。
MySQL是最流行的關係型數據庫管理系統,在WEB應用方面MySQL是最好的RDBMS(Relational Database Management System:關係數據庫管理系統)應用軟件之一。

MySQL是一種關聯數據庫管理系統,關聯數據庫將數據保存在丌同的表中,而不是將所有數據放在一個大倉庫內,這樣就增加了速度並提高了靈活性。

MySQL所使用的SQL語言是用於訪問數據庫最常用標準化語言。MySQL軟件採用了雙授權政策,它分爲社區版和商業版,由於其體積小、速度快、總體擁有成本低,尤其是開放源碼這一特點,一般中小型網站的開發都選擇MySQL作爲網站數據庫。由於其社區版的性能卓越,搭配PHP和Apache可組成良好的開發環境。

雙授權政策:開放源代碼版本和商業版本。
例如:很多公司出售應用軟件,例如Microsoft、Apple和Oracle;
如Red Hat和IBM,則通過爲其開放源代碼軟件提供銷售支援、託管戒諮詢等服務來進行賺錢。但鮮爲人知的是,企業可以透過開放源代碼發佈仕們的軟件,也可以同時銷售該軟件的商業版本。

服務安裝

安裝需要的軟件包

[root@localhost ~]# yum -y install httpd mariadb-server mariadb php php-mysql

查看某個命令由哪個包安裝

[root@localhost ~]# rpm -qf `which mysql`
mariadb-5.5.64-1.el7.x86_64

查看apache版本:

[root@localhost ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Aug  8 2019 11:41:18
[root@localhost ~]# mysql -V
mysql  Ver 15.1 Distrib 5.5.64-MariaDB, for Linux (x86_64) using readline 5.1

啓動服務

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

當apache啓動較慢的時候可以修改一下配置文件
在這裏插入圖片描述
將ServerName 的註釋去掉,可以寫成真實的域名,或者寫成localhost都可以。

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf 
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl atart mariadb
Unknown operation 'atart'.
[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 ~]# netstat -lunt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     
udp        0      0 0.0.0.0:68              0.0.0.0:*                          
udp        0      0 127.0.0.1:323           0.0.0.0:*                          
udp6       0      0 ::1:323                 :::*            

查看服務有在正常運行,卻無法訪問,請查看防火牆firewalld

MySQL安全配置嚮導
安裝完mysql-server 會提示可以運行mysql_secure_installation。運行mysql_secure_installation會執行幾個設置:
a)爲root用戶設置密碼
b)刪除匿名賬號
c)取消root用戶遠程登錄
d)刪除test庫和對test庫的訪問權限
e)刷新授權表使修改生效
通過這幾項的設置能夠提高mysql庫的安全。建議生產環境中mysql安裝這完成後一定要運行一次mysql_secure_installation,詳細步驟請參看下面的命令:

[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):   #請回車開始設置mysql的安全向導
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y              #設置root密碼,回車默認選擇Y
New password:       輸入密碼
Re-enter new password: 再次輸入
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]    #是否移除匿名用戶
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]     #是否禁止root遠程登錄,root用戶允許本地登錄即可,允許遠程登錄太危險
 ... Success!

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.

Remove test database and access to it? [Y/n]   #移除test數據庫
 - 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]    #刷新權限表,如果不刷新,剛剛設置的就不會生效
 ... 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!    

登錄mysql

[root@localhost ~]# mysql -uroot -p123456   #登錄
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.64-MariaDB MariaDB Server

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

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

MariaDB [(none)]> show databases;    #查看數據庫
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]>     #[(none)]表示當前所在位置
MariaDB [(none)]> use mysql;    #進到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]> show tables;     #查看mysql庫的表
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
24 rows in set (0.00 sec)

MariaDB [mysql]> 

測試php是否安裝成功
進入到網站的根目錄

[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ll
總用量 0
[root@localhost html]# pwd
/var/www/html

寫一個php測試頁面

[root@localhost html]# cat index.php 
<?php
	phpinfo();
?>
[root@localhost html]# systemctl  restart httpd   #重啓apache服務

在瀏覽器輸入IP,訪問,能訪問就說明php.已經安裝成功
在這裏插入圖片描述

ucenter下載

https://addon.dismall.com/
http://download.comsenz.com/UCen … r_1.6.0_SC_UTF8.zip #後臺管理

上傳至服務器

[root@localhost ~]# ll
總用量 1176
-rw-------. 1 root root   1201 10月 21 01:15 anaconda-ks.cfg
-rw-r--r--. 1 root root 594363 10月 21 02:30 UCenter_1.6.0_SC_GBK.zip
-rw-r--r--. 1 root root 599301 10月 21 02:30 UCenter_1.6.0_SC_UTF8.zip

創建一個目錄,解壓

[root@localhost ~]# mkdir  ucadmin
[root@localhost ~]# mkdir  /var/www/html/ucadmin
[root@localhost ~]# unzip UCenter_1.6.0_SC_UTF8.zip
[root@localhost ~]# mv upload/* ucadmin/
[root@localhost ~]# cd ucadmin/
[root@localhost ucadmin]# ll
總用量 28
-rw-r--r--. 1 root root 2704 5月  20 2011 admin.php
drwxr-xr-x. 2 root root   23 5月  20 2011 api
-rw-r--r--. 1 root root 1757 5月  20 2011 avatar.php
drwxr-xr-x. 3 root root  222 5月  20 2011 control
-rw-r--r--. 1 root root  280 5月  20 2011 crossdomain.xml
drwxr-xr-x. 8 root root   99 5月  20 2011 data
drwxr-xr-x. 5 root root 4096 5月  20 2011 images
-rw-r--r--. 1 root root 3075 5月  20 2011 index.php
drwxr-xr-x. 3 root root  147 5月  20 2011 install
drwxr-xr-x. 2 root root   94 5月  20 2011 js
drwxr-xr-x. 2 root root  187 5月  20 2011 lib
drwxr-xr-x. 2 root root 4096 5月  20 2011 model
drwxr-xr-x. 3 root root   23 5月  20 2011 plugin
drwxr-xr-x. 2 root root   25 5月  20 2011 release
-rw-r--r--. 1 root root   28 5月  20 2011 robots.txt
drwxr-xr-x. 3 root root   38 5月  20 2011 view
[root@localhost ucadmin]# cp -rp  ./* /var/www/html/ucadmin/

開始安裝,後臺管理,在瀏覽輸入ip/ucadmin/install,
如:10.10.100.194/ucadmin/install
在這裏插入圖片描述
根據提示解決問題

[root@localhost ucadmin]# vim /etc/php.ini
short_open_tag = Off  改爲On,保存退出,重啓apache服務
[root@localhost ucadmin]# systemctl restart httpd

繼續安裝
在這裏插入圖片描述
一樣,根據報錯處理,解決問題
在這裏插入圖片描述
目錄沒有寫的權限,根目錄

[root@localhost ucadmin]# ll -d /var/www/html/ucadmin/
drwxr-xr-x. 13 root root 241 10月 21 02:43 /var/www/html/ucadmin/   #當前目錄的屬主是root,可以修改屬主爲apache
[root@localhost ucadmin]# chown -R apache.apache /var/www/html/ucadmin/

繼續安裝
在這裏插入圖片描述
下一步,填寫數據庫信息,設置管理密碼
在這裏插入圖片描述
下一步
在這裏插入圖片描述
安裝成功
在這裏插入圖片描述
在這裏插入圖片描述
能夠登陸說明後臺管理已經完成安裝。

接下來安裝前端管理
解壓壓縮包

[root@localhost html]# unzip UCenter_Home_2.0_SC_UTF8.zip

根據提示操作

在這裏插入圖片描述

[root@localhost html]# mv config.new.php config.php 
[root@localhost html]# systemctl restart httpd

下一步,文件權限問題,修改文件的屬主
在這裏插入圖片描述

[root@localhost html]# chown -R apache.apache ./config.php 
[root@localhost html]# systemctl restart httpd

下一步,又是權限問題,同樣的處理方法
在這裏插入圖片描述

[root@localhost html]# chown -R apache.apache ./data/ ./attachment/ ./uc_client/
[root@localhost html]# systemctl restart httpd

在這裏插入圖片描述
下一步
在這裏插入圖片描述
在這裏插入圖片描述
下一步,配置數據庫信息
在這裏插入圖片描述
配置用戶
在這裏插入圖片描述
配置好用戶,密碼,直接下一步
在這裏插入圖片描述
到這裏就已經完成安裝
在這裏插入圖片描述
在這裏插入圖片描述
到此lamp架構的個人博客就搭建完成

下面配置apache同一端口的多個虛擬主機
創建不同域名的虛擬主機

[root@localhost html]# vim /etc/httpd/conf/httpd.conf

在這裏插入圖片描述
查看這行是否被註釋,把註釋去掉

[root@localhost html]# vim /etc/httpd/conf.d/vhost.conf  #新增加一個配置文件

<VirtualHost *:80>
ServerAdmin [email protected]                   #郵件地址
DocumentRoot /var/www/html/ucadmin      #根目錄
ServerName  admin.test.com                  #域名
</VirtualHost>

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/
ServerName  www.test.com
</VirtualHost>

[root@localhost html]# systemctl restart httpd

然後修改電腦的host文件
C:\Windows\System32\drivers\etc\HOST
10.10.100.194 admin.test.cm
10.10.100.194 www.test.com

保存

用域名訪問,
備註,這樣只能用於內網同網段的訪問

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章