在CentOS Minimal上配置PHP环境,可以按照以下步骤进行:
首先,确保你的系统是最新的:
sudo yum update -y
EPEL(Extra Packages for Enterprise Linux)提供了许多额外的软件包,包括PHP:
sudo yum install -y epel-release
你可以根据需要安装PHP及其相关模块。以下是一些常用的模块:
sudo yum install -y php php-cli php-fpm php-mysqlnd php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
如果你打算使用PHP-FPM来处理PHP请求,需要进行一些配置。
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
编辑PHP-FPM配置文件(通常位于/etc/php-fpm.d/www.conf
),设置监听地址:
listen = /run/php-fpm/php-fpm.sock
; 或者
; listen = 127.0.0.1:9000
如果你使用Nginx或Apache作为Web服务器,需要配置它们以使用PHP-FPM或直接处理PHP文件。
编辑Nginx配置文件(通常位于/etc/nginx/nginx.conf
或/etc/nginx/conf.d/default.conf
),添加以下内容:
server {
listen 80;
server_name your_domain.com;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
如果你使用Apache,确保启用了mod_php
模块,并在虚拟主机配置中添加以下内容:
<VirtualHost *:80>
ServerName your_domain.com
DocumentRoot /var/www/html
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
</VirtualHost>
根据你使用的Web服务器,重启服务以应用配置更改:
sudo systemctl restart nginx
# 或者
sudo systemctl restart httpd
创建一个简单的PHP文件来测试你的PHP环境是否正常工作。在/var/www/html
目录下创建一个名为info.php
的文件,并添加以下内容:
<?php
phpinfo();
?>
然后在浏览器中访问http://your_domain.com/info.php
,你应该能看到PHP的详细信息页面。
通过以上步骤,你应该能够在CentOS Minimal上成功配置PHP环境。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:CentOS Minimal适合哪些场景