一、编译安装Nginx
1.前期准备
#安装依赖 yum -y install pcre-devel zlib-devel gcc gcc-c++ make #创建用户 useradd -M -s /sbin/nologin nginx #获取源码包 wget https://nginx.org/download/nginx-1.24.0.tar.gz
cd /opt tar xf nginx-1.24.0.tar.gz #解压
2.开始编译安装
cd nginx-1.24.0/ #编译 ./configure \ --prefix=/usr/local/nginx \ --user=nginx \ --group=nginx \ --with-http_stub_status_module
#安装 make -j2 && make install
#让系统识别nginx操作命令,可以补全 ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
3.添加到系统服务(systemd启动)
#新建nginx.service vim /lib/systemd/system/nginx.service [Unit] Description=nginx After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target systemctl daemon-reload systemctl start nginx
二、编译安装MySQL服务
1.前置准备
#依赖环境 yum -y install \ ncurses \ ncurses-devel \ bison \ cmake #添加用户 useradd -s /sbin/nologin mysql
将MySQL源代码包放在 /opt目录下 tar xf mysql-boost-5.7.20.tar.gz #解压 cd mysql-5.7.20
2.编译安装
#编译 cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ -DSYSCONFDIR=/etc \ -DSYSTEMD_PID_DIR=/usr/local/mysql \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DWITH_BOOST=boost \ -DWITH_SYSTEMD=1 #安装 make -j2 && make install
3.编辑配置文件
#进入配置文件,把内容全删掉,然后加入以下内容 vim /etc/my.cnf [client] port = 3306 default-character-set=utf8 socket = /usr/local/mysql/mysql.sock [mysql] port = 3306 default-character-set=utf8 socket = /usr/local/mysql/mysql.sock [mysqld] user = mysql basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 character_set_server=utf8 pid-file = /usr/local/mysql/mysqld.pid socket = /usr/local/mysql/mysql.sock server-id = 1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
4.更改mysql安装目录和配置文件的属主属组
chown -R mysql:mysql /usr/local/mysql/ chown mysql:mysql /etc/my.cnf
5.设置路径环境变量
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile source /etc/profile
6.数据库初始化
cd /usr/local/mysql/bin/ ./mysqld \ --initialize-insecure \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data
7.添加mysqld系统服务
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ #能用systemd启动
systemctl daemon-reload 刷新识别 systemctl start mysqld.service 开启服务 systemctl enable mysqld 开机自启动 ss -natp | grep 3306 查看端口
8.修改用户mysql 的登录密码
mysqladmin -u root -p password "123abc" mysql -u root -p #授权远程登录
三、编译安装PHP
1.前置准备
#安装依赖环境 #安装GD库和GD库关联程序,用来处理和生成图片 yum -y install \ libjpeg \ libjpeg-devel \ libpng libpng-devel \ freetype freetype-devel \ libxml2 \ libxml2-devel \ zlib zlib-devel \ curl curl-devel \ openssl openssl-devel
将PHP源代码包放在 /opt目录下 tar -jxvf php-7.1.10.tar.bz2 #解压 cd /opt/php-7.1.10/
2.编译安装
#编译环境检测 功能模块添加 ./configure \ --prefix=/usr/local/php \ --with-mysql-sock=/usr/local/mysql/mysql.sock \ --with-mysqli \ --with-zlib \ --with-curl \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-openssl \ --enable-fpm \ --enable-mbstring \ --enable-xml \ --enable-session \ --enable-ftp \ --enable-pdo \ --enable-tokenizer \ --enable-zip
#安装 make -j2 && make install
3.路径优化
ln -s /usr/local/php/bin/* /usr/local/bin/ ln -s /usr/local/php/sbin/* /usr/local/sbin/
4.调整PHP配置文件
php有三个配置文件 php.ini 主配置文件 php-fpm.conf 进程服务配置文件 www.conf 扩展配置文件
调整主配置文件
cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini #模板 vim /usr/local/php/lib/php.ini #修改主配置文件
调整进程服务配置文件
cd /usr/local/php/etc/php-fpm.d/ cp www.conf.default www.conf
vim php-fpm.conf
5.启动php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini ss -napt | grep 9000
cd /opt/php-7.1.10/sapi/fpm cp php-fpm.service /usr/lib/systemd/system/php-fpm.service systemctl restart php-fpm.service
6.配置 Nginx 支持 PHP 解析
vim /usr/local/nginx/conf/nginx.conf
systemctl restart nginx.service
7.验证PHP 测试页
#创建网页文件 vi /usr/local/nginx/html/index.php <?php phpinfo(); ?> #重启nginx服务 systemctl restart nginx #在网页测试 http://192.168.100.140/index.php
四、安装论坛
1.以 root 用户身份登录到 MySQL 数据库,进行配置
mysql -u root -p #以 root 用户身份登录到 MySQL 数据库
mysql> CREATE DATABASE bbs; #创建一个数据库 mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123'; #把bbs数据库里面所有表的权限授予给bbsuser,并设置密码 mysql>flush privileges; #刷新数据库
2.解压Discuz源码包并配置
unzip /opt/Discuz_X3.4_SC_UTF8.zip #解压 cd /opt/dir_SC_UTF8/ #拷贝文件到数据 cp -r upload/ /usr/local/nginx/html/bbs/
#改权限 改属组属主 cd /usr/local/nginx/html/bbs/ chown -R root:nginx ./config/ chown -R root:nginx ./data/ chown -R root:nginx ./uc_client/ chown -R root:nginx ./uc_server/ chmod -R 777 ./config/ chmod -R 777 ./data/ chmod -R 777 ./uc_client/ chmod -R 777 ./uc_server/
3.安装Discuz论坛
浏览器访问 http://192.168.100.140/bbs/install/index.php
访问论坛
访问Discuz论坛 http://192.168.100.140/bbs/index.php
cd /usr/local/php/etc/ cp php-fpm.conf.default php-fpm.conf vim php-fpm.conf 标签:--,lnmp,nginx,usr,mysql,php,local From: https://www.cnblogs.com/hxqwe/p/18250625