Centos Server Setup - thiagobs-webdev/helptools GitHub Wiki
# Initial Server Setup
- Instructions:
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-centos-8
# Git
- Instructions:
https://www.digitalocean.com/community/tutorials/how-to-install-git-on-centos-8
# NGINX
-
Install packges:
dnf -y install epel-release curl wget tree zip unzip gcc gcc-c++ make pcre pcre-devel openssl openssl-devel zlib zlib-devel perl perl-devel perl-ExtUtils-Embed gd gd-devel libxslt libxslt-devel libxml2 libxml2-devel -
Development Tools:
dnf groupinstall -y 'Development Tools' -
Download packges:
wget https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.45/pcre2-10.45.tar.gz \ && tar xzvf pcre2-10.45.tar.gzwget https://zlib.net/zlib-1.3.1.tar.gz \ && tar xzvf zlib-1.3.1.tar.gzwget https://github.com/openssl/openssl/releases/download/openssl-3.4.1/openssl-3.4.1.tar.gz \ && tar xzvf openssl-3.4.1.tar.gz -
Download NGNIX:
wget http://nginx.org/download/nginx-1.26.3.tar.gz \ && tar xzvf nginx-1.26.3.tar.gz -
Remove files
tar.gz:rm -rf *.tar.gz -
Setup NGINX:
cd nginx-1.26.3 \ && cp man/nginx.8 /usr/share/man/man8/ \ && gzip /usr/share/man/man8/nginx.8 -
Install NGINX:
./configure \ --build=CentOS \ --builddir=nginx-1.26.3 \ --prefix=/usr/local/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --modules-path=/usr/lib64/nginx/modules \ --error-log-path=/var/log/nginx/error.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --user=nginx \ --group=nginx \ --http-log-path=/var/log/nginx/access.log \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --with-file-aio \ --with-threads \ --with-compat \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_xslt_module=dynamic \ --with-http_image_filter_module=dynamic \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_auth_request_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_degradation_module \ --with-http_slice_module \ --with-http_stub_status_module \ --with-http_perl_module=dynamic \ --with-mail=dynamic \ --with-mail_ssl_module \ --with-openssl=../openssl-3.4.1 \ --with-openssl-opt=no-nextprotoneg \ --with-perl=/usr/bin/perl \ --with-perl_modules_path=/usr/lib64/perl5 \ --with-pcre=../pcre2-10.45 \ --with-pcre-jit \ --with-poll_module \ --with-select_module \ --with-stream=dynamic \ --with-stream_ssl_module \ --with-stream_realip_module \ --with-stream_ssl_preread_module \ --with-zlib=../zlib-1.3.1 \ --with-debugmakemake install -
Setup NGINX environmnent:
ln -s /usr/lib64/nginx/modules /etc/nginx/modulesuseradd --system --home /var/cache/nginx --shell /sbin/nologin --comment "nginx user" --user-group nginxmkdir -p /var/cache/nginx/client_temp /var/cache/nginx/fastcgi_temp /var/cache/nginx/proxy_temp /var/cache/nginx/scgi_temp /var/cache/nginx/uwsgi_tempchmod 700 /var/cache/nginx/*chown nginx:root /var/cache/nginx/*vi /etc/systemd/system/nginx.service[Unit] Description=nginx - high performance web server Documentation=https://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.targetsystemctl enable nginx.servicesystemctl start nginx.servicesystemctl status nginx.servicemkdir /etc/nginx/{conf.d,snippets,sites-available,sites-enabled}chmod 640 /var/log/nginx/*chown nginx:adm /var/log/nginx/access.log /var/log/nginx/error.logvi /etc/logrotate.d/nginx/var/log/nginx/*.log { daily missingok rotate 52 compress delaycompress notifempty create 640 nginx adm sharedscripts postrotate if [ -f /var/run/nginx.pid ]; then kill -USR1 `cat /var/run/nginx.pid` fi endscript }rm -rf nginx-1.26.3/ openssl-3.4.1/ pcre2-10.45/ zlib-1.3.1/
# Install PHP
-
Enable Remi’s and EPEL repositories
dnf -y install http://rpms.remirepo.net/enterprise/remi-release-9.rpm \ && dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -
Update dnf cache
dnf makecache -y -
List configured repositories on the system.
dnf repolist -
Reset default PHP module on the system.
dnf module reset php -y -
Install PHP 8.4
dnf module -y install php:remi-8.4 -
Install modules:
dnf install -y php-{opcache,common,pear,cgi,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap,mcrypt,cli,mysql,ldap,fileinfo,pdo} -
Setup
php-fpm:vi /etc/php-fpm.d/www.confuser = nginx group = nginx ;listen = 127.0.0.1:9000 ;listen = /var/run/php-fpm.sock listen = /run/php-fpm.sock listen.owner = nginx listen.group = nginx listen.mode = 0660systemctl start php-fpmsystemctl enable php-fpmsystemctl status php-fpm -
Restart the Nginx and PHP-FPM:
systemctl restart nginx php-fpm -
Install composer
# Secure Nginx with Let's Encrypt (SSL)
-
Add EPEL repository:
dnf install epel-release -y -
Install all of the required packages:
dnf install certbot python3-certbot-nginx -
Updating the Firewall Rules:
3.1 check which services are already enabled:
sudo firewall-cmd --permanent --list-all3.2 Enable
http:sudo firewall-cmd --permanent --add-service=http3.3 Enable
https:sudo firewall-cmd --permanent --add-service=https3.4 Reload:
sudo firewall-cmd --reload -
Obtaining a Certificate:
sudo certbot --nginx -d your_domain -d www.your_domain -
Domain informations:
sudo certbot --nginx -
Setting Up Auto-Renewal:
6.1 Edit the crontab to create a new job that will run the renewal twice per day:
sudo crontab -e6.2 Add script:
0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew --quiet
# Create Let's Encrypt Wildcard Certificates
-
Install
hostcommand:dnf install bind-utils -
Test that wildcard DNS is working as intended:
host one.example.com