Ubuntu 14.04 source compilation installation php7.0 and MySQL 5.6

The apt installation package for the php7 version was not found in Ubuntu 14.04 in Aliyun, so it can only be installed by source code. There were many pits encountered in the process. There were problems in configuring with mysql and Nginx, so it is recorded here.

1. apt install mysql

1. Get Packages

1. Mysql version 5.5 was installed on the previous system. Here we uninstall it directly. If you have not installed it before, you can skip this step.

# Delete mysql first:
sudo apt-get remove mysql-*
# Then clean up the remaining data
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P

2. Update package:

apt update

3. Find an installable version of mysql

apt-cache search mysql

Print:

...
mysql-server-5.6 - MySQL database server binaries and system database setup
mysql-server-core-5.6 - MySQL database server binaries
mysql-source-5.5 - MySQL source
mysql-source-5.6 - MySQL source
mysql-testsuite - MySQL testsuite
mysql-testsuite-5.5 - MySQL testsuite
mysql-testsuite-5.6 - MySQL 5.6 testsuite

You can see that our package resources have version mysql-server-5.6.

4. Installation

 apt-get install mysql-server-5.6

During the installation process, you will need to enter the database password, just enter it directly.

5. Check if mysql is running
After successful installation, use the following command to see if it is working properly:

sudo service mysql status

You can see that mysql has been successfully installed and running:

root@iZ:/tmp# sudo service mysql status
mysql start/running, process 848

2. Modify Configuration

6. Change Configuration
Advance to mysql service:

#User name root, password assumed to be 123 456
mysql -uroot -p123456

Change the IP permissions for root access, or the external network connection will be denied.

> use mysql;
> update user set host='%' where user = 'root' and host = '::1'

7. Modify MySQL listening IP

By default, MySQL listens on 127.0.0.1, which is the local machine, so only the local machine can connect, so you need to change MySQL to listen on remote host IP or all IP.

Open the configuration file/etc/mysql/my.cnf, find bind-address, change to remote host IP if listening on fixed remote IP, change to 0.0.0.0 if listening on all IP, or comment on bind-address, we comment out directly here, and restart when modification is complete.

#bind-address = 127.0.0.1

Restart mysql

service mysql restart

8. Complete my.cnf configuration:
/etc/mysql/my.cnf

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port        = 3306
socket        = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket        = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket        = /var/run/mysqld/mysqld.sock
port        = 3306
basedir        = /usr
datadir        = /var/lib/mysql
tmpdir        = /tmp
lc-messages-dir    = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address        = 127.0.0.1
#
# * Fine Tuning
#
key_buffer        = 16M
max_allowed_packet    = 16M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit    = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries    = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id        = 1
#log_bin            = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10
max_binlog_size         = 100M
innodb_large_prefix = ON
innodb_file_format = BARRACUDA
max_connections = 10000
#binlog_do_db        = include_database_name
#binlog_ignore_db    = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem



[mysqldump]
quick
quote-names
max_allowed_packet    = 16M

[mysql]
#no-auto-rehash    # faster start of mysql but no tab completition

[isamchk]
key_buffer        = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

As you can see, we have added several new parameters to the configuration file:

#5.6 Compatibility 5.7 mb4 index over limit issue
innodb_large_prefix = ON
innodb_file_format = BARRACUDA
# Maximum number of connections 10000, default number is small
max_connections = 10000

So far, we have successfully installed MySQL 5.6 using apt.

2. Source Code Compilation and Installation php7.0

1. Download Source

Source packages are placed in the / var/software directory:

root@i:/var/software# wget http://am1.php.net/distributions/php-7.0.0.tar.gz

2. Unzip installation

1. Decompression

cd /var/software
tar -zxvf php-7.0.0.tar.gz
cd php-7.0.0

2. Compile

./configure --prefix=/usr/local/php7.0 --with-config-file-path=/usr/local/php7.0 --enable-mbstring --enable-ftp --with-gd  --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --enable-pcntl --enable-cli --with-openssl --with-curl 

--prefix denotes the path where php is installed and will default to one if not written.

We will install php7 in the / usr/local/php7.0 directory.

3. Compile and Install:

make && make install

4. Testing:
The directory we installed is: /usr/local/php7.0, which has these folders.

drwxr-xr-x 2 root root  4096 Nov 28 23:22 bin
drwxr-xr-x 3 root root  4096 Nov 29 09:40 etc
drwxr-xr-x 3 root root  4096 Nov 28 23:17 include
drwxr-xr-x 3 root root  4096 Nov 28 23:17 lib
drwxr-xr-x 4 root root  4096 Nov 28 23:17 php
drwxr-xr-x 2 root root  4096 Nov 28 23:22 sbin
drwxr-xr-x 4 root root  4096 Nov 28 23:17 var

After entering the installation directory, view the extensions with the command. /bin/php -m:

# cd /usr/local/php7.0
# ./bin/php -m
[PHP Modules]
Core
ctype
date
dom
fileinfo
filter
hash
iconv
json
libxml
pcre
PDO

3. Simplify PHP command execution

We can see that if you want to execute a PHP script, you need to execute/usr/local/php7.0/bin/php-m according to the full path of php, which is tedious and cumbersome. If you set an alias, it is very simple to follow a script directly, such as: php-m, is it very simple?

Modifying the execution command requires adding the executed command to the configuration file/root/.bashrc:

vim /root/.bashrc
# Add php shortcut command
alias php=/usr/local/php7.0/bin/php

Reload:

source /root/.bashrc

In this way, we can execute the command directly using php, that is, view the PHP version:

root@i:/usr/local/php7.0# php -v
PHP 7.0.0 (cli) (built: Nov 28 2019 23:16:55) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

4. php.ini file

Reference article:
Ubuntu installation php7.0 environment
PHP Source Installation for Swoole Learning (1)
Deploying the Laravel project on the Aliyun ECS

Tags: MySQL PHP Database sudo

Posted on Thu, 28 Nov 2019 23:18:05 -0800 by vij