1. 源码安装mysql
鉴于前边的文章已经详细说过mysql的源码安装 可以点击基于LAMP的Discuz论坛的实现(源码安装)自行查看 这里为了节省时间 用一个shell脚本进行mysql的源码安装 用到的mysql依然是5.6.46 没有源码包的同学可以点击 【mysql-5.6.46.tar.gz 提取码:nli5】进行下载
[root@localhost ~]# cat my.sh
#!/bin/bash
yum -y install bison cmake ncurses-devel openssl-devel perl-Data-Dumper
tar -zxf mysql-5.6.46.tar.gz
cd mysql-5.6.46
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
make -j4 && make install
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib
ln -s /usr/local/mysql/bin/* /usr/local/bin/
useradd -M -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql/
cd support-files/
\cp my-default.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysqld
sed -i '/^basedir=/c basedir=/usr/local/mysql' /etc/init.d/mysqld
sed -i '/^datadir=/c datadir=/usr/local/mysql/data' /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
[root@localhost ~]# bash my.sh
2. 源码安装nginx
对于nginx的安装,可以使用nginx安装、配置文件、虚拟主机、平滑升级、访问控制、启动脚本中的方法 但是 如果只是简单使用 没有复杂的模块的配置 可以使用如下的方式 快速安装 不需要添加用户 后期需要指定用户的时候修改配置文件即可
yum -y install gcc gcc-c++ pcre-devel zlib-devel openssl-devel
tar -zxf nginx-1.15.4.tar.gz
cd nginx-1.15.4
./configure && make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
nginx -v
3. 源码安装php
yum -y install gd libxml2-devel libjpeg-devel libpng-devel
tar -zxf php-7.2.0.tar.gz
cd php-7.2.0
./configure --prefix=/usr/local/php --with-gd --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib
make -j4 && make install
cp php.ini-development /usr/local/php/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
4. 修改nginx配置
[root@localhost etc]# vim /usr/local/nginx/conf/nginx.conf
43 location / {
44 root html;
45 index index.php index.html index.htm; #此行加index.php 在最前边
46 }
65-71行取消注释
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 include fastcgi.conf; #此行改为fastcgi.conf
71 }
检测语法
[root@localhost etc]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
5. 编辑测试页面
[root@localhost etc]# vim /usr/local/nginx/html/test1.php
<?php
phpinfo();
?>
[root@localhost etc]# vim /usr/local/nginx/html/test2.php
<?php
$con = new mysqli('127.0.0.1','root','123456');
if(!$con)
die("connect error:".mysqli_connect_error());
else
echo "connet mysql server ok!\n";
?>
6. 启动服务并测试
启动nginx(如果之前已启动则reload)并确保nginx是运行状态
[root@localhost ~]# nginx
[root@localhost ~]# netstat -anput | grep LISTEN | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 24989/nginx: master
启动php 并确保php是运行状态
[root@localhost ~]# /etc/init.d/php-fpm start
Starting php-fpm done
[root@localhost ~]# netstat -anput | grep LISTEN | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 25017/php-fpm: mast
确保mysql服务是开启的 如果没有开启 则开启
[root@localhost ~]# netstat -anput | grep LISTEN | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 18338/mysqld
分别访问http://nginx的ip/test1.php
http://nginx的ip/test2.php
进行测试 如下结果则OK
7. 部署Discuz论坛
论坛安装的操作与LAMP中的基本一致 在这里 web界面的操作 就不在做赘述了 可以参考 基于LAMP的Discuz论坛的实现(源码安装)里论坛的安装 里边有详细步骤和说明
[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# mkdir backup
[root@localhost html]# mv *.* backup/
[root@localhost html]# ls
backup
[root@localhost html]# cd
[root@localhost ~]# unzip ComsenzDiscuz-DiscuzX-master.zip
[root@localhost ~]# cp -r DiscuzX/upload/* /usr/local/nginx/html/
[root@localhost ~]# chmod -R 777 /usr/local/nginx/html/
[root@localhost ~]# firefox http://192.168.20.128/install/index.php