前言
环境:Centos 7.9 nginx-1.18.0.tar.gz mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz php-7.4.16.tar.gz
具体安装细节这里就不说,可以查看本人其他文章《Linux下安装mysql(yum、二进制包、源码包)》,这里是直接给出大概的安装脚本。
nginx的安装(命令脚本)
groupadd nginx
useradd -s /sbin/nologin -M nginx
yum install -y make gcc gcc-c++ pcre* zlib* openssh*
(或yum -y install make gcc gcc-c++ pcre pcre-devel zlib-devel zlib openssl-devel openssl)
tar -xzvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure --with-http_stub_status_module --prefix=/usr/local/nginx --user=nginx --group=nginx
make
make install
echo 'PATH=/usr/local/nginx/sbin/:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
mysql的安装(命令脚本)
这里采用二进制包,二进制包是已经预编译过了的,不需要cmake编译。
rpm -qa | grep glibc #查看本机的glibc版本后下载对应的mysql二进制包
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz
yum install libaio #官方说要安装这个libaio依赖包
yum install ncurses-compat-libs #官方说要安装ncurses-compat-libs依赖包(建议直接yum install ncurses*)
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar xvf /path/to/mysql-VERSION-OS.tar.xz
ln -s full-path-to-mysql-VERSION-OS mysql
cd mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
bin/mysqld --initialize --user=mysql #初始化数据目录,会生成root初始登录密码
bin/mysql_ssl_rsa_setup #配置自动支持安全连接
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysql.server
echo 'PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
echo 'export PATH' >> /etc/profile
scp /etc/my.cnf root@192.168.43.229:/etc/ #从其他主机复制一个my.cnf文件过来并修改参数,因为mysql8已经不提供该文件了
service mysql.server start
Shutting start MySQL.. SUCCESS! #出现这一行mysql就成功启动了
PHP的安装(命令脚本)
nginx和mysql都安装完了,现在安装PHP,为了保证PHP程序运行时不出现问题,建议(不是必须)安装下面的包。
rpm -qa sqlite-devel oniguruma oniguruma-devel zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
yum install sqlite-devel oniguruma oniguruma-devel zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
安装libiconv-devel失败,下面采用编译安装:
wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
tar -xzvf libiconv-1.16.tar.gz -C /usr/local/
cd /usr/local/
mkdir libiconv
cd libiconv-1.16/
./configure --prefix=/usr/local/libiconv
make
make install
yum install libmcrypt-devel #libmcrypt库
yum install mhash mcrypt #安装mhash、mcrypt加密扩展库
真正开始安装PHP
tar -xvzf php-7.4.16.tar.gz -C /usr/local/
cd /usr/local/
mkdir php
cd php-7.4.16
./configure \
--prefix=/usr/local/php \
--with-mysql=/usr/local/mysql \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with--openssh \
--with-mhash \
--enable--pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp
显示如下就表明预编译成功了:
make
make install
完成PHP的安装