rz 包 阅读源码包16,和nginx包
##nginx安装
##首先搭建Nginx详解看nginx
#gcc gcc-c++ make
mount /dev/sr0 /media/cdrom
yum -y install pcre-devel openssl-devel
tar xf nginx-1.10.2.tar.gz -C /usr/src
cd /usr/src/nginx-1.10.2/
##一个服务器搭建,nginx和php程序用户要相同
useradd -M -s /sbin/nologin lnmp
./configure --user=lnmp --group=lnmp --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
ln -s /usr/local/nginx/sbin/* /usr/local/sbin
cd /usr/local/nginx/conf/
egrep -v "#|^$" nginx.conf.default > nginx.conf
[root@moban6 yuanma]# du -sh mysql-5.5.32-linux2.6-x86_64.tar.gz
179M mysql-5.5.32-linux2.6-x86_64.tar.gz
#二进制包直接解压
[root@moban6 yuanma]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /usr/local
#创建用户
[root@moban6 yuanma]# useradd -s /sbin/nologin -M mysql
#做配置文件
[root@moban6 yuanma]# cd /usr/local/mysql-5.5.32-linux2.6-x86_64/
[root@moban6 mysql-5.5.32-linux2.6-x86_64]# /bin/cp support-files/my-small.cnf /etc/my.cnf
#做本机映射,否则有时候会出错
[root@moban6 mysql-5.5.32-linux2.6-x86_64]# echo "192.168.200.143 lnmp" >> /etc/hosts
#做个软连接,因为目录太长
[root@moban6 mysql-5.5.32-linux2.6-x86_64]# ln -s /usr/local/mysql-5.5.32-linux2.6-x86_64 /usr/local/mysql
#授权属主
[root@moban6 mysql]# chown -R mysql.mysql /usr/local/mysql
#安装支持包否则下一步初始化会出错
[root@moban6 mysql]# yum -y install libaio
#数据初始化
[root@moban6 mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#做启动文件
[root@moban6 mysql]# /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@moban6 mysql]# chmod +x /etc/init.d/mysqld
[root@moban6 mysql]# /etc/init.d/mysqld start
#软连接
[root@moban6 mysql]# ln -s /usr/local/mysql/bin/* /usr/local/bin
#给mysql的root设置密码
[root@moban6 mysql]# mysqladmin -uroot password '123123'
#安装php支持包
[root@moban6 mysql]# yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd libcurl-devel libxslt-devel
#发现少一个包,默认光盘源没有,但是rz 都有
#wget安装
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
[root@moban6 mysql]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
zlib-devel-1.2.3-29.el6.x86_64
libxml2-devel-2.7.6-14.el6.x86_64
libjpeg-turbo-devel-1.2.1-1.el6.x86_64
[root@moban6 ~]# cd /root/yuanma
[root@moban6 yuanma]# tar xf libiconv-1.14.tar.gz -C /usr/src
[root@moban6 yuanma]# cd /usr/src/libiconv-1.14/
[root@moban6 yuanma]# ./configure --prefix=/usr/local/libiconv && make && make install
#安装其他的库,在/root/rpm 安装的时候先过一圈,然后再过一圈,因为有依赖
[root@moban6 ~]# cd /root/rpm/
[root@moban6 rpm]# rpm -ihv libmcrypt-2.5.8-9.el6.x86_64.rpm
[root@moban6 rpm]# rpm -ihv libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
[root@moban6 rpm]# rpm -ihv mhash-0.9.9.9-3.el6.x86_64.rpm
[root@moban6 rpm]# rpm -ihv mcrypt-2.6.8-10.el6.x86_64.rpm
[root@moban6 yuanma]# cd /root/yuanma/
[root@moban6 yuanma]# tar xf php-5.3.28.tar.gz -C /usr/src
[root@moban6 yuanma]# cd /usr/src/php-5.3.28/
[root@moban6 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=lnmp --with-fpm-group=lnmp --enable-ftp
#解释最后的用户名要和nginx创建的相同,因为在同一个服务器里
##--with-mysql=/usr/local/mysql,需要指定MySQL的安装路径,如果没有则--with-mysql=mysqlnd代替。因为PHP软件里自带连接了MySQL的客户端工具
##如果报错,报错信息有包名,就yum安装试试 包名-devel
#创建个文件
[root@moban6 php-5.3.28]# touch ext/phar/phar.phar
[root@moban6 php-5.3.28]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64
#上两步,分离式不用写
[root@moban6 php-5.3.28]# make
# Build complete.
# Don't forget to run 'make test'.
#看到上面的话,代表成功
[root@moban6 php-5.3.28]# make install
#软连接
[root@moban6 php-5.3.28]# ln -s /usr/local/php5.3.28/ /usr/local/php
#查看PHP默认配置模板
[root@moban6 php-5.3.28]# ls php.ini*
#测试的(关了很多特效)和生产的
php.ini-development php.ini-production
#使用生产的,拷贝PHP配置文件到PHP默认目录,改名为php.ini
[root@moban6 php-5.3.28]# cp php.ini-production /usr/local/php/lib/php.ini
#配置PHP(FastCGI方式)的配置文件php-fpm.conf
[root@moban6 php-5.3.28]# cd /usr/local/php/etc/
[root@moban6 etc]# cp php-fpm.conf.default php-fpm.conf
#启动服务(FastCGI方式)
[root@moban6 etc]# /usr/local/php/sbin/php-fpm
[root@moban6 etc]# ss -antup |grep 9000
tcp LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",128684,7),("php-fpm",128685,0),("php-fpm",128686,0))
#上面 监听127.0.0.1:9000 本地的9000,因为在同一台服务器,如果不在同一台,则监听ip地址
[root@moban6 etc]# vim php-fpm.conf
151 listen = 127.0.0.1:9000
#软连接 2个
[root@moban6 blog]# ln -s /usr/local/php/bin/* /usr/local/bin/
[root@moban6 blog]# ln -s /usr/local/php/sbin/* /usr/local/sbin/
[root@moban6 nginx]# cd /usr/local/nginx/conf/
[root@moban6 conf]# vim nginx.conf
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name blog.yunjisuan.com;
location / {
root html/blog;
index index.html index.htm;
}
location ~.*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
#检查并启动Nginx
[root@moban6 conf]# /usr/local/nginx/sbin/nginx -t
[root@moban6 html]# cd /usr/local/nginx/html/
[root@moban6 html]# mkdir blog
[root@moban6 html]# echo "blog" > blog/index.html
[root@moban6 logs]# /usr/local/nginx/sbin/nginx
[root@moban6 blog]# echo "192.168.200.143 blog.yunjisuan.com" >> /etc/hosts
第一步:
Nginx: Web服务器所用到的目录 要改属组,必须属于程序用户,为了PHP使用
MySQL:没变化
PHP:编译安装时:--with-mysql=/usr/local/mysql ===>> 改为 --with-mysql=mysqlnd
创建程序用户,并且必须和Nginx的程序用户相同
编译完,不需要 touch ext/phar/phar.phar
和 ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64
直接 make && make install
中间一样。。。直到修改配置文件端口
[root@moban6 etc]# vim php-fpm.conf
151 listen = 192.168.299.145:9000
第二步
然后修改Nginx配置文件 实验推送
然后重启服务
第三步:php服务器按照nginx的目录,创建目录,并改属主.
宿主机测试php
宿主机映射
[root@moban6 blog]# vim test_info.php
[root@moban6 blog]# cat test_info.php
看内容(从编辑地方看)
宿主机测试mysql
[root@moban6 blog]# vim test_mysql.php
[root@moban6 blog]# cat test_mysql.php
执行下面命令测试,成功了
[root@moban6 blog]# php test_mysql.php
mysql successful by wanghaiyang
#数据库部署
[root@moban6 blog]# mysql -uroot -p123123
#创建wordpress库
mysql> create database wordpress;
#创建用户名,localhost为客户端地址,是php端IP地址
mysql> grant all on wordpress.* to 'wordpress'@'localhost' identified by '123123';
mysql> flush privileges;
mysql> exit
#补充一个首页文件index.php
[root@moban6 nginx]# cd /usr/local/nginx/conf/
[root@moban6 conf]# vim nginx.conf
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name blog.yunjiusan.com;
location / {
root html/blog;
index index.php index.html index.htm;
}
location ~.*\.(php|php5)?${
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
[root@moban6 blog]# /usr/local/nginx/sbin/nginx -s reload
[root@moban6 blog]# cd /root/yuanma
#解压博客包到当前,nginx端解压缩执行下面命令
[root@moban6 yuanma]# tar xf wordpress-4.7.4-zh_CN.tar.gz
#下面是为了把wordpress包内容放在blog里,为了实验,配合上面的nginx.conf配置文件部署
[root@moban6 html]# cd /usr/local/nginx/html/blog/
[root@moban6 blog]# rm -rf *
[root@moban6 blog]# mv ~/yuanma/wordpress/* .
#程序用户执行,特别是分离式部署,必须程序用户权限
[root@moban6 blog]# chown -R lnmp.lnmp /usr/local/nginx/html/blog
#动态改静态的配置改动
#增加了三个if语句
[root@moban6 blog]# cat /usr/local/nginx/conf/nginx.conf
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name blog.yunjiusan.com;
location / {
root html/blog;
index index.php index.html index.htm;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php) {
rewrite (.*) $1/index.php;
}
if (!-f $request_filename) {
rewrite (.*) /index.php;
}
}
location ~.*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
[root@moban6 blog]# /usr/local/nginx/sbin/nginx -s reload