在CentOS下安装PHP7+Nginx+MySQL,可以按照以下步骤进行操作:
更新系统软件包:
sudo yum update
安装Nginx:
sudo yum install epel-release
sudo yum install nginx
启动Nginx服务:
sudo systemctl start nginx
设置Nginx开机自启动:
sudo systemctl enable nginx
安装MySQL:
sudo yum install mysql-server
启动MySQL服务:
sudo systemctl start mysqld
设置MySQL开机自启动:
sudo systemctl enable mysqld
运行MySQL安全脚本,设置root密码等:
sudo mysql_secure_installation
安装PHP7及相关扩展:
sudo yum install epel-release
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum install yum-utils
sudo yum-config-manager --enable remi-php72
sudo yum install php php-fpm php-mysql
配置PHP-FPM:
sudo vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
启动PHP-FPM服务:
sudo systemctl start php-fpm
设置PHP-FPM开机自启动:
sudo systemctl enable php-fpm
配置Nginx:
编辑Nginx默认站点配置文件:
sudo vi /etc/nginx/conf.d/default.conf
添加以下内容:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
保存并退出。
重启Nginx服务:
sudo systemctl restart nginx
现在,你已经成功在CentOS下安装了PHP7+Nginx+MySQL。你可以通过访问服务器的IP地址或域名来测试是否正常工作。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站