Detailed steps Ubuntu 16.4.6 Server installation php7.2 + mysql5.6 + PHP FPM + redis to the custom directory

The installation environment is:

php-7.2.24.tar.bz2 
pcre-8.42.tar.bz2
openssl-1.0.2u.tar.gz 
nginx-1.16.1.tar.gz 
mysql-5.6.44.tar.gz 
freetype-2.10.0.tar.bz2 

The environment is installed in the specified directory without disturbing other environments.

The newly installed ubuntu system, ssh for shell management;

sudo apt-get install openssh-server
ssh localhost

Install the dependency package of Ubuntu system;

apt-get -y install  build-essential gcc g++ make bison bzip2 libxml2 openssl libssl-dev libcurl4-openssl-dev libsasl2-dev pkg-config libpng3 libjpeg-dev libpng-dev libpng12-0 libpng12-dev  libxslt1-dev  libncurses5 libncurses5-dev 


Create user name and group diywork

groupadd diywork
useradd -s /sbin/nologin -g diywork diywork

Create installation directory

mkdir -p /home/siyue/server/{data,etc,init.d,tmp,php,mysql,nginx,bin,lib}    
chown -R diywork:diywork /home/siyue/server/{data,etc,init.d,tmp,php,mysql,nginx,bin,lib}
chmod 755 /home/siyue/server/{data,etc,init.d,tmp,php,mysql,nginx,bin,lib} 

    
To install the php environment:

Install the auxiliary freetype package, and extract the downloaded freetype-2.10.0.tar.bz2 package.

    tar jxvf freetype-2.10.0.tar.bz2
    cd freetype-2.10.0
    ./configure --prefix=/home/siyue/server/local/freetype --enable-freetype-config
    make 
    make install

Unzip and download the installation package directory of php-7.2.24.tar.bz2

    tar jxvf php-7.2.24.tar.bz2
    cd php-7.2.24


     
Compile php7.2.4 package. Here, install the PHP environment to the directory / home / Siyu / server / PHP by setting the -- prefix parameter.

    ./configure --prefix=/home/siyue/server/php --with-config-file-path=/home/siyue/server/php/etc --with-config-file-scan-dir=/home/siyue/server/php/conf.d --enable-fpm --with-fpm-user=diywork --with-fpm-group=diywork --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/home/siyue/server/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-opcache --with-xsl  
    make  
    make install 
    


The above orders shall be executed line by line;

Configure php.ini
 

    \cp php.ini-production /home/siyue/server/php/etc/php.ini
    sed -i 's/post_max_size =.*/post_max_size = 50M/g' /home/siyue/server/php/etc/php.ini
    sed -i 's/upload_max_filesize =.*/upload_max_filesize = 50M/g' /home/siyue/server/php/etc/php.ini
    sed -i 's/;date.timezone =.*/date.timezone = PRC/g' /home/siyue/server/php/etc/php.ini
    sed -i 's/short_open_tag =.*/short_open_tag = On/g' /home/siyue/server/php/etc/php.ini
    sed -i 's/;cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/g' /home/siyue/server/php/etc/php.ini
    sed -i 's/max_execution_time =.*/max_execution_time = 300/g' /home/siyue/server/php/etc/php.ini
    sed -i 's/disable_functions =.*/disable_functions = passthru,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /home/siyue/server/php/etc/php.ini


    
Configure php-fpm.conf.

    vim  /home/siyue/server/etc/php-fpm.conf 

   
Copy the contents of the file into the file and save to exit.

[global]
pid = /home/siyue/server/php/var/run/php-fpm.pid
error_log = /home/siyue/server/php/var/log/php-fpm.log
log_level = notice

[xfplaywww]
listen = /home/siyue/server/tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner =diywork
listen.group = diywork
listen.mode = 777
user = diywork
group = diywork
pm = dynamic
pm.max_children = 80
pm.start_servers = 40
pm.min_spare_servers = 40
pm.max_spare_servers = 80
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = /home/siyue/server/log/slow.log
pm.status_path = /home/siyue/server/status

Copy PHP FPM startup script
cd to php7.2.4 source installation package directory

 mkdir /home/siyue/server/init.d

 \cp ./sapi/fpm/init.d.php-fpm /home/siyue/server/init.d/php-fpm
 chmod +x /home/siyue/server/init.d/php-fpm
 ln -s /home/siyue/server/init.d/php-fpm /etc/init.d/php-fpm


 
Install the composer component of php plug-in;
 

   wget --prefer-family=IPv4 --no-check-certificate -T 120 -t3 https://getcomposer.org/download/1.9.3/composer.phar -O /home/siyue/server/bin/composer

Install mysql5.6
Unzip the installation package

tar zxvf mysql-5.6.44.tar.gz
cd mysql-5.6.44
cmake -DCMAKE_INSTALL_PREFIX=/home/siyue/server/mysql -DSYSCONFDIR=/home/siyue/server/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1

make
make install

Configure my.cnf

mkdir /home/siyue/server/etc
mv /home/siyue/server/mysql/my.cnf /home/siyue/server/mysql/my-default.cnf
cat > /home/siyue/server/mysql/my.cnf<<EOF
[client]
#password= your_password
port= 23306
socket= /home/siyue/server/tmp/mysql.sock
default-character-set=utf8

#[mysqld_multi]
#mysqld=/home/siyue/server/mysql/bin/mysqld_safe
#mysqladmin=/home/siyue/server/mysql/bin/mysqladmin

[mysqld]
port= 23306
socket= /home/siyue/server/tmp/mysql.sock
datadir  =/home/siyue/server/data
basedir  =/home/siyue/server/mysql
tmpdir   =/home/siyue/server/data
log-error=/home/siyue/server/etc/logerror.err
pid-file=/home/siyue/server/data/localhost.pid
log-bin=mysql-bin
binlog_format=mixed
server_id = 1

#skip-locking
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 8M
net_buffer_length = 8K
read_buffer_size = 8M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 256
query_cache_size = 8M
tmp_table_size = 8M
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535 
#expire_logs_days = 10
#explicit_defaults_for_timestamp=true

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /home/siyue/server/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /home/siyue/server/data
innodb_buffer_pool_size = 10M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[myslqd_safe]
pid-file=/home/siyue/server/data/localhost.pid
log-error=/home/siyue/server/etc/logerror.err

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 8M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
EOF

Installation data directory

mkdir /home/siyue/server/data
chown diywork:diywork /home/siyue/server/data
chmod -R 755 /home/siyue/server/data

Initialize database data

  /home/siyue/server/mysql/scripts/mysql_install_db --defaults-file=/home/siyue/server/etc/my.cnf --basedir=/home/siyue/server/mysql --datadir=/home/siyue/server/data --user=diywork  

Add the startup script. The following code is executed in the mysql source package.

    
 chgrp -R diywork /home/siyue/server/mysql/.
 #\cp support-files/mysql.server /home/siyue/server/init.d/mysql
 chmod 755 /home/siyue/server/init.d/mysql
 ln -s /home/siyue/server/init.d/mysql /etc/init.d/mysql
 systemctl daemon-reload
 

Next, add the lib of mysql to the system library. Dynamic link library


cat > /etc/ld.so.conf.d/xfmysql.conf<<EOF
/home/siyue/server/mysql/lib
/home/siyue/server/local/lib
/usr/local/lib
EOF

 
Change administrator password: refer to another article.
 
Install Nginx

1 extract the file:
Install pcre plug-in to default

    tar jxvf pcre-8.42.tar.bz2
    cd pcre-8.42
    ./configure --prefix=/home/siyue/server/pcre-7.8 --libdir=/home/siyue/server/local/lib/pcre --includedir=/home/siyue/server/local/include/pcre
    make 
    make install
    
    ln -s /home/siyue/server/local/lib/libpcre.so.1.2.10  /usr/lib/libpcre.so.1
    

Extract the openssl package, which is used to install nginx to support ssl.

    tar zxvf openssl-1.0.2u.tar.gz

Add the following sentence to the configure statement of nginx:
    --with-openssl=/home/kunbei/serverInstallUbuntu/openssl-1.0.2u
    

    tar zxvf nginx-1.16.1.tar.gz 
    cd nginx-1.16.1
    
    ./configure --user=diywork --group=diywork --prefix=/home/siyue/server/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/home/kunbei/serverInstallUbuntu/openssl-1.0.2u 
   

Install nginx and configure the site directory.

    make
    make install
    
    mkdir -p /home/siyue/www
    chmod +w /home/siyue/www
    mkdir -p /home/siyue/wwwlogs
    chmod 777 /home/siyue/wwwlogs
    chown -R diywork:diywork /home/siyue/www
    mkdir /home/siyue/server/nginx/conf/vhost
     


The following is the startup script for nginx. The specific contents of init.d.nginx refer to another blog post.
    vim /home/siyue/server/init.d/nginx
Copy the contents of the startup script to a file and save to exit.
    chmod +x /home/siyue/server/init.d/nginx
    ln -s /home/siyue/server/init.d/nginx /etc/init.d/nginx
    systemctl daemon-reload
 
Install redis-5.0.5
 

 wget http://download.redis.io/releases/redis-5.0.5.tar.gz redis-5.0.5.tar.gz
 
 tar zxvf redis-5.0.5.tar.gz 
 cd redis-5.0.5
 make PREFIX=/home/siyue/server/redis install
 
 mkdir -p /home/siyue/server/redis/etc/
 
 #\cp redis.conf  /home/siyue/server/redis/etc/
 


Install the redis extension library redis-5.1.0 of php

 wget http://pecl.php.net/get/redis-5.1.0.tgz redis-5.1.0.tgz
  tar zxvf redis-5.1.0.tgz
  cd redis-5.1.0
  
  /home/siyue/server/php/bin/phpize
  ./configure --with-php-config=/home/siyue/server/php/bin/php-config
  make install
  
cat > /home/siyue/server/php/conf.d/redis-007.ini<<EOF
extension = "redis.so" 
EOF  


     
Here is the script to start redis. The specific contents of init.d/redis refer to another blog post.
    vim /home/siyue/server/init.d/redis
Copy the contents of the startup script to a file and save to exit.
    vim /home/siyue/server/init.d/redis
    
    chmod +x /home/siyue/server/init.d/redis
    ln -s /home/siyue/server/init.d/redis /etc/init.d/redis
    systemctl daemon-reload
 
 
 
 
 

Tags: Programming PHP MySQL Redis Nginx

Posted on Fri, 13 Mar 2020 06:23:00 -0400 by JD-AM