Skip to main content

basic config php system

## ssh

ssh -l root 159.223.43.172

sudo dnf update -y

## php

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
rpm -qa | grep epel
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
rpm -qa | grep remi
dnf module list php
dnf module enable php:remi-7.4


dnf install php php-fpm php-opcache php-gd php-curl php-mysqlnd php-mbstring php-dom zip unzip php-zip php-json php-pdo php-pdo_mysql

## mysql

dnf install mysql-server
systemctl start mysqld | mysqld.service
systemctl status mysqld
systemctl enable mysqld
mysql -u root -p
mysql_secure_installation // jika mahu ke live, maka run ini untuk pastikan setting mysql adalah betul
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; // jika php adalah php >7.3 + mysql 8

QvsfjYR@9pJs@T8oMCy23fwYyQ-.snmviq_!*24p.JC7YERFUsfx_.mQaN.tJGnM

## nginx

dnf install nginx
mv /etc/nginx/default.d/php.conf /etc/nginx/default.d/php.conf.disabled
vi /etc/nginx/conf.d/ekjp.conf

~~~
server {
    listen      80;
       server_name 10.21.1.86;
       root        /var/www/html/hlp/public;
       index       index.php;

       charset utf-8;
       gzip on;
    gzip_types text/css application/javascript text/javascript application/x-javascript  image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php {
                # include fastcgi.conf;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/run/php-fpm/www.sock;
                
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 256 16k;
                fastcgi_busy_buffers_size 256k;
                fastcgi_temp_file_write_size 256k;
                include        fastcgi_params;
        }
        location ~ /\.ht {
                deny all;
        }
}

~~~

nginx -t
systemctl start nginx
systemctl status nginx
systemctl enable nginx

## git

dnf install git

## composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
composer

## firewall

dnf install firewalld
systemctl enable firewalld
systemctl start firewalld
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --reload
firewall-cmd --permanent --list-all

## setting

cd /var/www/html
git clone https://gitlab.com/tmukmkd/jtm-ekjp-laravel-training.git ekjp
cd ekjp
composer update

vi /etc/php-fpm.d/www.conf
tukar apache kepada nginx
-- tukar nobody kepada nginx

update .env

chown -R nginx:nginx /var/www/html/sago-beta/storage/
chown -R nginx:nginx /var/www/html/sago-beta/bootstrap/cache/
chmod -R 0777 /var/www/html/sago-beta/storage/
chmod -R 0775 /var/www/html/sago-beta/bootstrap/cache/

semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/sago-beta/storage(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/sago-beta/bootstrap/cache(/.*)?'
restorecon -Rv '/var/www/html/sago-beta'

mv /etc/nginx/default.d/php.conf /etc/nginx/default.d/php.conf.disabled

systemctl restart php-fpm
systemctl restart nginx

## selinux
sudo setsebool -P httpd_can_network_connect_db=1
setenforce 0

## letsencrypt

dnf install epel-release
dnf install certbot python3-certbot-nginx
certbot --nginx -d some.domain.name

## add user to group
usermod -a -G group_name user_name