1.Syntax error on line 31 of /etc/httpd/conf.d/php.conf: Invalid command 'php_value'
解決辦法
(1) Connect to the server via SSH
(2) Create a backup of the configuration file:
# cp /etc/httpd/conf.d/php.conf{,.orig}
(3) Edit /etc/httpd/conf.d/php.conf
file in any text editor and edit the syntax to include the <IfModule mod_php5.c> tags:
BEFORE:
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
AFTER:
<IfModule mod_php5.c>
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
</IfModule>
2.CentOS 7 安裝和升級 PHP 7.x
(1) 前置作業,安裝所須軟體:
yum install -y wget yum-utils
(2) 由於較新版的 PHP7 並末收錄在 CentOS 7,因此須先更新軟體來源:
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh epel-release-latest-7.noarch.rpm
rpm -Uvh remi-release-7.rpm
(3)安裝 PHP 與相關軟體
會直接安裝上述指定的 PHP 版本:
yum install -y php php-mysqlnd php-pdo php-xml php-pear php-devel php-mbstring re2c gcc-c++ gcc
(4) 移除下載的檔案:
rm epel-release-latest-7.noarch.rpm remi-release-7.rpm
(5)檢查 PHP 版本
檢查目前安裝的版本為 PHP 7.2.5:
[root@localhost ~]# php -v
PHP 7.2.5 (cli) (built: Apr 24 2018 19:12:06) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
3.升級PHP之後還會遇到函數修改的問題
PHP>=5.5 時所有以 mysql_開頭的函數都會作廢 deprecated,改用以 mysqli_開頭的函數取代
(1) 建立資料庫連線,設定編碼
$DBNAME
=
"db"
;
$DBUSER
=
"user"
;
$DBPASSWD
=
"password"
;
$DBHOST
=
"localhost"
;
$conn
= mysqli_connect(
$DBHOST
,
$DBUSER
,
$DBPASSWD
,
$DBNAME
);
//
設定連線編碼
mysqli_query( $conn,
"SET NAMES 'utf8'"
);
if
(
empty
(
$conn
)){
print
mysqli_error(
$conn
);
die
(
"無法連結資料庫"
);
exit
;
}
(2) 取得資料
$sql
=
"select * from `table` where id=123"
;
$result
= mysqli_query(
$conn
,
$sql
);
備註
$result = mysql_query($sql) 修改成
$result = mysqli_query($conn,$sql) or die($sql);
(3) 關聯群組
$rs=mysql_fetch_array($result); 修改成
$rs=mysqli_fetch_array($result);
(4) 關閉連線
mysqli_close($conn);
沒有留言:
張貼留言