一、环境
[root@localhost ~]# uname -r
3.10.0-1062.el7.x86_64
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
二、源码安装mysql5.5
卸载mysql
[root@localhost ~]# rpm -qa|grep mariadb|xargs rpm -e –nodeps
[root@localhost ~]# rpm -qa|grep mysql|xargs rpm -e –nodeps
安装基础支持
[root@localhost ~]# yum install vim wget lrzsz cmake ncurses-devel ncurses gcc-c++ bison -y
下载mysql安装包
[root@localhost soft]# wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.62.tar.gz
准备安装
[root@localhost soft]# tar -zxvf mysql-5.5.62.tar.gz
[root@localhost soft]# cd mysql-5.5.62
预编译(cmake、make、make install)
预编译
[root@localhost mysql-5.5.62]# cmake .\
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql55\
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock\
-DMYSQL_DATADIR=/data/mysql\
-DSYSCONFDIR=/etc\
-DMYSQL_USER=mysql\
-DMYSQL_TCP_PORT=3306\
-DWITH_XTRADB_STORAGE_ENGINE=1\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_PARTITION_STORAGE_ENGINE=1\
-DWITH_BLACKHOLE_STORAGE_ENGINE=1\
-DWITH_MYISAM_STORAGE_ENGINE=1\
-DWITH_READLINE=1\
-DENABLED_LOCAL_INFILE=1\
-DWITH_EXTRA_CHARSETS=1\
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8_general_ci\
-DEXTRA_CHARSETS=all\
-DWITH_BIG_TABLES=1\
-DWITH_DEBUG=0 . 注:最后一行有‘.’
[root@localhost mysql-5.5.62]# echo $?
0
[root@localhost mysql-5.5.62]# make
[root@localhost mysql-5.5.62]# make install
将源码安装的mysql设置为系统服务,并使用chkconfig管理
[root@localhost mysql-5.5.62]# cd /usr/local/mysql55/
[root@localhost mysql55]# \cp support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql55]# \cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql55]# chkconfig --add mysqld
[root@localhost mysql55]# chkconfig --level 35 mysqld on
[root@localhost mysql55]# mkdir -p /data/mysql
[root@localhost mysql55]# useradd mysql
[root@localhost mysql55]# /usr/local/mysql55/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql55/
Installing MySQL system tables...
[root@localhost mysql55]# ln -s /usr/local/mysql55/bin/* /usr/bin/
[root@localhost mysql55]# /etc/init.d/mysqld start
------忽略-------------------------------------
不设置为系统服务,用源码方式启动mysql
#cd /usr/local/mysql55/
#mkdir -p /data/mysql
#/usr/local/mysql55/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql55/
#ln -s /usr/local/mysql55/bin/* /usr/bin/
#/usr/local/mysql55/bin/mysqld_safe --user=mysql &
…
修改mysql密码及远程连接权限
[root@localhost mysql55]# /etc/init.d/mysqld stop
[root@localhost mysql55]# /usr/bin/mysqld_safe --user=mysql --skip-grant-tables &
[1] 28949
'/data/mysql/localhost.localdomain.err'.
200509 21:55:30 mysqld_safe Starting mysqld daemon with databases from /data/mysql
[root@localhost mysql55]#
[root@localhost mysql55]# mysql
mysql> use mysql;
Database changed
mysql> update user set password=password('123456') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
重启mysql服务,添加外联权限
[root@localhost mysql55]# /etc/init.d/mysqld stop
[root@localhost mysql55]# /etc/init.d/mysqld start
[root@centos65MsqlServer ~]# mysql -uroot -p123456直接回车
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456" WITH GRANT OPTION; 添加外部远程连接数据库权限
mysql> FLUSH PRIVILEGES; 刷新权限
mysql>exit;
开启防火墙(因为我做的是zabbix,所以一次性多开启些端口)
[root@localhost mysql55]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@localhost mysql55]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost mysql55]# firewall-cmd --zone=public --add-port=10051/tcp --permanent
success
[root@localhost mysql55]# firewall-cmd --zone=public --add-port=10050/tcp --permanent
success
[root@localhost mysql55]# firewall-cmd --reload
success
[root@localhost mysql55]# firewall-cmd --zone=public --list-ports
80/tcp 3306/tcp 10051/tcp 10050/tcp
测试mysql,使用第三方工具连接(navicat)
Mysql连接成功
三、源码安装配置apache
下载httpd包
[root@VM_0_14_centos soft]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.43.tar.gz
安装基础支持环境
[root@localhost soft]# yum install gcc gcc-c++ make expat-devel apr apr-util apr-devel apr-util-devel pcre pcre-devel libxml2 libxml2-devel bzip2 bzip2-devel curl-devel -y
[root@localhost soft]# tar -zxvf httpd-2.4.43.tar.gz
[root@localhost soft]# cd httpd-2.4.43
[root@localhost httpd-2.4.43]# ./configure --prefix=/usr/local/apache \
--enable-so \
--enable-rewrite
[root@localhost httpd-2.4.43]# echo $?
0
[root@localhost httpd-2.4.43]# make
[root@localhost httpd-2.4.43]# make install
编译httpd.conf配置文件
[root@localhost httpd-2.4.43]# vim /usr/local/apache/conf/httpd.conf
ServerName www.example.com:80 把前面的注释去掉
测试:
在浏览器中输入http://192.168.1.107/ 看是否出现‘It works’,见下图
四、源码安装配置php7
下载安装包
[root@VM_0_14_centos soft]# wget https://www.php.net/distributions/php-7.2.30.tar.gz
安装基础环境支持
[root@localhost soft]#yum install -y libjpeg libpng-devel freetype freetype-devel libxslt libxslt-devel libXpm-devel postgresql-devel libzip
解压
[root@localhost soft]# tar -zxvf php-7.2.30.tar.gz
[root@localhost soft]# cd php-7.2.30
预编译
./configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--enable-fpm \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--with-pdo-pgsql \
--with-pdo-mysql=/usr/local/mysql55 \
--with-mysql-sock=/tmp/mysql.sock \
--with-pgsql \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-soap \
--enable-calendar \
--with-curl \
--with-gd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-mysqli \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-libdir=/lib/x86_64-linux-gnu/ \
--enable-ftp \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-opcache \
--with-iconv \
--with-xpm-dir=/usr \
--enable-mysqlnd \
--with-mysqli \
--with-iconv-dir \
--with-kerberos \
--with-pdo-sqlite \
--with-pear \
--enable-libxml \
--enable-shmop \
--enable-xml
报错:configure: error: off_t undefined; check your library configuration
添加文件库
[root@localhost php-7.2.30]# find / -name lib
[root@localhost php-7.2.30]# find / -name lib64 将得到的结果,选择添加进ld.so.conf文件,我加的有点长
[root@localhost php-7.2.30]# vim /etc/ld.so.conf 最下面添加多行
/run/initramfs/state/var/lib
/var/lib
/usr/lib
/usr/lib/debug/usr/lib
/usr/lib/debug/lib
/usr/lib/modules/3.10.0-1062.el7.x86_64/kernel/drivers/gpu/drm/amd/lib
/usr/lib/modules/3.10.0-1062.el7.x86_64/kernel/lib
/usr/lib/modules/3.10.0-1062.el7.x86_64/kernel/virt/lib
/usr/share/doc/perl-Test-Harness-3.28/examples/harness-hook/lib
/usr/share/gdb/auto-load/usr/lib
/usr/share/gdb/auto-load/lib
/usr/share/perl5/unicore/lib
/usr/include/pgsql/server/lib
/usr/local/lib
/usr/local/mysql55/lib
/usr/local/mysql55/mysql-test/lib
/usr/local/mysql55/mysql-test/suite/funcs_1/lib
/usr/local/mysql55/mysql-test/suite/funcs_2/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/alpha/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/arc/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/arm/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/arm64/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/avr32/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/blackfin/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/c6x/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/cris/arch-v10/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/cris/arch-v32/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/frv/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/h8300/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/hexagon/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/ia64/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/m32r/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/m68k/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/metag/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/microblaze/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/mips/fw/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/mips/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/mn10300/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/openrisc/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/parisc/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/powerpc/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/s390/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/score/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/sh/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/sparc/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/tile/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/unicore32/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/x86/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/xtensa/boot/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/xtensa/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/drivers/gpu/drm/amd/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/drivers/net/ethernet/mellanox/mlx5/core/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/include/config/ceph/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/include/config/snd/opl3/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/include/config/rt2800/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/include/config/rt2x00/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/tools/lib
/usr/src/kernels/3.10.0-1062.el7.x86_64/virt/lib
/lib
/usr/lib/debug/usr/lib64
/usr/lib/debug/lib64
/usr/lib/x86_64-redhat-linux6E/lib64
/usr/lib64
/usr/share/gdb/auto-load/usr/lib64
/usr/share/gdb/auto-load/lib64
/usr/local/lib64
/usr/src/kernels/3.10.0-1062.el7.x86_64/arch/sh/lib64
/lib64
[root@localhost php-7.2.30]# ldconfig -v 使之生效
再次预编译,没有出错了,安装
```bash
[root@localhost php-7.2.30]# make
[root@localhost php-7.2.30]# make install
配置环境变量
[root@localhost htdocs]# vim /etc/profile 最后一行加入
PATH=$PATH:/usr/local/php7/bin/
[root@localhost htdocs]# source /etc/profile
[root@localhost bin]# ln -s /usr/local/php7/bin/php /usr/bin/php
配置php-fpm
添加php.ini文件
[root@localhost php-7.2.30]# cp /home/soft/php-7.2.30/php.ini-development /usr/local/php7/etc/php.ini
[root@localhost bin]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
次配置文件(为php-fpm.conf中include):在其中可以配置php-fpm启动的端口、指定它的用户组及用户等
[root@localhost bin]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@localhost bin]# cp /home/soft/php-7.2.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost bin]# chmod +x /etc/init.d/php-fpm
[root@localhost bin]# ln -s /etc/init.d/php-fpm /usr/sbin/php-fpm
创建www-data组及用户
[root@localhost ~]# groupadd www-data
[root@localhost ~]# useradd -g www-data -m www-data
五、php-fpm与apache连接
[root@localhost htdocs]# vim /usr/local/apache/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule php7_module modules/libphp7.so 第156行
AddType application/x-httpd-php .php 第393行
AddType application/x-httpd-php-source .phps 第394行
DirectoryIndex index.php index.html 第255行
下面三行添加到最后
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
启动php-fpm
[root@localhost ~]# /etc/init.d/php-fpm start
Starting php-fpm done
[root@localhost ~]# ps -ef|grep php-fpm
root 2397 1 0 20:47 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
www-data 2398 2397 0 20:47 ? 00:00:00 php-fpm: pool www
www-data 2399 2397 0 20:47 ? 00:00:00 php-fpm: pool www
root 2404 2333 0 20:48 pts/0 00:00:00 grep --color=auto php-fpm
测试,查看phpinfo.php
六、添加动态模块方法,如mbstring
动态编译mbstring
[root@localhost htdocs]# cd /home/soft/php-7.2.30/ext/mbstring/
[root@localhost mbstring]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
[root@localhost mbstring]# ./configure --with-php-config=/usr/local/php7/bin/php-config
[root@localhost mbstring]# make
[root@localhost mbstring]# make install
Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20170718/
Installing header files: /usr/local/php7/include/php/
最后
extension = mbstring.so 添加到php.ini中
end