LNMP环境的项目实验
nginx的编译
1.编译nginx的支持包
5.创建程序用户
6.进行编译
echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local
nginx平滑重启命令 /usr/local/nginx/sbin/nginx -s reload
nginx停止服务命令 /usr/local/nginx/sbin/nginx -s stop
第一步,在客户端上ping服务器端IP,命令如下:
ping 10.0.0.8排除物理线路问题影响
第二步,在客户端上telnet服务器端IP,端口,命令如下:
telnet 10.0.0.8 80排除防火墙等得影响
第三步,在客户端使用wget命令检测,如下:
wget 10.0.0.8(curl -I 10.0.0.8)模拟用户访问,排除http服务自身问题,根据输出在排错
cd /usr/local/nginx/conf
egrep -v "#|^$" nginx.conf.default >nginx.conf
worker_processes 1; # CUP几核就配几
events {
worker_connections 1024; #进程内工作的线程个数,工作中一般是20480
}
http { #web模块
include mime.types;
default_type application/octet-stream;
sendfile on; #文件高效传输,默认开的
keepalive_timeout 65; # 连接保持65秒,通常设置是90-180秒
server { # 网站
listen 80; #socket 监听端口是80
server_name localhost; #localhost换成域名
location / { #默认匹配根开始
root html; #网页根目录路径
index index.html index.htm; # 首页
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
1、安装支持包 yum -y install ncurses-devel autoconf
2、首先要下载源码包 :mysql 和 cmake
3、安装支持: cmake
解包: tar xf (cmake包名) -C /usr/src
移动到安装路径: cd /usr/src/cmake包名
4、预配置 : ./configure && gmake && gmake install
5、准备完毕开始安装mysq
6、打开解包后的包名文件目录: cd /usr/src/mysql...
在此目录下开始预配置安装:
cmake -DCMAK_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all && make && make install
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all && make && make install
7、创建程序用户: useradd -Ms /sbin/nologin mysql
8、修改mysql目录的属主和属组
chown -R mysql.root /usr/local/mysql
9、创建修改my.cnf配置文件
10、启动脚本
11、为mysqld加x权限
12、加入开机启动
ln -s /usr/local/mysql/bin/* /usr/local/bin/
14、执行mysql_install_db脚本初始化数据库
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
1、安装支持
yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
yum -y install freetype-devel libpng-devel gd libcurl-devel libxslt-devel
2.安装本地yum源没有的libiconv软件包
cd /usr/src/libiconv-1.14
./configure --prefix=/usr/local/libiconv && make && make install
3.安装完后还有四给包不支持yum安装得rpm安装
rpm -ivh 包名
1.) libmcrypt 2.) mhash 3. )libmcrypt-devel 4.) mcrypt
4.准备完毕开始解压php包
tar xf php-5.3.28.tar.gz -C /usr/src
打开 cd /usr/src/php-5.3.28
./configure \
--prefix=/usr/local/php5.3.28 \
--with-mysql=/usr/local/mysql \
--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-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--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-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp
touch ext/phar/phar.phar
6、make
make最后的正确提示
Build complete.
Don't forget to run 'make test'.
7、make install
8. 配置PHP引擎配置文件php.ini
ln -s /usr/local/php5.3.28/ /usr/local/php
cd /usr/src/php-5.3.28/
cp php.ini-production /usr/local/php/lib/php.ini
9.配置PHP的配置文件php-fpm.conf
cd /usr/src/php-5.3.28/
cp php.ini-production /usr/local/php/lib/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
10、 启动PHP服务
/usr/local/php/sbin/php-fpm
echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local
11、检查PHP服务php-fpm进程及启动端口情况
ps -ef | grep php-fpm
yum -y install lsof
lsof -i:9000
12、 配置Nginx支持PHP程序请求访问
移动到nginx的配置文件 cd /usr/local/nginx/conf/
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
16、对PHP连接MySQL的情况进行测试
vim test_mysql.php
<?php
//$link_id=mysql_connect('主机名','用户','密码');
$link_id=mysql_connect('localhost','root','123123');
if($link_id){
echo "mysql successful by Mr.chen !";
}else{
echo mysql_error();
}
?>
这次测试结果如下
17、部署一个blog程序服务
(1)MySQL配置
mysql -uroot -p123456
create database wordpress;
show databases;
grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456';
flush privileges;
show grants for 'wordpress'@'localhost';
select user,host from mysql.user;
ctrl+D
(2)配置nginx

在首页文件添加一个index.php
添加if语句
/usr/local/nginx/sbin/nginx -s reload
(3)php的环境准备
cd /usr/local/nginx/html/
rm -rf blog/*
cd ~
tar xf wordpress-4.7.4-zh_CN.tar.gz -C /usr/local/nginx/html/blog/
mv wordpress/* .
chown -R nginx.nginx /usr/local/nginx/html/blog/
ls -l
(4)安装博客
在浏览器输入blog.yunjisuan.com



测试成功如下:

浙公网安备 33010602011771号