Ubuntu 14.04 LTS 升級套件須知

[前言]

本文章適用於Ubuntu 14.04的版本。目前收錄:PHP, MySQL 等升級要領。

[前置條件]

已經使用:tasksel 套件安裝好LAMP stack。(相關指令如下)

已經安裝好相關的套件供安裝需要的套件的時候所使用。

預設的PHP 版本為:5.5.9, MySQL版本為:5.5。


# Prerequisite
# You should run the initial_ubuntu.sh script before running this bash script file.
sudo apt-get update
sudo apt-get install dialog tasksel software-properties-common
sudo tasksel install lamp-server

[本文]

本章節主要是展示:

  • PHP 5.5 升級到PHP 7.0
  • MySQL5.5 升級到MySQL 5.6

[PHP5.5 升級]


# upgrade the PHP 5.5.9 to PHP 7
sudo add-apt-repository ppa:ondrej/php

[MySQL5.5升級]


# upgrade the MySQL 5.5 to MySQL 5.7
wget http://dev.mysql.com/get/mysql-apt-config_0.8.0-1_all.deb

# The following command will ask for input:
# see more details: https://askubuntu.com/questions/750498/mysql-5-5-update-to-mysql-5-7
# Notice: I choose the MySQL 5.6 because the MySQL 5.7 encounter some unexpected problems.
sudo dpkg -i mysql-apt-config_0.8.0-1_all.deb

MySQL 在安裝設定檔時,會有選項要選擇升級的MySQL版本。(如下示意圖)

動第一個選項就好,選完選『ok』

接下來是兩者都需要做的事情:更新repo 站點網址,安裝新版的套件以及重新啟動服務


# update the packages repo url
sudo apt-get update

# intall the required packages
sudo apt-get install php7.0
sudo apt-get install php7.0-mysql
sudo apt-get install mysql-server
sudo mysql_upgrade -u root -p
sudo service mysql restart

[MySQL 升級相關問題]


# MySQL server need the logger package during starting the MySQL service.
# If not, it will encounter: " mysqld_safe --syslog requested, but no 'logger' program found. Please ensure that 'logger' is in your PATH, or do not specify the --syslog option to mysqld_safe" error.
sudo apt-get install bsdutils

# solve the MySQL server error: MySQL 5.6 No directory, logging in with HOME=/
sudo service mysql stop
sudo chown mysql /var/run/mysqld
sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start

[PHP 升級相關問題]

下面列了幾個範例,當要額外安裝PHP extensions時,所做的動作以及啟動這些extensions

供 Apache server 以及 PHP CLI(command line interface) 所使用。


# If you use the Apache server
# Disable php5 Apache module then enable php7 Apache module
sudo a2dismod php5
sudo service apache2 restart
sudo a2enmod php7.0

# If you want to install additional extension for the PHP 7
# You have to refer the following commands.
sudo apt-get update
sudo apt-get install php7.0-curl php7.0-mbstring php7.0-mcrypt

# enable the module in PHP cli
sudo phpenmod mcrypt
sudo phpenmod mbstring
sudo phpenmod curl

# After installing the required PHP extensions, you should restart the Apache service.
# Then the PHP module will successfully load in PHP Apache modules.
sudo service apache2 restart

[參考資料]

  1. PHP, MySQL 升級相關bash script
  2. https://askubuntu.com/questions/750498/mysql-5-5-update-to-mysql-5-7
  3. https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-php-7-on-ubuntu-14-04
  4. https://stackoverflow.com/questions/35988990/how-to-enable-php7-module-in-apache