LAMP架構:
Linux+Apache+Mysql+PHP
官方網站:
http://www.mysql.com/
http://dev.mysql.com/downloads/mysql/
CentOS 7.0中,已經使用MariaDB替代了MySQL資料庫,原因你懂的,MYSQL被Oracle收購以後,前景堪憂,是以MYSQL兄弟MariaDB就出來了,繼續開源事業。
以rpm包的方式安裝LAMP。
一、安裝需要的軟體包
[root@docker-04 ~]# yum -y install httpd mariadb-server mariadb php php-mysql
centos6.5執行以下
[root@docker-04 ~]# yum install httpd mysql-server mysql php php-mysql -y
httpd # web伺服器
mariadb-server #mysql資料庫
mariadb # mysql伺服器linux下用戶端
php #php相關檔案
php-mysql #??? #php程式連接配接mysql使用的子產品
檢視某個指令由哪個包安裝
[root@docker-04 ~]# rpm -qf `which mysql`
mariadb-5.5.60-1.el7_5.x86_64
啟動服務LAMP相關服務:
[root@docker-04 ~]# systemctl start httpd
[root@docker-04 ~]# systemctl enable httpd
[root@docker-04 ~]# systemctl start mariadb
[root@docker-04 ~]# systemctl enable mariadb
[root@docker-04 ~]# systemctl status mariadb
測試資料庫連接配接:
連接配接mysql資料庫,連接配接本機可以去掉-h
#mysql
或:
# mysql -h IP -u USER -pPASS
Mysql的超級管理者是root擁有最mysql資料庫的最高權限。
例:
# mysql -u root –p123456 –h 10.10.10.68
mysql> exit; #退出mysql
MySQL安全配置向導
安裝完mysql-server 會提示可以運作mysql_secure_installation。運作mysql_secure_installation會執行幾個設定:
a)為root使用者設定密碼
b)删除匿名賬号
c)取消root使用者遠端登入
d)删除test庫和對test庫的通路權限
e)重新整理授權表使修改生效
通過這幾項的設定能夠提高mysql庫的安全。建議生産環境中mysql安裝這完成後一定要運作一次mysql_secure_installation,詳細步驟請參看下面的指令:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, 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):<–初次運作直接回車
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <– 是否設定root使用者密碼, 剛才我已設定密碼,我們輸n
... skipping
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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] <– 是否删除匿名使用者,生産環境建議删除,是以直接回車或Y
… 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遠端登入,根據自己的需求選擇Y/n并回車,建議禁止
By default, MySQL 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資料庫,直接回車或Y
- Dropping test database…
- Removing privileges on test database…
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <– 是否重新加載權限表,直接回車
Cleaning up…
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
如果不做安全配置root密碼
[root@docker-03 ~]# mysqladmin -u root password “123456"
測試:登入mysql
[root@docker-03 ~]# mysql -u root -p
[root@docker-03 ~]# mysql -u root -p123456
測試:
[root@docker-04 ~]# mysql -u root -p123456
mysql> show databases; #沒有test資料庫#執行時,所有指令以;号結尾
+--------------------+
| Database |
| information_schema |
| mysql |
| ucenter |
3 rows in set (0.00 sec)
mysql> exit #退出指令可以加分号,也可以不加分号。
測試網站是否支援PHP
# cd /var/www/html/
[root@docker-04 html]# vim index.php
<?php
phpinfo();
?>
[root@docker-04 html]# systemctl restart httpd 重新開機web
http://172.17.120.53/index.php
搭建LAMP環境部署Ucenter和Ucenter-home網站,搭建一個人人網的社交網站
www.renren.com

UCenter 使用者中心,實作使用者的統一登入登出,積分的兌換,TAG的互通等,在安裝UCenter Home、Discuz!、SupeSite、X-Space 等應用前必須先安裝UCenter。本教程講解的即是如何全新安裝UCenter 3.2.0。
http://www.discuz.net
Discuz! 論壇,百萬站長的選擇,定會給您帶來非凡的論壇體驗。Discuz! 7.0.0 的推出使Discuz! 的使用者體驗又上升到了一個新的高度。本教程講解的即是如何全新安裝Discuz! 7.0.0 FULL(內建了UCenter 安裝的版本)。
UCenter Home 個人家園,給社群中的會員一個可以安家的地方,在這裡會員可以交朋友,寫記錄,發日志,貼照片,玩遊戲...使會員可以牢牢的黏在你的社群裡。本教程講解的即是如何全新安裝UCenter Home 3.2。
SupeSite 社群門戶,實作CMS 的功能,擁有強大的模型功能,對Discuz! 和UCenter Home 的完美聚合,是您将社群中所有資訊進行整合展示的最佳平台。本教程講解的即是如何全新安裝SupeSite
到伺服器上/opt目錄下:
[root@docker-04 opt]# wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip
[root@docker-04 opt]# unzip -d ./ucenter Discuz_X3.2_SC_UTF8.zip # 解壓縮到./ucenter
[root@docker-04 opt]# cd ./ucenter
[root@docker-04 ucenter]# ls
readme upload utility
[root@docker-04 ucenter]# mkdir /var/www/html/ucadmin #建立目錄
[root@docker-04 ucenter]# mv upload/* /var/www/html/ucadmin
[root@docker-04 ucenter]# cd /var/www/html/ucadmin
[root@docker-04 ucadmin]# ls
admin.php connect.php forum.php member.php search.php uc_server
api cp.php group.php misc.php source userapp.php
api.php crossdomain.xml home.php plugin.php static
archiver data index.php portal.php template
config favicon.ico install robots.txt uc_client
# robots.txt 網站根目錄下,robots.txt 檔案作用。
Robots協定(也稱為爬蟲協定、機器人協定等)全稱是“網絡爬蟲排除标準”(Robots Exclusion Protocol),網站通過Robots協定告訴搜尋引擎哪些頁面可以抓取,哪些頁面不能抓取。
robots.txt檔案是一個文本檔案,使用任何一個常見的文本編輯器,比如Windows系統自帶的Notepad,就可以建立和編輯它[1] 。robots.txt是一個協定,而不是一個指令。robots.txt是搜尋引擎中通路網站的時候要檢視的第一個檔案。robots.txt檔案告訴蜘蛛程式在伺服器上什麼檔案是可以被檢視的。
但robots.txt不是指令,也不是防火牆,如同守門人無法阻止竊賊等惡意闖入者。
修改檔案權限:
[root@docker-04 ucadmin]# ls -ld data
drwxr-xr-x. 13 root root 216 5月 31 2016 data
[root@docker-04 ucadmin]# ps -aux | grep httpd
root 18277 0.0 0.1 410156 13540 ? Ss 14:46 0:00 /usr/sbin/http-DFOREGROUND
apache 18279 0.0 0.0 410288 9156 ? S 14:46 0:00 /usr/sbin/http-DFOREGROUND
apache 18280 0.0 0.0 410288 7860 ? S 14:46 0:00 /usr/sbin/http-DFOREGROUND
[root@docker-04 ucadmin]# id apache
uid=48(apache) gid=48(apache) 組=48(apache)
[root@docker-04 ucadmin]# chown apache:apache data/ -R
[root@docker-04 ucadmin]# chmod -R 777 data #
為安全正确做法應該是chown –R apache:apache data。後面安裝好後測試。
安裝網站模版:
安裝UCenter:
打開:http://172.17.120.53/ucadmin/install/
要安這個打開:
[root@docker-04 ucadmin]# vim /etc/php.ini #php運用程式的配置檔案
改:211 short_open_tag = Off
為:211 short_open_tag = On
開啟PHP短标簽功能。
決定是否允許使用,代碼開始标志的縮寫形式(<? 。。。?>)
PHP 代碼開始标志的完整形式為:<?php。。。?>
#重新加載配置檔案
[root@docker-04 ucadmin]# systemctl restart httpd.service
測試:http://172.17.120.53/ucadmin/install/
需要這個data目錄可寫:
注:這個注冊碼很不清楚,多按F5重新整理幾次就可以了
要記錄創始人使用者名:admin 密碼:123456