PHP

Centos

  1. 從官網取得 Remi和 EPEL rpm的連結
1
2
3
4
5
6
7
8
9
centos 7:
$sudo rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-7.rpm;

$sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm;

centos 8:
$sudo rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-8.rpm;

$sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm;
  1. 安装 yum-utils工具,並設定 php套件為 7.2 版本(可省略)
1
$sudo yum install yum-utils

設定 php套件為 7.2 版本

1
$sudo  yum-config-manager --enable remi-php72
  1. 安裝 php和相關套件

如果跳過第2步驟,則指令如下:

1
$sudo yum --enablerepo=remi-php72 install ...(下列套件)
1
2
$sudo yum install php php-ctype php-json php-openssl php-nette-tokenizer php-pecl-zip php-pdo php-mbstring php-xml php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
zip unzip php-bcmath(laravel5.7↑)

Ubuntu

Ubuntu 18.04 預設安裝 php7.2,若想安裝最新版本,需新增 PPA

Ubuntu之前有安裝php,但因更新Ubuntu版本後,PPA需再新增一次

  1. Add PPA

We’ll add ppa:ondrej/php PPA repository which has the latest build packages of PHP.

1
$sudo add-apt-repository ppa:ondrej/
  1. 安裝 php 7.4和相關套件
1
$sudo apt install php7.4

確認安裝版本

1
2
3
4
5
6
$php -v

PHP 7.4.6 (cli) (built: May 14 2020 10:02:44) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies

相關套件

1
$sudo apt install php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip}

伺服器(Apache)

Centos

  1. 安裝
1
$sudo yum install httpd
  1. 設定狀態
1
2
3
4
5
$sudo systemctl start httpd (啟動apache)
$sudo systemctl enable httpd (開機時啟動)
$sudo systemctl status httpd(查看狀態)
$sudo systemctl restart httpd(重新啟動)
$sudo systemctl stop httpd(停止apache)

Ubuntu

  1. 安裝
1
$sudo yum install apache2
  1. 設定狀態
1
2
3
4
5
$sudo systemctl start apache2 (啟動apache)
$sudo systemctl enable apache2 (開機時啟動)
$sudo systemctl status apache2(查看狀態)
$sudo systemctl restart apache2(重新啟動)
$sudo systemctl stop apache2(停止apache)

伺服器(Nginx)

Centos

  1. 安裝
1
$sudo yum install nginx
  1. 啟動
1
2
3
4
$sudo systemctl start nginx (啟動nginx)
$sudo systemctl enable nginx (開機時啟動)
$sudo systemctl status nginx(查看狀態)
$sudo systemctl restart nginx(重新啟動)
  1. 設定 在設定檔中,新增設定
1
$sudo vim /etc/nginx/nginx.conf
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
server {
    .
    index index.php index.html
    .
    
    location ~ \.php$ {
            root           /usr/share/nginx/html;
            fastcgi_pass   unix:/var/run/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
    }
}
  1. 預設目錄 :::info /usr/share/nginx/html/ :::

Ubuntu

  1. Install
1
$sudo apt install nginx
  1. Setting
1
$sudo vim /etc/nginx/sites-available/default
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
server {
	
	index index.php index.html index.htm index.nginx-debian.html;

	server_name _;

	#Add Down
    
	location ~ \.php$ {
        	include snippets/fastcgi-php.conf;
        	fastcgi_pass unix:/run/php/php7.4-fpm.sock;
	}
 
    location ~ /\.ht {
            deny all;
    }
	
}

MySQL

Centos

Ubuntu

PhpMyAdmin

Centos

Ubuntu

防火牆(Firewall)