三十八、LNMP潮流组合搭建
一、安装mysql 数据库
1.1 mysql数据库安装的三种方法: 1)编译安装,在lamp经典组合安装是5.1版本,是configure,make,make install,这里如果是5.5版本采用的是cmake安装
2)yum/rpm
3)二进制包,直接压缩解压,初始化数据库即可,无需编译
1.2安装(软件路径和安装路径为:/home/oldboy/tools/mysql-5.5.32-linux2.6-x86_64和/application/mysql/mysql-5.5.32-linux2.6-x86_64)
1)上传,解压软件
rz -y
tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz
2) 因为是二进制文件,将文件直接拷贝到安装目录
mv ./mysql-5.5.32-linux2.6-x86_64 /application/mysql/
3)数据库数据目录授权
chown -R mysql /application/mysql/data/
4) 数据库初始化
/application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql/data --datadir=/application/mysql/data/
5)配置文件放到默认位置
cp ./support-files/my-small.cnf /etc/my.cnf
6)将启动服务文件放到默认位置
/cp ./support-files/mysql.server /etc/init.d/mysqld
7)修改启动命令路径,如下
vim /etc/init.d/mysqld
8)将数据库启动命令进行配置,这里有两种方式
1.添加到PATH变量里面,系统内会自动搜索,例如:/usr/local/sbin下
[root@djw1 mysql]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
2.添加到 /etc/profile下面,末尾添加如下:
9)添加用户名密码
/application/mysql/bin/mysqladmin -u root password 'oldboy124'
10)登录成功:mysql -uroot -p
1.3.优化用户名,只保留127.0.0.1和localhost,删除空用户和::1ipv6用户
mysql 数据库中可以使用 DROP USER 语句来删除一个或多个用户账号以及相关的权限。
优化如下: drop user ""@"localhost"; drop user ""@"::1"; drop user ""@"djw1";
二、安装PHP工具所需要的库
安装php是因为有一些动态数据需要通过PHP程序运行到mysql数据库中,而PHP程序依赖于PHP工具进行编译运行。
2.1检查安装PHP所需lib库,php会调用这些跟图形相关的函数库
yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y
2.2检查安装libiconv字符转换库工具
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
cd ../
2.3 libmcrypt:加密算法扩展库,支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法
tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
sleep 2
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../
2.4 mhash:hash是基于离散数学原理的不可逆向的php加密方式扩展库,其在默认情况下不开启。mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存(如密码)等
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
make
make install
cd ../
rm -f /usr/lib64/libmhash.*
ln -s /usr/local/lib64/libmcrypt.la /usr/lib64/libmcrypt.la
ln -s /usr/local/lib64/libmcrypt.so /usr/lib64/libmcrypt.so
ln -s /usr/local/lib64/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
ln -s /usr/local/lib64/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
ln -s /usr/local/lib64/libmhash.a /usr/lib64/libmhash.a
ln -s /usr/local/lib64/libmhash.la /usr/lib64/libmhash.la
ln -s /usr/local/lib64/libmhash.so /usr/lib64/libmhash.so
ln -s /usr/local/lib64/libmhash.so.2 /usr/lib64/libmhash.so.2
ln -s /usr/local/lib64/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure LD_LIBRARY_PATH=/usr/local/lib
make
make install
cd ../
cd php-5.3.27
--with-mysql=/application/mysql \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib/
![](https://img2018.cnblogs.com/blog/1586308/201908/1586308-20190806193424735-2006624842.png)
注意:启动php-fpm进程前,一定要启动nginx进程,查看php-fpm进程初始化如下:
启动成功!启动命令为 :/application/php/sbin/php-fpm -t \/application/php/sbin/php-fpm
五、php整合nginx,在nginx中添加如下内容:
1)配置参数
server {
listen 80;
server_name bbs.etiantian.org;
root html/bbs;
index index.php index.html index.htm;
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
2)写入站点连接数据库
[root@djw1 bbs]# cat ../../html/bbs/mysql.php
<?php
$link_id=mysql_connect('localhost','root','oldboy124') or mysql_error();
if($link_id){
echo "mysql successful by oldboy !\n";
}else{
echo mysql_error();
}
?>
3)测试
1.直接用php引擎: /application/php/bin/php mysql.php
2.页面测试:
六、安装部署开源软件wiki测试:
1.数据库:
create database wiki;
grant all on wiki.* to wiki@'localhost' identified by 'wiki';\
flush privileges;
2.下载开源软件:kaiyuan.baike.com ,复制链接后,wget下载;将软件解压,复制到上述配置好的bbs目录下,nginx会进行首页index.php读取
3.进入首页后,根据提示,导入数据库,输入必要的配置参数,就可以看到了,如下