[CentOS 7] LAMP主機安裝

指令教學

參考網址:https://goo.gl/Bz1F4h

# rpm -qa | grep php //查詢安裝軟體,EX:查 php 安裝軟體

更新檔案

# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm //映像檔
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm  //映像檔
# yum update -y

安裝 VIM (編輯器)

# yum install vim-enhanced -y
# mv /bin/vi /bin/vi.bak
# ln -s /usr/bin/vim /bin/vi
# echo "set nu" >> /etc/vimrc //顯示行數

修改 Linux 預設的 Language 以免 Putty 顯示不出中文

# vi /etc/sysconfig/selinux
SELINUX=disabled //關閉

開啟 NTP 自動校時服務

# yum install ntp -y
# systemctl start ntpd
# systemctl enable ntpd
# ntpdate tick.stdtime.gov.tw
# systemctl restart ntpd

安裝Server使用工具

# yum install wget rsyslog telnet -y

安裝 PHP

# yum install php71w-pdo php71w-mbstring php71w-xml php71w-common php71w-mysqlnd php71w-gd php71w-devel php71w-soap php71w php71w-cli php71w-xmlrpc php71w-mcrypt -y

設定

修改 php.ini 的配置

#vi /etc/php.ini

short_open_tag = On
max_execution_time = 300
max_input_time = 600
memory_limit = 128M
display_errors = Off
log_errors = On
ignore_repeated_errors = On
ignore_repeated_source = On
post_max_size = 20M
upload_max_filesize = 16M
date.timezone = Asia/Taipei

httpd.conf 設定

# vi /etc/httpd/conf/httpd.conf

ServerAdmin root@localhost	# 調整成管理者 Email
<Directory />
	AllowOverride ALL
	Require all denied
</Directory>

<Directory "/var/www">
	AllowOverride ALL
	# Allow open access:
	Require all granted
</Directory>

# Further relax access to the default document root:
<Directory "/var/www/html">
	#
	# Possible values for the Options directive are "None",     "All",
	# or any combination of:
	#   Indexes Includes FollowSymLinks SymLinksifOwnerMatc    h ExecCGI MultiViews
	#
	# Note that "MultiViews" must be named *explicitly* ---     "Options All"
	# doesn't give it to you.
	#
	# The Options directive is both complicated and importa    nt.  Please see
	# http://httpd.apache.org/docs/2.4/mod/core.html#option    s
	# for more information.
	#
	Options FollowSymLinks
	
	#
	# AllowOverride controls what directives may be placed     in .htaccess files.
	# It can be "All", "None", or any combination of the ke    ywords:
	#   Options FileInfo AuthConfig Limit
	#
	AllowOverride ALL
	
	#
	# Controls who can get stuff from this server.
	#
	Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.php index.html index.htm
</IfModule>

<Directory "/var/www/cgi-bin">
	AllowOverride ALL
	Options FollowSymLinks
	Require all granted
</Directory>

<IfModule prefork.c>
StartServers			8		# 啟動 httpd 時,喚醒幾個 PID 來處理服務的意思
MinSpareServers			5		# 最小的預備使用的 PID 數量
MaxSpareServers			20		# 最大的預備使用的 PID 數量
ServerLimit				10000	# 伺服器的限制
MaxClients				256		# 最多可以容許多少個用戶端同時連線到 httpd 的意思
MaxRequestsPerChild  500
</IfModule>


<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

# systemctl restart httpd	# 設定完需重啟Apache

設定 virtual.conf 檔案

# vi /etc/httpd/conf.d/virtual.conf	# 第一次會沒有這檔案,直接新增

NameVirtualHost *:80				# virtual.conf 檔案最上面放置一次即可

<Directory "/var/www/test">
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
<VirtualHost *:80>
    ServerName    test.test.com
    DocumentRoot  /var/www/test
    CustomLog     /var/log/httpd/test.access_log combined
    ErrorLog      /var/log/httpd/test_error_log
</VirtualHost>

# systemctl restart httpd				# 設定完需重啟Apache

服務設定
啟用服務並開機自動啟用

# systemctl start httpd
# systemctl enable httpd

防火牆
設定 firewall 允許 http(80 Port)、https(443 Port)封包通行

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload

檢設 firewall 的設定

# firewall-cmd --zone=public --list-all
回饋
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh http https
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

安裝 MariaDB

# yum install mariadb-server mariadb -y

初始化設定

須先啟用服務,才可進行初始化

# systemctl start mariadb

進行初始化設定

# mysql_secure_installation

/usr/bin/mysql_secure_installation: line 379: find_mysql_client:命令找不到
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): 

# 輸入目前 MariaDB 的 root 密碼(第一次設定應該是空的,所以直接「ENTER」即可)

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]

# 直接「ENTER」

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] 

# 是否要移除 anonymous user 的資料,直接「ENTER」

... 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 從 localhost 登入,無法從其他的網路登入,直接「ENTER」

... 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 的資料庫,直接「ENTER」

- 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] 

# 是否要重新載入權限的 table 資訊,直接「ENTER」

... 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!

服務設定
啟用服務並開機自動啟用

# systemctl start mariadb
# systemctl enable mariadb

安裝 MC (GUI介面)

參考網址:https://goo.gl/hiqCUq

# yum install mc -y

安裝 ZIP (壓縮軟體)

# yum install zip unzip -y

安裝 nmap (查 Port 軟體)

# yum install nmap -y
# nmap -sT -O localhost

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *