2022年12月15日 星期四

在CentOS上安裝PHP8

1. 先安裝一下epel-release
yum -y install epel-release

2. 在安裝php會用到的函示庫,執行以下指令
yum install -y \
gcc-c++ autoconf libjpeg libjpeg-devel libpng \
libpng-devel freetype freetype-devel \
libpng libpng-devel libxml2 libxml2-devel \
zlib zlib-devel glibc glibc-devel glib2 \
glib2-devel bzip2 bzip2-devel ncurses curl \
openssl-devel gdbm-devel db4-devel libXpm-devel \
libX11-devel gd-devel gmp-devel readline-devel \
libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel \
libicu-devel libmcrypt-devel libmemcached-devel \
sqlite-devel oniguruma-devel

3. 下載穩定版的php8,解壓縮後,切到此目錄
cd /usr/src/
wget https://www.php.net/distributions/php-8.1.13.tar.gz
tar -xzvf php-8.1.13.tar.gz
cd php-8.1.13

4. 設定php編譯參數,如果有錯誤訊息,就要確認相依套件是否有安裝好
./configure --prefix=/usr/local/php \
--with-mysql-sock --with-mysqli --enable-fpm \
--enable-soap --with-openssl --with-mhash \
--with-zlib --enable-bcmath --with-iconv \
--with-bz2 --enable-calendar --with-curl \
--with-cdb --enable-dom --enable-exif \
--enable-fileinfo --enable-filter --enable-ftp \
--with-openssl-dir --with-zlib-dir --enable-gd-jis-conv \
--with-gettext --with-gmp --enable-mbstring \
--enable-mbregex --disable-debug --enable-pdo \
--with-pdo-mysql --with-readline --enable-session \
--enable-shmop --enable-simplexml --enable-sockets \
--enable-sysvmsg --enable-sysvsem --enable-sysvshm \
--with-xsl --disable-rpath --with-pear --enable-intl \
--enable-mysqlnd-compression-support

5. 進行編譯跟安裝
make
make install

6. 執行以下建立php的環境變數
ln -sf /usr/local/php/bin/php /usr/local/bin/php

7. 執行以下步驟,將預設的配置檔複製到正常路徑
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp /usr/src/php-8.1.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

8. 啟動php-fpm
/etc/init.d/php-fpm restart
/etc/init.d/php-fpm start

9. 修改php.ini,把cgi.fix_pathinfo=0 (為了安全性,避免惡意腳本插入攻擊)
vim /usr/local/php/lib/php.ini

10. 打開nginx的設定檔,加入PHP的設定,執行 vim /etc/nginx/conf.d/default.conf 在index部分加入 index.php 加入以下設定
location / {
    root /usr/share/nginx/html;
    index index.php index.html index.htm;
}
location  ~ \.php(/|$) {
    fastcgi_index index.php;
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    root /usr/share/nginx/html;
}

11. 在跟目錄就可以新增一個php檔案來測試,編輯vim /usr/share/nginx/html/info.php
<?php
    phpinfo();
?>

12. 重新啟動nginx
systemctl restart nginx

13. 打開網址http://xx.xx.xx.xx/info.php

2022年11月2日 星期三

安裝Nexus Repository

1. 安裝wget & java
yum install wget -y
yum install -y java-1.8.0-openjdk.x86_64

2. 下載nexus並解壓縮
wget -O nexus.tar.gz https://download.sonatype.com/nexus/3/latest-unix.tar.gz
tar -xvf nexus.tar.gz -C /opt
mv /opt/nexus-3* /opt/nexus

3. 建立使用者nexus
sudo adduser nexus
sudo chown -R nexus:nexus /opt/nexus
sudo chown -R nexus:nexus /opt/sonatype-work

4. 修改檔案
vi /opt/nexus/bin/nexus.rc
run_as_user="nexus"

vi /etc/security/limits.conf
nexus - nofile 65536

以下依情況調整
vi /opt/nexus/bin/nexus.vmoptions

5. 設定nexus服務
vi /etc/systemd/system/nexus.service
[Unit]
Description=nexus service
After=network.target

[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Group=nexus
Restart=on-abort

[Install]
WantedBy=multi-user.target

6. 啟動服務
sudo systemctl daemon-reload
sudo systemctl enable nexus
sudo systemctl start nexus

7. 確認服務,稍微要等一下服務啟動
sudo systemctl status nexus
ss -ntlp

8. 連線 http:/nexus_ip:8081/
密碼在 cat /opt/sonatype-work/nexus3/admin.password

2022年10月30日 星期日

安裝sonar-scanner

1. 下載sonar-scanner並且解壓縮
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.7.0.2747-linux.zip
unzip sonar-scanner-cli-4.7.0.2747-linux.zip -d /opt

2. 將sonar-scanner加入PATH路徑
vi /etc/profile
export SONAR_SCANNER_HOME=/opt/sonar-scanner-4.7.0.2747-linux
export PATH=$PATH:$SONAR_SCANNER_HOME/bin
source /etc/profile

3. 測試
sonar-scanner -v

4. 下載一個spring boot的範例程式碼,並且利用maven進行編譯
git clone https://gitlab.abow.online/abowspy/spring-boot-demo.git
cd spring-boot-demo/
mvn clean package

6. 進行程式碼掃描
sonar-scanner \
-Dsonar.host.url=http://192.168.1.124:9000 \
-Dsonar.projectKey=spring-boot-demo \
-Dsonar.projectName=spring-boot-demo \
-Dsonar.projectVersion=1.0 \
-Dsonar.login=admin \
-Dsonar.password=1q2w3e4r \
-Dsonar.ws.timeout=30 \
-Dsonar.projectDescription="my first project" \
-Dsonar.links.homepage=http://www.google.com \
-Dsonar.sources=src \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.java.binaries=target/classes \
-Dsonar.java.test.binaries=target/test-classes \
-Dsonar.java.surefire.report=target/surefire-reports

7. 最後成功的話,網頁就會看見如下: