LNMP服务搭建
一 安装nginx服务
1.安装依赖程序
yum -y install pcre-devel zlib-devel
2.创建nginx管理用户
useradd -M -s /sbin/nologin nginx
3.解压nginx (linux光盘)
4.配置nginx
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --user=nginx
5.编译安装
make && make install
6.优化nginx命令
ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
7.配置Nginx虚拟主机
1)创建虚拟主机网站根目录设置主页
2)修改nginx主配置文件,支持虚拟主机
验证:
二.安装mysql服务
1.安装 依赖程序
yum -y install cmake ncurses-devel
2.创建管理mysql组,将创建的mysql用户加入到组
3.解压mysql (linux光盘)
3.配置mysql
[root@centosmysql-5.5.22]#cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_
COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
4.安装
5.生产mysql主配置文件
cp support-files/my-medium.cnf /etc/my.cnf
6.生产mysql服务控制文件
cp support-files/mysql.server /etc/init.d/mysqld
[root@centos ~]# chmod +x /etc/init.d/mysqld
[root@centos ~]# chkconfig --add mysqld
[root@centos ~]# chkconfig --level 35 mysqld on
7.优化MySQL服务管理命令。
[root@centos ~]# vim /etc/profile
[root@centos ~]# source /etc/profile8.修改所有者为mysql
[root@centos01 ~]# chown -R mysql:mysql /usr/local/mysql/
9.初始化mysql
[root@centos ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/
启动mysqld服务为root用户设置密码
三安装PHP
1.安装php依赖
[root@centos ~]# yum -y install yum -y install gd libxml2-devel libjpeg-devel libpng-devel
2.解压php
[root@centos ~]# tar zxvf /mnt/php-5.3.28.tar.gz -C /usr/src/
3.配置php
[root@centos php-5.3.28]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql
_config --with-config-file-path=/usr/local/php --enable-mbstring --enable-fpm --with-gd --with-zlib --with-jpeg-dir=/usr/libus
4.编译安装
5.生产php配置文件
[root@centos php-5.3.28]# cp php.ini-production /usr/local/php/php.ini
6.优化php命令
7.配置Zend加速
[root@centos php-5.3.x]# cp ZendGuardLoader.so /usr/local/php/lib/php/
zend_extensinotallow=/usr/local/php/lib/php/ZendGuardLoader.so
zend_loader.enable=1
四.配置php-fpm解析php动态语言
- 生成php-fpm主配置文件
[root@centos01 ~]#cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@centos01 ~]# vim /usr/local/php/etc/php-fpm.conf
2.启动php-fpm
[root@centos ~]# php-fpm
五.修改nginx主配置文件连结php协同工作
1.修改nginx主配置文件
}
server {
listen 80;
server_name www.benet.com;
charset uft-8;
access_log logs/www.benet.com.access.log;
location / {
root /var/www/benetcom;
index index.html index.php;
}location ~ \.php$ {
root /www/benetcom;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}}
server {
listen 80;
server_name www.accp.com;
charset uft-8;
access_log logs/www.accp.com.access.log;
location / {
root /var/www/accpcom;
index index.html index.php;
}location ~ \.php$ {
root /www/accpcom;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}}
2.设置php测试页
<?php phpinfo(); ?>
六.部署论坛
1.解压论坛文件
[root@centos ~]# cp /mnt/Discuz_X3.2_SC_UTF8.zip ./
[root@centos ~]# unzip Discuz_X3.2_SC_UTF8.zip
2.剪切项目文件到网站根目录
[root@centos ~]# rm -rf /var/www/benetcom/*
[root@centos upload]# mv ./* /var/www/benetcom/
3.设置目录所有者和权限
[root@centos ~]# chown -R nginx:nginx /var/www/benetcom/
[root@centos ~]# chown -R 755 /var/www/benetcom/
4.创建论坛项目使用的数据库文件
mysql> create database bbs;
mysql> grant all on bbs.* to ‘bbs’@‘localhost’ identified by ‘pwd@123’;
验证:
1.
2.为了安全,把admin.php 改成benet.php