LNMP ---》源码包装nginx mysql5.6 php
1.安装mysql
#先解开mysql5.6源码包
#tar -zxf mysql-5.6.25.tar.gz
#cd mysql-5.6.25/
#useradd mysql
#yum -y install cmake gcc
#yum install gcc-c++
# yum -y install ncurses-devel
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all
#make &&make install
#cd /usr/local/mysql/
#./scripts/mysql_install_db --datadir=/usr/local/mysql/data/ --user=mysql (初始化数据库)
#ls /usr/local/mysql/data/
#ls -l /usr/local/mysql/data/mysql
复制主配置文件启动脚本:
#ls support-files/
#cp support-files/my-default.cnf /etc/my.cnf
#cp support-files/mysql.server /etc/init.d/mysql
#chmod +x /etc/init.d/mysql
#chkcpmfig --add mysql (添加为系统服务)
#chkconfig --list mysql
#chkconfig mysql on
#service mysql status
#netstat -anptu |grep :3306
#service mysql start
#ln -s /usr/local/mysql/* /bin 把命令的路径添加到path变量里
#echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
#source /etc/profile
#echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
#mysql -uroot -p
mysql>quit
设置数据库管理员从本机登录的密码
#mysqladmin -hlocalhost -uroot password "123456" 这是设置密码
#mysql -uroot -p123456
mysql>quit
修改密码
# mysqladmin -hlocalhost -uroot -p password "11" (新密码)
Enter password: (这填旧密码)
#mysql -uroot -p11
#vim /etc/ls.so.conf (库文件连接 系统启动会读这个文件,会加载程序的库文件,第三方软件就能找到mysql库文件位置)
/usr/local/mysql/lib/
#ldconfig -v |grep -i --color mysql
2.安装PHP
安装PHP 先安装扩展包
libmcrypt-2.5.8.tar.gz
mhash-0.9.9.9.tar.gz
# tar zxf mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9/
# ./configure
# make &&make install
# tar -zxf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8/
# ./configure
# make &&make install
把库文件更新到系统默认搜索的目录下
# ln -s /usr/local/lib/libmcrypt* /usr/lib/
# ln -vs /usr/local/lib/libmhash.* /usr/lib/
#ldconfig -v
安装PHP
# tar zxf php-5.4.24.tar.gz
# cd php-5.4.24/
# ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --enable-fpm --enable-mbstring --with-mcrypt --with-mhash --with-config-file-path=/usr/local/php5/etc --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-memached
# yum list |grep xml2* (看上面报错,缺少什么先找到再装)
# yum -y install *xml2*
# ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --enable-fpm --enable-mbstring --with-mcrypt --with-mhash --with-config-file-path=/usr/local/php5/etc --with-mysqli=/usr/local/mysql/bin/mysql_config
# make && make install
3.安装nginx
配置nginx服务接收到访问php文件的请求,把请求发给本机的9000端口
安装nginx
#useradd nginx
#tar -zxf nginx-1.8.0.tar.gz
#cd nginx-1.8.0/
#yum -y install gcc gcc-c++ openssl openssl-devel pcre pcre-devel
安装依赖包,由于lnmp安装在一台服务器上,有些已经安装过了,可用直接./configure编译了,缺少什么包会报错再安装就行,一般是下面这些依赖:)[[#yum -y install gcc zlib-devel openssl-devel ]]
#./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
#yum list |grep pcre
#yum -y install pcre*
# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
#make && make install
#ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
#netstat -anptu |grep nginx (先要把之前别的占用80端口关了)
#nginx (#chkconfig nginx on 这里nginx没有启动脚本,不能设置开机自启 写脚本)
# echo 1111 > /usr/local/nginx/html/test.html
# yum -y install elinks
# elinks --dump http://localhost/test.html
1111
#vim /usr/local/nginx/conf/nginx.conf
65-71 注释去掉
69行: fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#nginx -s reload
编写php脚本文件
#cat /usr/local/nginx/html/test.php
<?php
phpinfo();
?>
客户端访问
#http://192.168.4.254/test.php (能解释php代码)
测试php程序能否连接数据库
先把数据库服务开启
# netstat -anptu |grep :3306
tcp 0 0 :::3306 :::* LISTEN 2634/mysqld
#mysql -hlocalhost -uroot -p123456
mysql>grant all on bbsdb.* to webadmin@"localhost" identified by "123456";
mysql>create database bbsdb;
mysql>quit
#vim /usr/local/nginx/html/db.php
<?php
mysql_connect("localhost","webadmin","123456");
if($x){
echo "ok";
}else{
echo "err";
}
?>
测试
#http://192.168.4.254/db.php
ok
(诺数据库没开启,测试得到的就是err)
——————————————————————————————————————————————————————
4.安装memcached
安装memcached服务 (memcache,内存存储——要先装事件触发器的包libevent,libevent和memache要版本兼容,这里libevent-2.0.21,memcached-1.4.24)
先安装libevent
#yum -y install gcc
#tar -xf libevent-2.0.21-stable.tar.gz (memcached服务库文件)
#cd libevent-2.0.21-stable
#./configure
#make && make install
可以直接给库文件做链接也可在库配置文件中写进去,做下面其一就行。
1) #ln -s /usr/local/lib/libevent/* /usr/lib/
#ldconfig (//刷新)
2) #vim /etc/ld.so.conf (库文件的配置文件)
/usr/local/lib/
#ldconfig (//刷新)
3) #vim /etc/ld.so.conf/libevent.conf
/usr/local/lib/
#ldconfig
#tar -zxf memcached-1.4.24.tar.gz
#cd memcached-1.4.24
#./configure
#make && make install
#ln -s /usr/local/bin/memached /bin
#memcached -h (查看帮助)
[root@proxe ~]# memcached -u root -m 64 -vv -d 启动memcached
查看服务是否启动:
[root@proxe ~]# netstat -anptu |grep :11211
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 6813/memcached
tcp 0 0 :::11211 :::* LISTEN 6813/memcached
udp 0 0 0.0.0.0:11211 0.0.0.0:* 6813/memcached
udp 0 0 :::11211 :::* 6813/memcached
【memcached 没有关闭服务脚本,杀进程 pkill -9 memcached 停止服务】
测试:
[root@host b]# yum -y install telnet
[root@host b]# telnet 192.168.4.5 11211
Trying 192.168.4.5...
Connected to 192.168.4.5.
Escape character is ‘^]‘.
set name 0 100 3
tom
STORED
get name
VALUE name 0 3
tom
END
replace name 0 200 3
asc
STORED
get name
VALUE name 0 3
asc
END
add set replace delete get
#cd /usr/lcoal/bin
#./php -m (查看php所支持的功能)
#./php -m |grep memcached (查php是否支持memcached)
让php支持memcached
#cd
# tar -zxvf memcahce-2.2.5
# cd memcahce-2.2.5
#/usr/local/php5/bin/phpize
#./configure --with-php-config=/usr/local/php5/bin/php-config --anable-memcache
#make && make install
#vim /usr/local/php5/etc/php.ini
extension_dir="/usr/local/php5nginx/lib/php/extensions/no-
debug-non-zts-20100525/"
extension=memcache.so
#/etc/init.d/php-fpm restart
修改nginx服务的主配置文件,接收到请求时,先访问11211端口。 (设置先从缓存中查找,没有再从数据库中查询)
#vim /usr/local/nginx/conf/nginx.conf
编写测试文件
#cat /usr/local/nginx/html/mem.php
<?php$memcache=new Memcache;//创建memcache对象
$memcache->connect(‘localhost‘,11211) or die (‘could not
connect!! ‘);
$memcache->set(‘name‘, ‘jim‘); //定义变量
$get_values=$memcache->get(‘name‘);//获取变量值echo
$get_values;?>
#http://nginx-ip/mem.php
jim
本文出自 “12336621” 博客,请务必保留此出处http://12346621.blog.51cto.com/12336621/1914293
lnmp安装---源码安装mysql5.6 -- nginx -- php -- memached
原文地址:http://12346621.blog.51cto.com/12336621/1914293