/ 创建MySQL用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
// 下载依赖包[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs
//修改名字[root@localhost local]# mv mysql-5.7.34-linux-glibc2.12-x86_64 mysql
// 修改目录/usr/local/mysql的属主属组[root@localhost local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost local]# ll -d /usr/local/mysql
drwxr-xr-x 9 mysql mysql 12910月 2710:05/usr/local/mysql
// 添加环境变量[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH'>/etc/profile.d/mysql.sh
[root@localhost ~]# ./etc/profile.d/mysql.sh
[root@localhost local]# which mysql
/usr/local/mysql/bin/mysql
// 创建数据存放目录[root@localhost ~]# mkdir /opt/data[root@localhost ~]# chown -R mysql.mysql /opt/data/// 初始化数据存放目录[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/2021-10-27T02:28:32.843787Z 0[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option(see documentation for more details).2021-10-27T02:28:33.064111Z 0[Warning] InnoDB: New log files created, LSN=457902021-10-27T02:28:33.095252Z 0[Warning] InnoDB: Creating foreign key constraint system tables.2021-10-27T02:28:33.152490Z 0[Warning] No existing UUID has been found, so we assume that thisis the first time that this server has been started. Generating a new UUID: 94a2a2c8-36cd-11ec-b7c0-000c29c8c712.2021-10-27T02:28:33.153197Z 0[Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2021-10-27T02:28:33.520218Z 0[Warning] CA certificate ca.pem is self signed.2021-10-27T02:28:33.791421Z 1[Note] A temporary password is generated forroot@localhost:)g5o1oc(ouaF
//备份最后的密码[root@localhost ~]# echo ')g5o1oc(ouaF'> pass.txt
[root@localhost ~]# cat pass.txt
)g5o1oc(ouaF
// 配置mysql[root@localhost ~]# ln -sv /usr/local/mysql/include//usr/local/include/mysql
"/usr/local/include/mysql"->"/usr/local/mysql/include/"[root@localhost ~]# echo '/usr/local/mysql/lib'>/etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# ldconfig
// 生成配置文件[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
basedir =/usr/local/mysql
datadir =/opt/data
socket =/tmp/mysql.sock
port =3306
pid-file =/opt/data/mysql.pid
user = mysql
skip-name-resolve
// 配置服务启动脚本[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g'/etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g'/etc/init.d/mysqld
//生成service文件[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# cat /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysqld server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
[Install]
WantedBy=multi-user.target
//重载[root@localhost ~]# systemctl daemon-reload
//启动服务[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0128*:22*:*
LISTEN 0100127.0.0.1:25*:*
LISTEN 080:::3306:::*
LISTEN 0128:::22:::*
LISTEN 0100::1:25:::// 登录并更改密码[root@localhost ~]# cat pass.txt
)g5o1oc(ouaF
[root@localhost ~]# mysql -uroot -p')g5o1oc(ouaF'//复制密码用引号括起
mysql:[Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ;or \g.
Your MySQL connection id is2
Server version:5.7.34Copyright(c)2000,2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or'\h'for help. Type '\c'to clear the current input statement.
mysql>
mysql>set password =password('1');
Query OK,0 rows affected,1warning(0.00 sec)
mysql> exit
Bye
4. 安装php
// 下载依赖包[root@localhost ~]# yum -y install sqlite-devel libzip-devel libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
// 编译安装[root@localhost]# cd /usr/local/php-8.0.10/[root@localhost php-8.0.10]# ./configure --prefix=/usr/local/php8 \
--with-config-file-path=/etc \
--enable-fpm \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix
此时会出现下面这个报错,
No package'oniguruma' found
//需要从网上下载,然后再安装[root@localhost php-8.0.10]# wget http://mirror.centos.org/centos/7/cloud/x86_64/openstack-queens/Packages/o/oniguruma-6.7.0-1.el7.x86_64.rpm
[root@localhost php-8.0.10]# wget http://mirror.centos.org/centos/7/cloud/x86_64/openstack-queens/Packages/o/oniguruma-devel-6.7.0-1.el7.x86_64.rpm
[root@localhost php-8.0.10]# yum -y install oniguruma*
又会有下面的报错,这里是说对libzip版本有要求
Requested 'libzip >= 0.11' but version of libzip is0.10.1//先删除老版本[root@localhost php-8.0.10]# yum remove libzip-devel libzip
//下载新的,编译安装[root@localhost php-8.0.10]# wget https://libzip.org/download/libzip-1.2.0.tar.gz --no-check-certificate
[root@localhost php-8.0.10]# tar -zxvf libzip-1.2.0.tar.gz
[root@localhost php-8.0.10]# cd libzip-1.2.0[root@localhost php-8.0.10]# ./configure
[root@localhost php-8.0.10]# make && make install
找一下/usr/local/lib下有没有pkgconfig目录,有的话设置环境变量
[root@localhost php-8.0.10]# export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"//重新编译+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available inthis |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
看到欢迎页面表示成功
[root@localhost php-8.0.10]# make && make install
//配置环境变量[root@localhost php-8.0.10]# echo 'export PATH=/usr/local/php8/bin:$PATH'>/etc/profile.d/php.sh
[root@localhost php-8.0.10]# source /etc/profile.d/php.sh
[root@localhost php-8.0.10]# which php
/usr/local/php8/bin/php
[root@localhost php-8.0.10]# php -v
PHP 8.0.10(cli)(built: Oct 27202111:29:54)( NTS )Copyright(c) The PHP Group
Zend Engine v4.0.10,Copyright(c) Zend Technologies
// 配置php-fpm[root@localhost php-8.0.10]# cp -f /usr/local/php-8.0.10/php.ini-production /etc/php.ini
[root@localhost php-8.0.10]# cp /usr/local/php-8.0.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm -f
[root@localhost php-8.0.10]# chmod +x /etc/init.d/php-fpm
[root@localhost php-8.0.10]# cp -f /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
[root@localhost php-8.0.10]# cp -f /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
// 配置service文件[root@localhost php-8.0.10]# vim /usr/lib/systemd/system/php-fpm.service
[root@localhost php-8.0.10]# cat /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=Php-fpm server daemon
After=network.target
[Service]
Type=forking
ExecStart=service php-fpm start
ExecStop=service php-fpm stop
[Install]
WantedBy=multi-user.target
[root@localhost php-8.0.10]# service php-fpm start
Starting php-fpm done
[root@localhost php-8.0.10]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0128127.0.0.1:9000*:*
LISTEN 0128*:22*:*
LISTEN 0100127.0.0.1:25*:*
LISTEN 080:::3306:::*
LISTEN 0128:::22:::*
LISTEN 0100::1:25:::*
[root@localhost ~]# vim /usr/local/php8/etc/php-fpm.d/www.conf
20; Unix user/group of processes
21; Note: The user is mandatory. If the group is not set, the default user's group
22; will be used.23 user = nginx #改为nginx
24 group = nginx #改为nginx
2526; The address on which to accept FastCGI requests.
7. 重启服务并测试
[root@localhost ~]# nginx -s stop;nginx
[root@localhost ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS![root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0128127.0.0.1:9000*:*
LISTEN 0128*:80*:*
LISTEN 0128*:22*:*
LISTEN 0100127.0.0.1:25*:*
LISTEN 080:::3306:::*
LISTEN 0128:::22:::*
LISTEN 0100::1:25:::*