CentOS7配置網(wǎng)站環(huán)境
系統(tǒng)環(huán)境準備
執(zhí)行系統(tǒng)更新確保所有軟件包為最新版本:
yum update -y
安裝常用工具包:
yum install -y wget curl vim
Web服務(wù)器安裝
Apache安裝方案
yum install -y httpd
systemctl start httpd
systemctl enable httpd
Nginx安裝方案
yum install -y epel-release
yum install -y nginx
systemctl start nginx
systemctl enable nginx
數(shù)據(jù)庫服務(wù)部署
yum install -y mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
PHP環(huán)境配置
yum install -y php php-mysql php-fpm
systemctl start php-fpm
systemctl enable php-fpm
安裝常用擴展:
yum install -y php-gd php-json php-mbstring php-xml
防火墻配置
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
虛擬主機配置
Apache示例配置
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName example.com
ErrorLog /var/log/httpd/example-error.log
CustomLog /var/log/httpd/example-access.log combined
</VirtualHost>
Nginx示例配置
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html;
index index.php index.html;
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
環(huán)境驗證測試
創(chuàng)建PHP測試文件:
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
通過瀏覽器訪問 http://服務(wù)器IP/info.php 驗證PHP環(huán)境
安全加固建議
- 禁用不必要的PHP函數(shù)
- 配置數(shù)據(jù)庫遠程訪問限制
- 定期更新系統(tǒng)安全補丁
- 啟用SSL證書加密傳輸