bash,sudo yum install epelrelease y,sudo yum install nginx y,sudo systemctl start nginx,sudo systemctl enable nginx,
`,,2. 安装PHPFPM:,
`bash,sudo yum install epelrelease y,sudo yum install php phpfpm y,sudo systemctl start phpfpm,sudo systemctl enable phpfpm,
`,,3. 安装MySQL:,
`bash,sudo yum install mariadbserver y,sudo systemctl start mariadb,sudo systemctl enable mariadb,sudo mysql_secure_installation,
`,,4. 配置Nginx和PHPFPM:,编辑Nginx配置文件(通常位于
/etc/nginx/conf.d/default.conf),将以下内容添加到
server块中:,
`bash,location ~ \.php$ {, fastcgi_pass 127.0.0.1:9000;, fastcgi_index index.php;, fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;, include fastcgi_params;,},
`,重启Nginx和PHPFPM服务:,
`bash,sudo systemctl restart nginx,sudo systemctl restart phpfpm,
``,,至此,您已成功安装了CentOS、Nginx、PHPFPM和MySQL。安装CentOS Nginx PHPFPM MySQL
以下是详细步骤和配置,以确保在CentOS上成功安装Nginx、PHPFPM和MySQL:
更新系统并安装基础软件包
1、更新系统:
```bash
sudo yum update y
```
2、安装EPEL源(此步骤确保能够获取到最新的软件包):
```bash
sudo yum install epelrelease y
```
3、安装必要的开发工具和库(这些工具和库是编译和安装软件所需的):
```bash
sudo yum groupinstall "Development Tools" y
sudo yum install wget y
```
安装Nginx
1、添加Nginx存储库:
```bash
sudo rpm Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginxreleasecentos70.el7.ngx.noarch.rpm
```
2、安装Nginx:
```bash
sudo yum install nginx y
```
3、启动并启用Nginx:
```bash
sudo systemctl start nginx
sudo systemctl enable nginx
```
安装PHP和PHPFPM
1、添加Webtatic存储库(用于获取最新的PHP版本):
```bash
sudo rpm Uvh https://mirror.webtatic.com/yum/el7/webtaticrelease.rpm
```
2、安装PHP及其扩展:
```bash
sudo yum install php74w php74wfpm php74wmysql php74wopcache y
```
3、启动并启用PHPFPM:
```bash
sudo systemctl start phpfpm
sudo systemctl enable phpfpm
```
配置Nginx解析PHP
1、打开Nginx配置文件:
```bash
sudo vi /etc/nginx/nginx.conf
```
2、在server
块中插入以下代码:
```nginx
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/phpfpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
```
3、保存并退出。
安装MySQL
1、添加MySQL存储库:
```bash
sudo rpm Uvh https://dev.mysql.com/get/mysql57communityreleaseel711.noarch.rpm
```
2、安装MySQL服务器:
```bash
sudo yum install mysqlcommunityserver y
```
3、启动并启用MySQL服务:
```bash
sudo systemctl start mysqld
sudo systemctl enable mysqld
```
测试配置
1、测试PHP配置:
创建一个PHP测试文件:
```bash
sudo vi /usr/share/nginx/html/info.php
```
添加以下内容:
```php
<?php phpinfo(); ?>
```
保存并退出,然后在浏览器中访问http://your_server_ip/info.php
,如果看到PHP信息页面,说明PHP配置成功。
2、测试MySQL配置:
登录MySQL:
```bash
mysql u root p
```
输入初始密码(可以在MySQL日志中找到)并更改为安全密码:
```sql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewSecurePassword!';
FLUSH PRIVILEGES;
```
FAQs
问题1:为什么Nginx无法解析PHP文件?
答案1:请确保Nginx配置文件中的fastcgi_pass
指令指向正确的PHPFPM套接字路径,并且该路径在PHPFPM配置文件中正确设置,确保PHPFPM服务已启动。
问题2:如何找到MySQL的初始密码?
答案2:MySQL的初始密码通常在MySQL日志文件中可以找到,可以使用以下命令查看日志文件的内容:
sudo grep 'temporary password' /var/log/mysqld.log
1分钟完美安装最新CentOS Nginx PHPFPM MySQL
前提条件
一台已经安装好CentOS操作系统的服务器
root权限
步骤
1. 更新系统
sudo yum update y
2. 安装Epel仓库
sudo yum install epelrelease y
3. 安装Nginx
sudo yum install nginx y
4. 启动Nginx并设置为开机自启
sudo systemctl start nginx sudo systemctl enable nginx
5. 安装PHP
sudo yum install php phpfpm phpmysql y
6. 配置PHPFPM
编辑/etc/php/fpm/pool.d/www.conf
文件,找到以下行并修改:
; pm = static pm = dynamic
找到并取消以下行的注释:
pm.max_children = 50 pm.start_servers = 10 pm.min_spare_servers = 5 pm.max_spare_servers = 35
7. 启动PHPFPM并设置为开机自启
sudo systemctl start phpfpm sudo systemctl enable phpfpm
8. 安装MySQL
sudo yum install mysqlserver y
9. 启动MySQL并设置为开机自启
sudo systemctl start mysqld sudo systemctl enable mysqld
10. 设置MySQL root密码
sudo mysql_secure_installation
按照提示设置root密码、删除匿名用户、禁止root远程登录、删除test数据库等。
11. 测试Nginx、PHP和MySQL
创建一个简单的PHP页面,例如/var/www/html/info.php
如下:
<?php phpinfo(); ?>
在浏览器中访问http://你的服务器IP/info.php
,应该能看到PHP和MySQL的配置信息。
完成
至此,最新版本的CentOS系统已经成功安装了Nginx、PHPFPM和MySQL。