Article

  • 7 years

    1 year

    YetiShare / Core

    13646

Yetishare v5 Install: VestaCP, CentOS, Nginx, PHP-FPM, MySQL - New Server Setup Guidance

New server install on CentOS 6.x 64bit. Do not use this guide for other Linux distros or CentOS version numbers (other than for guidance).

Important: This document is supplied without support. Our support covers script related issues so this guidance is provided as-is, without warranty. You should contact your server admin for support on server related issues. If you would prefer us to manage the installation and configuration on your servers, we can arrange this at a cost, see here.

Install VestaCP:

SSH (via Putty) to your server via 'root'.

cd /root
curl -O http://vestacp.com/pub/vst-install.sh
bash vst-install.sh --nginx yes --phpfpm yes --apache no --vsftpd no --proftpd no --exim yes --dovecot yes --spamassassin yes --clamav yes --named yes --iptables yes --fail2ban yes --mysql yes --postgresql no --remi yes --quota no

Enter your hostname (yourdomain.com) and the admin email address when prompted. Once installed, make note of your new VestaCP access details.

* If you see a dependency error on CentOS 7.x, try the guidance here to fix - https://forum.vestacp.com/viewtopic.php?f=10&t=20167&p=83185&hilit=Error%3A+Package%3A+php+pecl+mcrypt#p83185

Setup the database:

Now create a MySQL database and user for the script. Open your new VestaCP area using the details you where issues earlier. i.e. https://[your_ip_address]:8083

  • Navigate to 'DB'.
  • Click the green '+' symbol.
  • Choose a database name and user (such as 'yeti').
  • Generate a password and make note of your new database details.
  • Click 'Add' to submit the form.

Install the script:

Using WinSCP login as root to your server.

  • Go to /home/admin/web/yourdomain.com/public_html
  • Remove the default site files in your webroot:
rm /home/admin/web/yourdomain.com/public_html/index.html
rm /home/admin/web/yourdomain.com/public_html/robots.txt

  • Download YetiShare from our website and upload it using WinSCP to the above path. Once uploaded, extract the archive using your SSH session (Putty).
cd /home/admin/web/yourdomain.com/public_html
unzip File_Hosting_Script_*
rm File_Hosting_Script_*
chmod 755 _config.inc.php
chmod 755 plugins/
chmod 755 files/
chmod 755 logs/
chmod 755 cache/

  • Load the installation wizard in your browser - http://yourdomain.com/install/
  • If the initial checks for permissions fail, try CHMOD 777 on all the paths above instead.
  • Click 'next'.
  • Set the database details you configured above and click 'test'.
  • If it connects fine, enter the admin username and password you want to setup and click 'next/install'.
  • If everything installs fine you'll see the final confirmation page. You'll need to setup these crons on your server to enable the background tasks so keep this page in your browser for now.

Setup cron tasks:

Via SSH, enter:

crontab -e

  • Press the 'i' key.
  • Go back to your installation confirmation page and copy the 6 cron lines.
  • Back in your SSH session, right click or paste the lines.
  • Press the 'escape' key.
  • Type ':w' without the quote and press enter.
  • This will confirm the crontab has been saved.
  • Type ':q' without the quotes and press enter to exit.

Setup the Nginx rewrite rules:

Via SSH (Putty):

nano /home/admin/conf/web/nginx.yourdomain.com.conf
IMPORTANT - If you've enabled https, this file will be named as:

nano /home/admin/conf/web/snginx.yourdomain.com.conf

  • Delete the entire 'location / {' section. There should be about 17 lines.

Replace with:

    client_max_body_size 5G;

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
        if (!-e $request_filename) { rewrite ^/(.*) /index.php?_page_url=$1 last; }
        fastcgi_pass 127.0.0.1:9001;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED on;
        include fastcgi_params;
    }

     #location / {
        if (!-e $request_filename) {
            rewrite ^/(.*) /index.php?_page_url=$1 last;
        }
     #}

    location /files/ {
        internal;
    }

    # these locations would be hidden by .htaccess normally
    location /logs/ {
        deny all;
    }

  • Press 'ctrl + x', then 'Y', then enter to save. Restart Nginx:

service nginx restart

  • You'll see sub-pages on the site will now work fine, i.e. http://yoursite.com/register


Server Performance Improvements:

Via SSH (Putty) execute all the following commands. These will amend your configuration files to work best with the script. Note that these have been prepared for CentOS 6.x, do not use them on any other Linux distro or CentOS version. Instead use this guide.

PHP settings:

cp /etc/php.ini /etc/php-ORIG.ini
sed -i 's/memory_limit = .*/memory_limit = 512M/' /etc/php.ini
sed -i 's/upload_max_filesize = .*/upload_max_filesize = 5G/' /etc/php.ini
sed -i 's/post_max_size = .*/post_max_size = 5G/' /etc/php.ini
sed -i 's/max_execution_time = .*/max_execution_time = 180/' /etc/php.ini
sed -i 's/max_input_time = .*/max_input_time = 180/' /etc/php.ini
sed -i 's/output_buffering = .*/output_buffering = 4096/' /etc/php.ini
sed -i 's/;output_handler =.*/output_handler =/' /etc/php.ini
sed -i 's/zlib.output_compression = .*/zlib.output_compression = Off/' /etc/php.ini
sed -i 's/zlib.output_compression_level = .*/zlib.output_compression_level = -1/' /etc/php.ini
sed -i 's/;zlib.output_handler =.*/zlib.output_handler =/' /etc/php.ini

NGINX settings:

cp /etc/nginx/nginx.conf /etc/nginx/nginx-ORIG.conf
sed -i '/http {/a fastcgi_read_timeout 300;' /etc/nginx/nginx.conf
sed -i '/http {/a fastcgi_keep_conn on;' /etc/nginx/nginx.conf
sed -i '/http {/a fastcgi_buffering off;' /etc/nginx/nginx.conf
sed -i '/http {/a proxy_buffering off;' /etc/nginx/nginx.conf
sed --in-place '/gzip /d' /etc/nginx/nginx.conf
sed -i '/http {/a gzip off;' /etc/nginx/nginx.conf
sed --in-place '/worker_connections /d' /etc/nginx/nginx.conf
sed -i '/events {/a worker_connections 10000;' /etc/nginx/nginx.conf

cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www-ORIG.conf
sed --in-place '/pm = dynamic/d' /etc/php-fpm.d/www.conf
sed --in-place '/pm.max_children = /d' /etc/php-fpm.d/www.conf
sed -i -e '$arequest_terminate_timeout = 300' /etc/php-fpm.d/www.conf
sed -i -e '$apm = ondemand' /etc/php-fpm.d/www.conf
sed -i -e '$apm.max_children = 75' /etc/php-fpm.d/www.conf
sed -i -e '$apm.process_idle_timeout = 10s' /etc/php-fpm.d/www.conf

MYSQL settings:

cp /etc/my.cnf /etc/my-ORIG.cnf
sed -i 's/max_connections.*/max_connections=600/' /etc/my.cnf
sed --in-place '/query_cache_size=*/d' /etc/my.cnf
sed -i '/max_connections=600/a query_cache_limit = 1048576' /etc/my.cnf
sed -i '/max_connections=600/a query_cache_type = 1' /etc/my.cnf
sed -i '/max_connections=600/a query_cache_size = 268435456' /etc/my.cnf

Restart all services:

service mysqld restart or service mariadb restart
service nginx restart
service php-fpm restart

Your new server is done! Have a break :)


Setup File Servers (optional)

Set your "direct" file server using the "Install VestaCP" guide shown above.

Remove the default site files in your webroot:

rm /home/admin/web/fs1.yourdomain.com/public_html/index.html
rm /home/admin/web/fs1.yourdomain.com/public_html/robots.txt

Copy all files including the _config.inc.php from the main server to the file server. Example using rsync:

rsync -avh --progress --exclude 'files/*' --exclude 'logs/*' --exclude 'cache/*' --exclude '___OLD_SITE/*' /home/admin/web/yourdomain.com/public_html/ [email protected]:/home/admin/web/fs1.yourdomain.com/public_html

Set yourdomain.com, IP address (currently 1.1.1.2) with your server IP and the fs1.yourdomain.com with the web root path on your file server.

Once completed, on your file server edit the _config.inc.php file. Set the first 3 constants:

define("_CONFIG_SITE_HOST_URL", "fs1.yourdomain.com");
define("_CONFIG_SITE_FULL_URL", "fs1.yourdomain.com");

define("_CONFIG_DB_HOST", "1.1.1.1"); /* database host name */


  • Apply the Nginx rewrite rules to your file server. (as above)
  • Apply the performance configuration changes. (as above)
  • Add the file server to your admin area within the script.
  • Setup remote database access:

nano /etc/my.cnf

Ensure:

#bind-address = 127.0.0.1

Exit and save.

service mysqld restart

  • Setup or amend the existing MySQL user so it can access the database remotely. You can text this by connecting from the file server on the command line to the remote database.


Troubleshooting:

This guide is for CentOS 6.x however on CentOS 7 the homepage can sometime show a 404 or 500 error. Ensure the path to the root has the correct permissions:

chmod +x /home/admin/web/yourdomain.com/public_html/

SOURCE: http://stackoverflow.com/questions/25774999/nginx-stat-failed-13-permission-denied

CentOS phpMyAdmin Dependency Error

If you get about half way through the install and it exists with a phpMyAdmin error, try again without remi enabled. i.e.

bash vst-install.sh --nginx yes --phpfpm yes --apache no --vsftpd no --proftpd no --exim yes --dovecot yes --spamassassin yes --clamav yes --named yes --iptables yes --fail2ban yes --mysql yes --postgresql no --remi yes --quota no
You will need to upgrade PHP to v7.4 after:

yum install yum-utils
yum-config-manager --enable remi-php74
yum update -y
If you see other dependency issues with roundcube or phpMyAdmin, these may need removing via yum first.