实验环境:rhel6.5
实验主机:server1 172.25.70.1
一、mysql源码安装
1.安装编译mysql的cmake工具
所需软件包:cmake-2.8.12.2-4.el6.x86_64.rpm
[root@server1 ~]# yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y
2.安装mysql源码包
所需软件包:mysql-boost-5.7.11.tar.gz
[root@server1 ~]# tar -zxf mysql-boost-5.7.11.tar.gz
检查编译环境
[root@server1 ~]# cd mysql-5.7.11/
[root@server1 mysql-5.7.11]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=/root/mysql-5.7.11/boost/boost_1_59_0/
出现下面报错,需要删除CMakeCache.txt缓存
执行
[root@server1 mysql-5.7.11]# rm -rf remove CMakeCache.txt
在检查过程中,需要安装下面依赖包
[root@server1 mysql-5.7.11]# yum install -y gcc gcc-c++ make ncurses-devel bison openssl-devel zlib-devel
[root@server1 mysql-5.7.11]# make && make install
3.mysql的配置
[root@server1 ~]# vim /etc/my.cnf #更改mysql的data路径和sock路径
datadir=/usr/local/lnmp/mysql/data
socket=/usr/local/lnmp/mysql/data/mysql.sock
[root@server1 ~]# vim ~/.bash_profile #指定位置到全局变量中
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
[root@server1 ~]# source ~/.bash_profile #重新生效
创建mysql用户
[root@server1 ~]# groupadd -g 27 mysql
[root@server1 ~]# useradd -u 27 -g 27 -s /sbin/nologin -M -d /usr/local/lnmp/mysql/ mysql
[root@server1 ~]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
初始化之前更改/usr/local/lnmp/mysql/下所有文件的所属用户和所属组为mysql
[root@server1 mysql]# cd /usr/local/lnmp/mysql/
[root@server1 mysql]# chown mysql:mysql . -R
[root@server1 mysql]# ll #更改至如下
total 56
drwxr-xr-x 2 mysql mysql 4096 Feb 23 16:20 bin
-rw-r--r-- 1 mysql mysql 17987 Feb 2 2016 COPYING
drwxr-xr-x 2 mysql mysql 4096 Feb 23 16:19 docs
drwxr-xr-x 3 mysql mysql 4096 Feb 23 16:19 include
drwxr-xr-x 4 mysql mysql 4096 Feb 23 16:20 lib
drwxr-xr-x 4 mysql mysql 4096 Feb 23 16:19 man
drwxr-xr-x 10 mysql mysql 4096 Feb 23 16:21 mysql-test
-rw-r--r-- 1 mysql mysql 2478 Feb 2 2016 README
drwxr-xr-x 28 mysql mysql 4096 Feb 23 16:21 share
drwxr-xr-x 2 mysql mysql 4096 Feb 23 16:21 support-files
将启动脚本移到特定位置
[root@server1 mysql]# cd support-files/
[root@server1 support-files]# ls
magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld
[root@server1 support-files]# chmod +x /etc/init.d/mysqld
mysql的初始化
[root@server1 support-files]# mysqld --initialize --user=mysql
初始化密码待用
更改/usr/local/lnmp/mysql下的文件的所属用户为root(除了data目录下的所有文件)
[root@server1 mysql]# chown root . -R
[root@server1 mysql]# chown mysql data/ -R
[root@server1 mysql]# ll #更改至如下
total 60
drwxr-xr-x 2 root mysql 4096 Feb 23 16:20 bin
-rw-r--r-- 1 root mysql 17987 Feb 2 2016 COPYING
drwxr-x--- 5 mysql mysql 4096 Feb 23 17:01 data
drwxr-xr-x 2 root mysql 4096 Feb 23 16:19 docs
drwxr-xr-x 3 root mysql 4096 Feb 23 16:19 include
drwxr-xr-x 4 root mysql 4096 Feb 23 16:20 lib
drwxr-xr-x 4 root mysql 4096 Feb 23 16:19 man
drwxr-xr-x 10 root mysql 4096 Feb 23 16:21 mysql-test
-rw-r--r-- 1 root mysql 2478 Feb 2 2016 README
drwxr-xr-x 28 root mysql 4096 Feb 23 16:21 share
drwxr-xr-x 2 root mysql 4096 Feb 23 16:21 support-files
启动服务
[root@server1 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
由于初始化密码不好记,我们可以更改密码(需要用到前面保存的初始化密码)
[root@server1 mysql]# mysql_secure_installation
二、php源码安装
所需软件包:libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm gd-devel-2.0.35-11.el6.x86_64.rpm php-5.6.20.tar.bz2
1.安装编译环境所需要的依赖包
yum install curl-devel openssl-devel libxml2-devel libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm gd-devel-2.0.35-11.el6.x86_64.rpm gmp-devel bison net-snmp-devel -y
2.对php包进行解包,在检查通过后,源码安装
解包
tar jxf php-5.6.20.tar.bz2
检查编译环境
[root@server1 php-5.6.20]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
[root@server1 local]# useradd -u 800 -M -d /usr/local/lnmp/php -s /sbin/nologin nginx #-M表示不要自动建立用户的登入目录 -d用来指定nginx用户的主目录 -s用来指定nginx的用户登录shell
[root@server1 local]# id nginx
uid=800(nginx) gid=800(nginx) groups=800(nginx)
编译和安装
[root@server1 php-5.6.20]# make && make install
3.对php配置文件的修改
将配置文件放在指定位置
[root@server1 php-5.6.20]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# ls
pear.conf php-fpm.conf.default
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]# cd /root/php-5.6.20
[root@server1 php-5.6.20]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 php-5.6.20]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@server1 etc]# vim php.ini #更改时区
[root@server1 etc]# vim php-fpm.conf
加服务的启动脚本放到/etc/init.d/下,并加上x权限
[root@server1 ~]# cd php-5.6.20/sapi/fpm/
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm
将php的路径添加到环境变量中
[root@server1 fpm]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin
[root@server1 ~]# source ~/.bash_profile #重新生效
启动服务
[root@server1 bin]# /etc/init.d/php-fpm start
Starting php-fpm done
[root@server1 bin]# netstat -antlpe | grep 9000 #查看改服务的端口
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 0 111018 20722/php-fpm
三、nginx源码安装和配置
1.安装
所需软件包:nginx-1.10.1.tar.gz
[root@server1 ~]# tar -zxf nginx-1.10.1.tar.gz
[root@server1 ~]# cd nginx-1.10.1
[root@server1 nginx-1.10.1]# vim src/core/nginx.h #去掉版本号
[root@server1 nginx-1.10.1]# vim auto/cc/gcc #关闭gcc编译
在编译检查过程中检查到需要依赖包pcre-devel openssl-devel zlib-devel
yum install pcre-devel openssl-devel zlib-devel -y
编译环境的检查
[root@server1 nginx-1.10.1]# ./configure --prefix=/usr/local/lnmp/nginx/ --with-http_stub_status_module --with-http_ssl_module --user=nginx --group=nginx
[root@server1 nginx-1.10.1]# make && make install
安装成功后,组启动服务的软链接
[root@server1 ~]# ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/
[root@server1 ~]# nginx #启动服务
2.配置nginx服务
[root@server1 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf
配置默认发布文件为index.php
修改include为 fastcgi.conf
[root@server1 ~]# vim /usr/local/lnmp/nginx/html/index.php #编辑index.php页面
phpinfo()
?>
[root@server1 ~]# vim /usr/local/lnmp/php/etc/php.ini #添加mysql.sock文件位置
[root@server1 ~]# nginx -s reload
在客户机上测试index.php页面,显示正常
四、论坛Discuz的搭建
所需材料:Discuz_X3.2_SC_UTF8.zip
1.解Discuz论坛包
[root@server1 ~]# unzip Discuz_X3.2_SC_UTF8.zip
将upload移到nginx的html发布目录里
[root@server1 ~]# mv upload/ /usr/local/lnmp/nginx/html/
2.配置Discuz论坛包
在浏览器上
点击“我同意“
由于权限问题,出现不可写入的报错
[root@server1 ~]# cd /usr/local/lnmp/nginx/html/upload
[root@server1 upload]# chmod 777 config/ data/ uc_client/ uc_server/ -R #更改这些目录下的所有为满权限
刷新重试
出现数据库连接错误,属于权限问题,将数据库的data目录权限修改为775
[root@server1 ~]# chmod 755 /usr/local/lnmp/mysql/data/