安装nginx和php
1. 添加epel源
yum -y install epel-release
2. 安装nginx和php
yum install epel-release -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum install yum-utils -y
yum-config-manager --enable remi-php74
yum -y install php php-xml php-gd php-mbstring php-process php-ldap php-xml php-zip php-mysql php-intl php-fpm nginx
配置php
使用 vim 编辑默认的 php7-fpm 配置文件。
vim /etc/php-fpm.d/www.conf
在第 8 行和第 10行,user 和 group 赋值为 nginx。
user = nginx
group = nginx
在第 22 行,确保 php-fpm 运行在指定端口。
listen = 127.0.0.1:9000
取消第 366-370 行的注释,启用 php-fpm 的系统环境变量。
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
保存文件并退出 vim 编辑器。
下一步,就是在 /var/lib/ 目录下创建一个新的文件夹 session,并将其拥有者变更为 nginx 用户。
mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/
然后启动 php-fpm,并且设置为随开机启动的服务。
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
PHP7-FPM 配置完成
安装mysql或者MariaDB
使用 MariaDB 作为 Nextcloud 的数据库,直接使用 yum 命令进行安装即可
yum -y install mariadb mariadb-server
启动 MariaDB,并将其添加开机启动
systemctl start mariadb
systemctl enable mariadb
开始配置 MariaDB 的 root 用户密码。
mysql_secure_installation
在出现的选项中键入 Y ,然后根据自己的习惯设置密码
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
密码设置好后,使用密码登陆。我们开始创建给netxcloud使用的数据库和用户
mysql -u root -p
输入刚刚设置的 root 密码,然后登陆到数据库中
输入以下 mysql 语句来创建新的数据库和用户。以下命令会创建一个名为nextcloud_db额数据库,数据库访问用户和密码分别为nextcloud和test1234。以上三个参数可自行修改
MariaDB [(none)]> CREATE DATABASE nextcloud_db;
MariaDB [(none)]> GRANT ALL ON nextcloud_db.* TO 'nextcloud'@'localhost' IDENTIFIED BY 'next@gosun!@#';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit
添加ssl证书(可选)
如果使用域名来访问我们的网站,为了我们网站的安全性我们可以为域名配置一个ssl证书。证书需要自行去申请,可以使用let's encrypt 等免费 SSL 证书
为 SSL 文件创建新目录
mkdir -p /etc/nginx/cert/
将自己的域名ssl证书上传到改目录下
修改一下证书和所在文件夹的权限大小
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/*
下载netxcloud
去到netxcloud的官网下载最新版的nextcloud,并解压缩
wget https://download.nextcloud.com/server/releases/nextcloud-23.0.0.zip
unzip nextcloud-23.0.0.zip
将文件放到nginx的网站根目录下,然后在nextcloud目录下创建一个data目录用来存放上传的各类文件
mv nextcloud /usr/share/nginx/html/
cd /usr/share/nginx/html/
mkdir -p nextcloud/data/
修改nextclou目录的归属用户和组,修改为nginx
chown nginx:nginx -R nextcloud/
配置nginx,添加一个虚拟主机
在 Nginx 的 conf.d 目录下创建一个新的虚拟主机配置文件 nextcloud.conf
cd /etc/nginx/conf.d/
vim nextcloud.conf
将以下内容粘贴到虚拟主机配置文件中:
upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name cloud.nsvortex.cn;#此处绑定域名修改为自己的
# enforce https
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name cloud.nextcloud.co;
ssl_certificate /etc/nginx/cert/1_nsvortex.cn_bundle.crt;#改成自己的证书名字
ssl_certificate_key /etc/nginx/cert/2_nsvortex.cn.key;#改成自己的证书名字
# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this
# topic first.
add_header Strict-Transport-Security "max-age=15768000;
includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Path to the root of your installation
root /usr/share/nginx/html/nextcloud/;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
# last;
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# Disable gzip to avoid the removal of the ETag header
gzip off;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location / {
rewrite ^ /index.php$uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
#Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
# Before enabling Strict-Transport-Security headers please read into
# this topic first.
add_header Strict-Transport-Security "max-age=15768000;
includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Optional: Don't log access to assets
access_log off;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
# Optional: Don't log access to other assets
access_log off;
}
}
测试Nginx 配置文件是否有错误,没有的话就可以重启服务了。
nginx -t
systemctl restart nginx
2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
新车首发,新的一年,只带想赚米的人coinsrore.com
新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
新车上路,只带前10个人coinsrore.com
新盘首开 新盘首开 征召客户!!!coinsrore.com
新项目准备上线,寻找志同道合 的合作伙伴coinsrore.com
新车即将上线 真正的项目,期待你的参与coinsrore.com
新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com