2016年12月16日 星期五

CentOS中apache與php寫入權限與SELinux設定

Original : http://diary.tw/tim/entry/config-selinux-with-apache-and-php-to-write-permission

由於 CentOS 有 SELinux 的權限設限, 所以相對一些安全層級也都比較高, 最近有個需要用 php 寫入檔案(或是上傳檔案的應用), 原本的 php 在預設狀況下, 就會對 /tmp 有寫入的權限(預設是會在 /tmp/systemd-private-xxxxxx 下的私有 /tmp), 所以上傳時沒有問題, 但使用 move_uploaded_file() 至目的目錄時, 會有寫入的權限問題.

方式如下:

Method A
1. 要寫入需要有對應的權限, 建議方式是將要寫入的目錄給予 apache 執行用戶的擁有者, 如 CentOS 配 apache 時, user 為 apache

chown -R apache /var/www/mysite1/upload
2. 此時只需要給予對應目錄 755 的權限即可(通常預設也是這個).

chmod -R 755 /var/www/mysite1/upload

Method B (不建議)
1. 直接給予該目錄 global write 的權限, 777 即可, 不過會有安全性的考量

chmod -R 777 /var/www/mysite1/upload

完成之後, 若仍無法寫入, 則是因為 SELinux 的設限, 所以即使完成了上面的設定也無法寫入, 此時要再進一步設定 SELinux, 方式如下:

sudo chcon -t httpd_sys_rw_content_t /var/www/mysite1/upload -R


原因為預設的 webservice 能擁有的權限角色為 httpd_sys_content_t , 是無法寫入檔案的, 所以需要再進一步設定 SELinux 才行.

參考資料:
https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/

另外寫得很仔細的 SELinux 資料可以參考:
https://www.digitalocean.com/community/tutorials/an-introduction-to-selinux-on-centos-7-part-1-basic-concepts
https://www.digitalocean.com/community/tutorials/an-introduction-to-selinux-on-centos-7-part-2-files-and-processes
https://www.digitalocean.com/community/tutorials/an-introduction-to-selinux-on-centos-7-part-3-users

2015年5月18日 星期一

yum install

yum install php-xml --enablerepo=remi,remi-php55

2010年8月9日 星期一

分組小計

IF Exists(Select * from Tempdb..sysobjects where id=object_id('tempdb..#tmp0'))
drop table #tmp0

select aid=identity(int,1,1), empno,deptno into #tmp0 from tableA where eduuid='00101' order by deptno,empno

select *,(select count(1)+1 from #tmp0 a
where a.aid<#tmp0.aid and a.deptno=#tmp0.deptno) from #tmp0

2009年7月17日 星期五

斜率算角度

[轉貼]
1.三角函數是用「角度量」計算角的大小。VB6 是以「弧度量」計算角的大小。
2.「角度」與「弧度」的轉換方法為:角度乘以 pi/180 為弧度;弧度除以 pi/180 是角度。
3.VB 可用 Atn(1)*4 得到一個 Double 型別的 PI 值。

Private Sub Command1_Click()
'-----建立一個 30度、60度、90度的直角三角形-----
dy = Sqr(3) / 2 '--- 二分之根號3
dx = 0.5 '--- 0.5
pi = 4 * Atn(1) '--- 圓周率
斜率 = dy / dx '--- 用 dt_Y 除以 dt_X 求斜率
角度 = Atn(斜率) / (pi / 180)
斜率1 = Tan(角度 * (pi / 180))
Debug.Print "用 dt_Y 除以 dt_X 求斜率 = "; 斜率
Debug.Print "用Atn函數從斜率求角度 = "; 角度
Debug.Print "用Tan函數從角度求斜率 = "; 斜率1
End Sub

2009年6月16日 星期二

AddHandler

For Each c As Control In Me.Controls
If TypeName(c) = "Label" Then
If c.Name.ToString.Substring(0, 3) <> "Not" Then
AddHandler c.MouseDown, AddressOf All_label_MouseDown
AddHandler c.MouseUp, AddressOf All_label_MouseUp
AddHandler c.Click, AddressOf ALL_label_Click
End If
End If
Next
下面是事件處理的部分
Private Sub ALL_label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim O As Object = CType(sender, Label)
Select Case O.name.ToString
Case Is = "lab0", "lab1", "lab2", "lab3", "lab4", "lab5", "lab6", "lab7","lab8","lab9"
''0~9被按下的處理
Case Is = "labEqu"
''等於的按鈕
Case Is = "labAdd", "labSub", "labMul", "labDiv"
''四則運算處理
Case Is = "labClear"
''清除處理
End Select
End Sub

這樣子就可以一起處理,並且知道是哪一個Label發生Click事件了。
參考資料:http://www.ncis.com.tw/ncis_bbs/viewthread.php?tid=881
參考資料:http://msdn2.microsoft.com/zh-tw/library/kxt4418a(VS.80).aspx