未加星标

How to Install Nextcloud with Nginx and PHP7-FPM on CentOS 7

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二05 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

Nextcloud is a free (Open Source) Dropbox-like software, a fork of the ownCloud project. Nextcloud is written inphp and javascript, it supports many database systems such as, mysql/MariaDB, PostgreSQL, Oracle Database and SQLite. In order to keep your files synchronized between Desktop and your own server, Nextcloud provides applications for windows, linux and Mac desktops and a mobile app for android and iOS. Nextcloud is not just a dropbox clone, it provides additional features like Calendar, Contacts, Schedule tasks, and streaming media with Ampache.

In this tutorial, I will show you how to install and configure the latest Nextcloud 10 release on a CentOS 7 server. I will run Nextcloud with a Nginx web server and PHP7-FPM and use MariaDB as the database system.

Prerequisite CentOS 7 64bit Root privileges on the server Step 1 - Install Nginx and PHP7-FPM on CentOS 7

Before we start with the Nginx and php7-fpm installation, we have to add the EPEL package repository. Install it with this yum command.

yum -y install epel-release

Now install Nginx from the EPEL repository.

yum -y install nginx

Then we have to add another repository for php7-fpm. There are several repositories available on the net that provide PHP 7 packages, I will use webtatichere.

Add the PHP7-FPM webtatic repository:

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Next, install PHP7-FPM and some additional packages for the Nextcloud installation.

yum -y install php70w-fpm php70w-cli php70w-gd php70w-mcrypt php70w-mysql php70w-pear php70w-xml php70w-mbstring php70w-pdo php70w-json php70w-pecl-apcu php70w-pecl-apcu-devel

Finally, check the PHP version from server terminal to verify that PHP installed correctly.

php -v


How to Install Nextcloud with Nginx and PHP7-FPM on CentOS 7
Step 2 - Configure PHP7-FPM

In this step, we will configure php-fpm to run with Nginx. Php7-fpm will run under user nginx and listen on port 9000.

Edit the default php7-fpm configuration file with vim.

vim /etc/php-fpm.d/www.conf

In line 8 and 10, change user and group to ' nginx '.

user = nginx

group = nginx

In line 22, make sure php-fpm is running under server port.

listen = 127.0.0.1:9000

Uncomment line 366-370 to activate the php-fpm system environment variables.

env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp

Save the file and exit the vim editor.

Next, create a new directory for the session path in the '/var/lib/' directory, and change the owner to the 'nginx' user.

mkdir -p /var/lib/php/session

chown nginx:nginx -R /var/lib/php/session/

Now start php-fpm and Nginx, then enable the services to start at boot time.

sudo systemctl start php-fpm

sudo systemctl start nginx

sudo systemctl enable php-fpm

sudo systemctl enable nginx


How to Install Nextcloud with Nginx and PHP7-FPM on CentOS 7

PHP7-FPM configuration is done.

Step 3 - Install and Configure MariaDB

Iwill use MariaDB for the Nextcloud database. Install themariadb-server package from the CentOS repository with yum.

yum -y install mariadb mariadb-server

Start the MariaDB service and add it to run at boot time.

systemctl start mariadb

systemctl enable mariadb

Now configure the MariaDB root password.

mysql_secure_installation

Type in your root password when requested.

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

The MariaDB root password has been set, now we can login to the mysql shell to create a new database and a new user for Nextcloud. I will create a new database named ' nextcloud_db ' and a user ' nextclouduser ' with password ' nextclouduser@ '. Choose a secure password for your installation!

mysql -u root -p

Type Password

Type in the mysql query below to create a new database and a new user.

create database nextcloud_db;

create user[emailprotected]

identified by 'nextclouduser@';

grant all privileges on nextcloud_db.* to[emailprotected] identified by 'nextclouduser@';

flush privileges;


How to Install Nextcloud with Nginx and PHP7-FPM on CentOS 7

The nextcloud_db database with user 'nextclouduser' has been created.

Step 4 - Generate a Self-signed SSL Certificate for Nextcloud

In this tutorial, I will run nextcloud with a https connection for the client. You can use free SSL such as let's encrypt or create self signed SSL certificate.I will create my own self-signed SSL certificate file with the OpenSSL command.

Create a new directory for the SSL file.

mkdir -p /etc/nginx/cert/

And generate a new SSL certificate file with the theopenssl command below.

openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key

Finally, change the permission of all certificate files to 600 with chmod.

chmod 700 /etc/nginx/cert

chmod 600 /etc/nginx/cert/*


How to Install Nextcloud with Nginx and PHP7-FPM on CentOS 7
Step 5 - Download and Install Nextcloud

We will download Nextcloud with wget directly to the server, so we have to install wget first. Additionally, we need the unzip program. Install both applications with yum.

yum -y install wget unzip

Go to the /tmp directory and download latest stable Nextcloud 10 version from the Nextcloud web site with wget.

cd /tmp

wget https://download.nextcloud.com/server/releases/nextcloud-10.0.2.zip

Extract the nextcloud zip file and move it's content to the '/usr/share/nginx/html/' directory.

unzip nextcloud-10.0.2.zip

mv nextcloud/ /usr/share/nginx/html/

Next, go to the Nginx web root directory and create a new 'data' directory for Nextcloud.

cd /usr/share/nginx/html/

mkdir -p nextcloud/data/

Change the owner of the 'nextcloud' directory to the 'nginx' user and group.

chown nginx:nginx -R nextcloud/

Step 6 - Configure Nextcloud Virtual Host in Nginx

In step 5 we've downloaded the Nextcloud source code and configured it to run under the Nginx web server. But we still need to configure a virtual host for Nextcloud. Create a new virtual host configuration file 'nextcloud.conf' in the Nginx 'conf.d' directory.

cd /etc/nginx/conf.d/

vim nextcloud.conf

Paste the Nextcloud virtual host configuration below.

upstream php-handler { server 127.0.0.1:9000; #server unix:/var/run/php5-fpm.sock; } server { listen 80; server_name cloud.nextcloud.co; # enforce https return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name cloud.nextcloud.co; ssl_certificate /etc/nginx/cert/nextcloud.crt; ssl_certificate_key /etc/nginx/cert/nextcloud.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=bl

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: PHPNginxSQLMySQLOpenSSLPostgreSQLJavaScriptLinuxiOSJava
分页:12
转载请注明
本文标题:How to Install Nextcloud with Nginx and PHP7-FPM on CentOS 7
本站链接:http://www.codesec.net/view/524244.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(73)