3. MySQL installation
- Several commonly used installation packages of MySQL: rpm, source code, binary compiler-free
- rpm package can not be customized, not recommended; source code to compile, very slow, but can improve performance, temporarily do not learn; learn others compiled compiler-free package first
3.1 Download Software Package
[root@localhost ~]# cd /usr/local/src // / enters the directory, which will be used as the download and storage directory of software packages by default in the future. [root@localhost src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz//download packages to this directory
3.2 Initialization of Mysql Installation File
[root@localhost src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz//decompression-free compiler package - mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql //Mobile directory / usr/local /, renamed MySQL # Verify that / usr/local/mysql is not created, otherwise the following command will become mobile rather than renamed - useradd mysql Establish MySQL user - mkdir /data/ Establish MySQL Data storage directory - ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql Format mysql file [root@localhost src]# ls mysql-5.6.35-linux-glibc2.5-x86_64 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz [root@localhost src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql [root@localhost src]# cd !$ cd /usr/local/mysql [root@localhost mysql]# ls bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files [root@localhost mysql]# useradd mysql // Professional users who add mysql [root@localhost mysql]# Mkdir-p/data/mysql//create datadir, where the database files exist [root@localhost mysql]# Chown-R mysql: mysql/data/mysql//Change permissions and allocate permissions reasonably [root@localhost mysql]# / scripts/mysql_install_db --user=mysql --datadir=/data/mysql // initialization [root@localhost mysql]# echo $? 0 # Query whether the previous compilation command succeeded, return 0 indicates success, return 1 indicates failure.
3.2.1 Errors encountered during initialization
Error 1:
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper
Solution:
# yum-y install autoconf // install missing autoconf
Error 2:
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
Solution:
# Yum install-y libaio-devel.x86_64// / Install missing libaio packages, usually just install devel library files.
3.3 Configuration of Mysql
# Copy configuration files [root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf cp: Is it covered?"/etc/my.cnf"? y # Copy the startup script file and modify its properties [root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@localhost mysql]# chmod 755 /etc/init.d/mysqld # Modify the startup script [root@localhost mysql]# vim /etc/init.d/mysqld # Where changes are needed, basedir and datadir basedir=/usr/local/mysql datadir=/data/mysql # Add the startup script to the startup entry and set the startup startup [root@localhost mysql]# chkconfig --add mysqld // add mysqld service to boot service [root@localhost mysql]# chkconfig --list // / Check to see if the boot service was successful # Command to start mysql service [root@localhost mysql]# service mysqld start Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'. SUCCESS! # Check whether the mysql process starts and its port ps aux | grep mysql netstat -lntp mysql Default port 3306 # View the error log that mysql cannot start properly [root@localhost mysql]# Cat/data/mysql/localhost.localdomain.err//usually/data/mysql/host name.err file
3.3.1 Command Line Start mysql Method
- If you can't put the script into the boot-up service, or if you don't have a copy of the script template, start the mysql service, using the command line /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql & ps
- Start mysql with the service command and close it with the / etc/init.d/mysqld stop command, but open it in the way of the command line above. That's not enough. So how do we stop?
- Only kill all MySQL can be used to shut down, not kill mysql, because kill will terminate the process directly, and kill all will wait. After reading and writing the data, it will be finished. If there is no response from killall in the later work, it is because of the large amount of data, then wait all the time. Don't worry.
- The killall command centos7 is not installed by default. The installation command is as follows
# yum install -y psmisc
4. Apache(httpd) installation
4.1 Download Source Pack
- apache official address: http://www.apache.org/dyn/closer.cgi
- Apache is the name of a foundation. httpd is the package we want to install. In the early days, it was called apache. Now the mainstream version is 2.4.
- The installation methods of 2.2 and 2.4 are different, involving different versions of the APR generic libraries that depend on them. Our APR package in CentOS7 is 2.2, while 2.4 needs to be downloaded and compiled by ourselves.
[root@localhost mysql]# cd /usr/local/s [root@host src]# WGet http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.32.tar.gz//httpd binary package [root@host src]# WGet http://mirrors.hust.edu.cn/apache/apr/apr-1.6.3.tar.gz//APR library source package [root@host src]# WGet http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.gz//APR-util library source package
4.2 Decompression
[root@localhost src]# tar zxvf httpd-2.4.32.tar.gz [root@localhost src]# tar zxvf apr-1.6.3.tar.gz [root@localhost src]# tar zxvf apr-util-1.6.1.tar.gz
4.3 Installation of apr
[root@localhost src]# cd /usr/local/src/apr-1.6.3 [root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu Configuring APR library Platform: x86_64-pc-linux-gnu checking for working mkdir -p... yes APR Version: 1.6.3 checking for chosen layout... apr checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/usr/local/src/apr-1.6.3': configure: error: no acceptable C compiler found in $PATH // Wrong! See `config.log' for more details # Errors occurred in compilation. The solution is to install gcc Suite [root@localhost apr-1.6.3]# yum install -y gcc # An error occurred in the recompilation. The error code is as follows: ... ... config.status: executing libtool commands rm: cannot remove 'libtoolT': No such file or directory config.status: executing default commands # The solution is editors. configure Document, Find $RM "$cfgfile" This place, use#Annotate [root@localhost apr-1.6.3]# vim configure /$RM "$cfgfile //Find this and comment it out with #. [root@localhost apr-1.6.3]# Make & make install // compile [root@localhost apr-1.6.3]# echo $? 0
4.4 Installation of APR-util
[root@localhost apr-1.6.3]# cd /usr/local/src/apr-util-1.6.1 [root@localhost apr-util-1.6.1]# . / configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr//initialization [root@localhost apr-util-1.6.1]# echo $? 0 [root@localhost apr-util-1.6.1]# Make & make install // compile ... ... # Report errors xml/apr_xml.c:35:19: Fatal error: expat.h: No file or directory #include <expat.h> # Solution: Install expat Library [root@localhost apr-util-1.6.1]# yum install expat-devel [root@localhost apr-util-1.6.1]# Make & make install // / recompile [root@localhost apr-util-1.6.1]# echo $? 0
4.5 Install httpd
[root@localhost apr-util-1.6.1]# cd /usr/local/httpd-2.4.32 [root@localhost httpd-2.4.32]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most #### --enable-so \ //Open support for dynamic extension modules, PHP and Appache support the existence of modules --enable-mods-shared=most //Represents opening most modules #### # Compile and report errors ... ... checking for pcre-config... false configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ # Solution to install pcre Library [root@localhost httpd-2.4.32]# yum install -y pcre-devel.x86_64 # Re initialization [root@localhost httpd-2.4.32]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most [root@localhost httpd-2.4.32]# echo $? 0 # Compile [root@localhost httpd-2.4.32]# make && make install [root@localhost httpd-2.4.32]# echo $? 0 # If the following error occurs during compilation: ...... #Errors may or may not occur, but if they occur later, note that the reason for the damage of the apr package is collect2: error: ld returned 1 exit status make[2]: *** [htpasswd] Error 1 make[2]: Leaving directory `/usr/local/src/httpd-2.4.27/support' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/usr/local/src/httpd-2.4.27/support' # Solution: Because there is no APR package, it may be the first initialization time, there was a mistake, the APR package messed up, and then reinstalled the APR package and apr-util package. # Start apache [root@localhost httpd-2.4.32]# / usr / local / Apache 2.4 / bin / apachectl start // / is prompted below, but it's not wrong AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message [root@localhost httpd-2.4.32]# ps aux | grep httpd root 63343 0.0 0.1 70904 2212 ? Ss 01:10 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 63344 0.0 0.1 359868 2212 ? Sl 01:10 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 63345 0.0 0.1 359868 2212 ? Sl 01:10 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 63346 0.0 0.1 359868 2212 ? Sl 01:10 0:00 /usr/local/apache2.4/bin/httpd -k start root 63429 0.0 0.0 112676 984 pts/0 R+ 01:10 0:00 grep --color=auto httpd [root@localhost httpd-2.4.32]# Netstat-lntp//View port, httpd default listening port is 80 port Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 852/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1069/master tcp6 0 0 :::80 :::* LISTEN 63343/httpd tcp6 0 0 :::22 :::* LISTEN 852/sshd tcp6 0 0 ::1:25 :::* LISTEN 1069/master tcp6 0 0 :::3306 :::* LISTEN 1884/mysqld
5. Compile and install PHP
The reason for putting PHP in the final installation is that apache and mysql paths need to be specified when compiling PHP. The installation sequence of apache and mysql doesn't matter. The current mainstream versions of PHP are 5.6 and 7.1
5.1 Download and Unzip PHP 5.6
[root@localhost httpd-2.4.32]# cd /usr/local/src [root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2 [root@localhost src]# tar jxf php-5.6.30.tar.bz2 tar (child): bzip2: Cannot exec: No such file or directory tar (child): Error is not recoverable: exiting now tar: Child returned status 2 tar: Error is not recoverable: exiting now //Note that the package (bzip2) is not installed. Solution: Install (bzip2) package [root@localhost src]# yum -y install bzip2 [root@localhost src]# tar jxf php-5.6.30.tar.bz2
5.2 Configure compilation parameters, compile and install
[root@localhost src]# cd php-5.6.30 # Initialization (LAMP, M=mysql) [root@localhost php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --- # Initialization (LAMP, M=mariadb) [root@localhost php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mariadb --with-pdo-mysql=/usr/local/mariadb --with-mysqli=/usr/local/mariadb/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --- # explain # Preix installation directory #with-apxs2 apache tool, let us not need to interfere with it manually, help to put the extension module into apache modules directory, and add a line of mod-modules to its configuration file, automatically configure the module for you, generally you can add so files, but will not automatically load the configuration module, which is why you do not install PHP later. #With-mysql -- with-pdo-mysql -- with-mysql defines a function or driver for MySQL communication that allows php to exchange data with MySQL #with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif are some of the necessary parameters. #In the compilation process, there will be some errors, often due to the lack of relevant library files. # Report errors 1. configure: error: xml2-config not found. Please check your libxml2 installation. yum install libxml2-devel -y 2. configure: error: Cannot find OpenSSL's <evp.h> yum install -y openssl openssl-devel 3. configure: error: Please reinstall the BZip2 distribution yum install -y bzip2 bzip2-devel 4. configure: error: jpeglib.h not found. yum install -y libjpeg-devel 5. configure: error: png.h not found. yum install -y libpng-devel 6. configure: error: freetype-config not found. yum install -y freetype-devel 7. configure: error: mcrypt.h not found. Please reinstall libmcrypt. (centos Source cannot be installed libmcrypt-devel,For copyright reasons, no self-contained mcrypt Package rpm -qa|grep limcrypt limcrypt-devel,This source is rethot Source of Community Edition) //Installation of third-party yum sources wget http://www.atomicorp.com/installers/atomic sh ./atomic yum install php-mcrypt libmcrypt libmcrypt-devel # Compile [root@localhost php-5.6.30]# echo $? 0 [root@localhost php-5.6.30]# make && make install [root@localhost php-5.6.30]# echo $? 0
5.3 Copy of php configuration file
# Copy the reference profile to the defined path [root@localhost php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini # You can also find it yourself, / usr/local/php/bin/php -i | less to see some php parameters # php.ini-production is used in the production environment configuration file, as well as for the development and experimental environment configuration file php.ini-development.
5.4 view
[root@localhost php-5.6.30]# Ls/usr/local/php/php/php core file bin etc include lib php [root@localhost php-5.6.30]# The binary files of ls/usr/local/php/bin/php core are in this folder pear peardev pecl phar phar.phar php php-cgi php-config phpize [root@localhost php-5.6.30]# du -sh /usr/local/php/bin/php 36M /usr/local/php/bin/php [root@localhost php-5.6.30]# Du-sh/usr/local/apache 2.4/modules/libphp5.so//PHP and Apache combined modules 37M /usr/local/apache2.4/modules/libphp5.so # View php loaded modules (static) [root@localhost php-5.6.30]# /usr/local/php/bin/php -m # View php loaded modules (static + dynamic) [root@localhost php-5.6.30]# /usr/local/php/bin/php -M # apache configuration file [root@localhost php-5.6.30]#vi /usr/local/apache2.4/conf/httpd.conf
5.5 Install PHP7
Similar steps to installing PHP5
cd /usr/local/src/ wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2 tar zxf php-7.1.6.tar.bz2 cd php-7.1.6 ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif make && make install ls /usr/local/apache2.4/modules/libphp7.so cp php.ini-production /usr/local/php7/etc/php.ini