源码包安装使用

---------------------------------------------------------------------------------------

1)先安装

2)安装后:命令搜索路径#$PATH,做链接ln -s ,复制启动脚本或自己写用shell。

---------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------

有时装源码包时 没装成功 要会看报错 解决  下面这个是缺少了依赖包问题

--------------------------------------------------------------------------------------

./configure 

Error xml2... library  (报错 可能少了库文件)



yum list |grep xml2 (查询依赖包)

yum -y install *xml2*

---------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------

mysql源码包安装  (3306端口)

----------------------------------------------------------------------------------------

1.安装软件

  依赖包

  创建用户

  解密

 cmake

 make  &&make install


2.初始化数据库


/usr/local/mysql/scripts/mysql_install_db(脚本)   ---user=mysql --

datadir=/usr/local/mysql/data/    (如果报错找不到数据库 告诉它 --basedir=/usr/local/mysql/data/

注释:该脚本为perl脚本,需要有perl

使用的用户是:mysql

该脚本将自动生成MySQL所需要的基本数据库



3.复制启动脚本(安装后操作)


#ls -l /usr/local/mysql/data

#chown -R root.mysql /usr/local/mysql

#chown -R mysql.mysql /usr/local/mysql/data



# ln -s /usr/local/mysql/bin/*    /usr/bin/

#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

#cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf


4.启动mysql服务:

#service mysqld start

Starting MySQL.. SUCCESS! 


----------------------------------------------------------------------

LNMP(Linux,Nginx,MySQL,PHP)

---------------------------------------------------------------------


1.安装Nginx

#yum -y install gcc

#yum -y install zlib-devel

#yum -y install openssl-devel

#tar -xf nginx-1.8.0.tar.gz

#cd nginx-1.8.0

#./configure --with-http_ssl_module

#make && make install


#ln -s /usr/local/nginx/sbin/nginx /usr/sbin/


2.安装MySQL

#yum -y install cmake

#yum -y install gcc gcc-c++

#yum -y install ncurses-devel

#yum -y install perl

#useradd -s /sbin/nologin mysql

#tar -xf mysql-5.6.25.tar.gz

#cd mysql-5.6.25

#cmake .

#make && make install

#ls /usr/local/mysql   校验


默认MySQL数据库位置:

/usr/local/mysql/data  #默认为空


3.初始化数据库

/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/

注释:该脚本为perl脚本,需要有perl

该脚本将自动生成MySQL所需要的基本数据库


#ls -l /usr/local/mysql/data

#chown -R root.mysql /usr/local/mysql

#chown -R mysql.mysql /usr/local/mysql/data


4.复制启动脚本

#vim /etc/ld.so.conf (库文件的配置文件)

/usr/local/mysql/lib

#ldconfig   //将mysql库文件添加到系统搜索路径

#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

#cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf (mysql主配置文件)

#service mysqld start

---------------------------------------------------------------------

[root@proex ~]# mysql     


mysql> show databases;      /查看数据库

+--------------------+ 

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.05 sec)



mysql> use mysql;    进入数据库

Database changed

mysql> show tables;  查看数据表

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| columns_priv              |

| db                        |

| event                     |

| func                      |

| general_log               |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| innodb_index_stats        |

| innodb_table_stats        |

| ndb_binlog_index          |

| plugin                    |

| proc                      |

| procs_priv                |

| proxies_priv              |

| servers                   |

| slave_master_info         |

| slave_relay_log_info      |

| slave_worker_info         |

| slow_log                  |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

+---------------------------+

28 rows in set (0.00 sec)


mysql>select * from user\G;

 

数据库  相当于excel 工作薄

数据表   excel  表1


mysql数据库服务器

数据库---》数据表---》数据

工作簿--->表----->数据


++++++++++++++++++++++++++++

#mysql

mysql> show databases; //查看数据库

mysql>use mysql;   //进入数据库

mysql>show tables;  //查看数据表

mysql>select * from user\G;



#mysqladmin -u root password '123'

#mysql  //失败

#mysql -u root -p123

mysql>create database  mydb;

mysql>use mydb;

mysql>create table t1 (name char(10), age int(3));

mysql> describe t1;

mysql> select * from t1;

mysql> insert into t1 values("tom",18);

mysql>show databases;

mysql>exit


--------------------------------------------------------------------------------------

 PHP 源码包安装 (9000端口)

--------------------------------------------------------------------------------------            


先安装2个依赖包mcrypt,mhash(装这两个依赖包也是从官网上下下来安装,也是按源码包安装,可以看官网提示操作)


#vim /etc/ld.so.conf

/usr/local/lib/

#ldconfig    //刷新库文件

#ldconfig -v |grep mhash  //查看系统是否能找到库文件


#tar -zxvf php-5.4.9.tar.gz

# cd php-5.4.9

# ./configure \

--prefix=/usr/local/php5 \

安装路径

--with-mysql=/usr/local/mysql\

制定MySQL位置

--enable-fpm \

安装PHP-fpm服务###必须要设置

--enable-mbstring \

#多字节字符[汉字支持]

--with-mcrypt  --with-mhash

启用加密和hash功能

--with-config-file-path=/usr/local/php5/etc\

制定PHP的配置文件存放路径

--with-mysqli=/usr/local/mysql/bin/mysql_config

制定MySQL位置,mysql_config

#make

#make install

#cp  php.ini-production /usr/local/php5/etc/php.ini (PHP主配置文件)

#cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf (php-fpm解释器配置文件)


复制启动脚本:

#cd lnmp_soft/php-5.4.24/sapi/fpm

#cp init.d.php-fpm /etc/init.d/php-fpm  (启动脚本)

#chmod +x /etc/init.d/php-fpm

#service php-fpm start

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

默认监听127.0.0.1:9000端口


库文件《===》依赖《==》函数《====》类

库.so

1.安装依赖,可用使用yum

  优势,他的so库文件会放在合适的地方

  系统可以自动搜索到该文件


2.源码安装,默认安装/usr/local/

  系统无法识别到该库文件

注意:此时,需要管理员将so文件,手动做链接放到/lib64,/lib,/usr/lib

     #vim /etc/ld.so.conf (库文件的配置文件)

       /usr/local/lib/

    #ldconfig -v (显示所有目前识别的库文件)

    #ldconfig    (//刷新)

      该文件一个路径为一行,计算机会自动搜索你给定所有路径(做了链接就不用改库文件配置文件,做一个就可)


修改PHP配置文件

进程数量

PHP每个进程大于占用25M内存

#vim /usr/local/php5/etc/php-fpm.conf

listen = 127.0.0.1:9000

pm = dynamic   动态调整进程

pm.max_children = 64   最大进程

pm.start_servers = 32   最小进程

pm.min_spare_servers = 15  最小空闲

pm.max_spare_servers = 64  最大空闲

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

[root@proxe etc]# netstat -anptu |grep nginx

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      5769/nginx

[root@proex init.d]# netstat -anptu |grep :9000

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      16582/php-fpm       

[root@proex init.d]# netstat -anptu |grep :80

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      13254/nginx         

[root@proex init.d]# netstat -anptu |grep :3306

tcp        0      0 :::3306                     :::*                        LISTEN      8360/mysqld         



1.设置nginx(实现动静分离)

 如果用户访问静态页面,nginx直接給用户

 如果用户访问动态页面,nginx转发給9000,9000把执行结果反馈給nginx,nginx转发给用户


nginx代理服务器:

实验步骤:

1.把nginx和php启动

    #nginx 

    #service php-fpm restart

    #server mysqld start


2.Nginx连接PHP

vim /usr/local/nginx/conf/nginx.conf


... ...

http{

     server {

       listen 80;

       server_name localhost;

     location / {

           root html;

           index index.html;

     }

    }

  location ~ \.php$ {

     root  html;

     fastcgi_pass 127.0.0.1:9000;

     fastcgi_index  index.php;

     include        fastcgi.conf;

    }


}

.........


#nginx -s reload


3.准备静态动态页面并测试:(静态页面之前有)

(写的第一个动态页面)

#vim /usr/local/nginx/html/abc.php

<?php

phpinfo();

?>


4.测试:(nginx代理服务器或客户机host测试都行)

#firefox http://192.168.4.5 (静态页面,之前有一个./html/index.html静态页面)浏览器自动解释打开。

#firefox http://192.168.4.5/abc.php(第一个动态页面测试)nginx转发給9000,9000把执行结果反馈給nginx,nginx转发给浏览器打开。


++++++++++++++++++++++++++++++

写的第二个动态页面 (密码如果之前创建了就写  没创建就是‘ ’)

#vim /usr/local/nginx/html/abc.php

<?php

$link = mysql_connect ( 'localhost','root', '123' );

if (! $link ) {

    die( 'Could not connect: '.mysql_error ());

}

$sql  =  'CREATE DATABASE my_db';

if ( mysql_query ( $sql ,  $link )) {

    echo  "Database my_db created successfully\n" ;

} else {

    echo  'Error creating database: '  .  mysql_error () .  "\n" ;

}

?>



#firefox http://192.168.4.5/abc.php  (一连接就会创建一个数据库,不改动情况下再连接就会报错,这个测试创

建数据库可以是用户测试创建,也可管理员进入mysql创建,但一般不会写这样的代码給用户在前台连接创建)


[root@proxe html]# /usr/local/php5/bin/php abc.php (开发的人直接这样验证结果,用命令测试)

TTT


---------------------------------


(nginx代理服因为mysql装在这)查看效果:

#mysql   root -p123

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| my_db              |

| mydb               |

| mysql              |

| performance_schema |

| test               |

+--------------------+

6 rows in set (0.00 sec)


mysql> 


++++++++++++++++++++++++++++++++++++++++++++++++++++++++


PHP <----> MySQL

PHP使用代码取连接MySQL


#vim /usr/local/nginx/html/abc.php


<?php

$links=mysql_connect("localhost","root","root密码");

if($links){

echo "link db ok!!!";

}

else{

echo "link db no!!!";

}

?>

#firefox http://192.168.4.5/abc.php


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


地址重写


rewrite  正则 修改后的地址 【选项】


【nginx代理服务器】

1.当用户访问a,html----->b.html


     server {

       listen 80;

       server_name localhost;

     location / {

           root html;

           index index.html;

     rewrite a.html  /b.html;

     }


[root@proxe lnmp_soft]# echo "hello" >/usr/local/nginx/html/b.html  (原本a.html有没有都没关系,这里只创一个b.html)

[root@proxe lnmp_soft]# nginx -s reload


测试【客户机】

[root@host ~]# firefox http://192.168.4.5/a.html (OK)   (原本没有a.html,现在打开了b.html,地址转换了)

[root@host ~]# curl  http://192.168.4.5/a.html   (OK)

hello



反过来实验下:


 然后我在把rewrite 注释掉。

    server {

       listen 80;

       server_name localhost;

     location / {

           root html;

           index index.html;

   #  rewrite a.html  /b.html;

     }


[root@proxe lnmp_soft]# nginx -s reload


[root@host ~]# firefox http://192.168.4.5/a.html (报错 404找不到,因为根本没有a.html)

[root@host ~]# curl  http://192.168.4.5/a.html   (报错)


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


www.360buy.com ----www.jd.com


  server {

       listen 80;

       server_name www.360buy.com;

     location / {

           root html;

           index index.html;

     rewrite ^/    http://www.jd.com;

     }


 server {

       listen 80;

       server_name www.360buy.com;

     location / {

           root html;

           index index.html;

     rewrite ^/    http://www.jd.com/abc.html; (跳到子页面)

     }


www.360buy.com/phone/iphone.html --------->http://www.jd.com/phone/iphone.html

用正则:


server {

       listen 80;

       server_name www.360buy.com;

     location / {

           root html;

           index index.html;

     rewrite ^/(.*)    http://www.jd.com/$1;

     }



+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


firefox  /html/test.html


uc       /html/uc/test.html


if ($http_user_agent  ~ uc)

     rewrite /(.*)   /html/uc/$1;



fire fox http://192.168.4.5/test.html

   

uc   http://192.168.4.5/test.html


http://192.168.4.5/uc/test.html   

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


    location / {

            root   html;

            index  index.html index.htm;

       #      rewrite a.html /b.html;

        }

          if (!-e $request_filename){

       rewrite   ^/   http://192.168.4.5/a.html;

       }


[root@proxe lnmp_soft]# echo "HAHA0" >/usr/local/nginx/html/a.html

[root@proxe lnmp_soft]# nginx -s reload


[root@host ~]# firefox http://192.168.4.5/sdda   (用浏览器测试 打开的额是a.html网页)

[root@host ~]# firefox http://192.168.4.5/sadfaf  (用浏览器测试 打开的额是a.html网页)


[root@host ~]# curl http://192.168.4.5/sd   (用命令没测试出来)

<html> 

<head><title>302 Found</title></head>

<body bgcolor="white">

<center><h1>302 Found</h1></center>

<hr><center>nginx/1.8.0</center>

</body>

</html>



  location / {

            root   html;

            index  index.html index.htm;

       #      rewrite a.html /b.html;

        }

          if (!-e $request_filename){

       rewrite   ^/   http://192.168.4.5/a.html  redirect;

       }


[root@host ~]# firefox http://192.168.4.5/sdda   (用浏览器测试 打开的额是a.html网页,且地址栏中的有改变,

输得是/http://192.168.4.5/sdda 转成http://192.168.4.5/a.html))


++++++++++++++++++++++++++++++++


#vim /usr/local/nginx/conf/nginx.conf

... 

server {

   listen 80;

   server_name localhost;

  location / { .... ....}

if ($http_usert ~_agen* curl){

  rewrite /(.*)  /curl/$1;

}

}

#cd /usr/local/nginx/html

#echo "正常" > test.html

#mkdir curl

#echo "curl" > curl/test.html

#nginx -s reload


#firefox http://192.168.4.5/test.html

#curl http://192.168.4.5/test.html


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


将p_w_picpath目录下资源转重定向到picture目录下

rewriter /p_w_picpath/(.*) /picture/$1


rewrite a.html  /c.html last;

rewrite a.html  /c.html  break;(结束,不再读下面的rewrite)


rewrite  a.html /c.html redirect;

 

rewrite  a.html  /c.html  permanent;


做网站:

UI,前端开发,后端开发,运维

画草图,HMTL+div+css+javascript

PHP,java,python,shell,C

上线:服务器(平台)LAMP LNMP LTMJ (tomcat+java)

后期维护


Nginx地址重写

rewrite 正则  转换后的URL [选项]


#vim /usr/local/nginx/conf/nginx.conf

.. ...

http{

     server {

       listen 80;

server_name localhost;

location / {

             root html;

    index index.html;

  rewrite a.html /b.html;

       }

    }

}

#cd /usr/local/nginx/html

#echo "woshi BB" > b.html

#nginx -s reload

#firefox http://192.168.4.5/a.html


案例2:

#vim /usr/local/nginx/conf/nginx.conf

... ...

server {

   listen 80;

   server_name localhost;

   location / {

     rewrite ^/  http://www.baidu.com;

   .... ...

   }

  }

#nginx -s reload



案例3:

#vim /usr/local/nginx/conf/nginx.conf

... 

server {

   listen 80;

   server_name localhost;

  location / { .... ....}

if ($http_user_agent ~* curl){

  rewrite /(.*)  /curl/$1;

}

}

#cd /usr/local/nginx/html

#echo "正常" > test.html

#mkdir curl

#echo "curl" > curl/test.html

#nginx -s reload


#firefox http://192.168.2.100/test.html

#curl http://192.168.2.100/test.html



+++++++++++++++++++++++++++++++


rewrite 语法格式

rewrite 旧URI  新URI [选项];

选项可用是:

last 不再读取其他的rewrite

break  不再读取其他的rewrite,结束请求

permanent 永久重定向,地址栏改变

redirect  临时重定向,地址栏改变

 

1.nginx【配置,虚拟主机】

2.nginx【用户,密码,HTTPS】

3.nginx+PHP+MySQL

4.nginx【地址重写rewrite]

5.nginx优化[nginx.conf]



location ~* \.(jpg|flv|rm){

      expires 30d;

}

#nginx -s reload

#find / -name "*.jpg"


firefox   about:cache  清空历史