2015年2月26日 星期四

6. 系統升級,安裝 LAMP(Linux + Apache + MariaDB + PHP)及 VSFTP

CentOS 7 快速設定 LAMP(Linux + Apache + MariaDB + PHP)

快速的在 CentOS 中建置 LAMP(Linux + Apache + MariaDB + PHP)服務。
RHEL7/CentOS7 已不包含 MySQL 資料庫,取而代之的是由原先 MySQL 開發團隊所維護的 MariaDB,其功能與函式使用均與 MySQL 相同,基本上若無使用特別的套件,大部份的應用程式應該都相容可以,無需修改程式。

1.安裝 HTTP、PHP、MariaDB 與相關工具

# yum install httpd mariadb-server mariadb php php-mbstring php-mysql php-gd
# yum install wget unzip

2.安裝 phpMyAdmin

$ sudo yum install phpmyadmin


3.設定 MariaDB Innodb
修改 /etc/my.cnf 檔案,在 [mysqld] 下新增

innodb_file_per_table = 1

4.啟動 httpd 與 mariadb,並設定開機時啟動
# systemctl start mariadb.service
# systemctl start httpd.service
# systemctl enable mariadb.service
# systemctl enable httpd.service

5.設定 MariaDB 資料庫的 root 密碼
# mysqladmin -u root password 'your-password'

6.開啟 Web Browser,輸入 http://your-ip/phpmyadmin 使用 phpMyAdmin

7.修正phpmyadmin 參數

After installation, Open /etc/httpd/conf.d/phpMyAdmin.conf file ( Apache config file for phpmyadmin ) and edit as follows.
Find these lines . ( Found 2 times )

# Apache 2.4
     <RequireAny>
       Require ip 127.0.0.1
       Require ip ::1
     </RequireAny>

修改成以下,加上Require all granted

 # Apache 2.4
    <RequireAny>
      # Require ip 127.0.0.1
      # Require ip ::1
      Require all granted
    </RequireAny>

Restart Apache service .
# systemctl restart httpd.service



8.安裝vsftp程式
# yum -y install vsftpd

啟動 vsftpd 服務: 
#  systemctl start vsftpd
   
設定開機時啟動 vsftpd
#  systemctl enable vsftpd

修改設定檔
# vi /etc/vsftpd/vsftpd.conf

限制使用者離開家目錄,只有chroot_list名單中的使用者,才可以離開家目錄(給管理者用)
    anonymous_enable=NO

    找到下列,將前面 # 的刪除
    chroot_list_enable=YES
    chroot_list_file=/etc/vsftpd/chroot_list
    chroot_local_user=YES
   
    讓使用者可用檔案總管方式上傳檔案
    connect_from_port_20=NO
    pasv_enable=YES
   
    
外部新增檔案chroot_list加入管理者名單
 #vi /etc/vsftpd/chroot_list
    ftp1
    ftp2
存檔後離開,以後只有這個檔案中允許的使用者才能登入ftp server。

重啟 ftp服務:
   # systemctl restart vsftpd



10.UserDir 用戶個人網頁

1.UserDir 模組:可以讓伺服器中的用戶,擁有自己的網頁。例如:http://iP/~user,查看模組有沒有載入,沒有的話要自行載入。

# grep userdir /etc/httpd/conf.modules.d/00-base.conf
LoadModule userdir_module modules/mod_userdir.so

2.開啟 Userdir,並設定用戶個人網頁的根目錄。
# vim /etc/httpd/conf.d/userdir.conf
<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    #UserDir disabled  <= 註解這一行
    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disabled" line above, and uncomment
    # the following line instead:
    #
    UserDir public_html  <= 取消註解這行,個人網頁根目錄為 public_html
</IfModule>

3.查看用戶個人網頁根目錄的存取設定是否符合要求,不符合的話就要修改。
# tail /etc/httpd/conf.d/userdir.conf

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory "/home/*/public_html">
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>

4.重新啟動 httpd。
# systemctl restart httpd.service


5.建立個人網頁資料夾
#mkdir  /home/user/public_html
設定資料夾權限。

#chmod  711  /home/user           ##本資料夾可執行

#chmod 755  /home/user/public_html   ##網頁資料夾 apache 可讀可執行