LNMP网站平台搭建
一、搭建LNMP平台案例需求:在ip地址 192.168.1.10的服务器上搭建LNMP平台
系统环境准备:
配置固定Ip地址、关闭 iptables selinux
配置yum源
安装开发库软件包组 和开发工具软件包组
编译工具 gccgcc-c++ make
service httpd stop;chkconfig--level35 httpdoff
LNMP简介
LNMP是网站运行平台
L Linux操作系统 (RHEL5 )
N Nginx 网站服务
MMySQL 数据库服务
P PHP动态网站编程语言
注:PHP一定是安装再MYSQL之前
rpm包安装 rpm -ivh xxx.rpm
源码包安装 *
1、安装源码nginx
yum -yinstall pcre-devel
# useradd-s/sbin/nologin-Mwww
#./configure \
>--prefix=/usr/local/nginx \
>--pid-path=/usr/local/nginx/nginx.pid\
>--user=www --group=www \
>--with-http_ssl_module--with-http_flv_module\
>--with-http_stub_status_module \
>--with-http_gzip_static_module \
#make
#make install
# ls /usr/local/nginx/
confhtml logssbin
启动服务
# /usr/local/nginx/sbin/nginx
访问nginx服务
# elinks--dump http://localhost
Welcome tonginx!
2、安装源码mysql
# rpm -qa | grep -i mysql-server
# mv/etc/my.cnf/etc/my.cnf.bak
# service mysqldstop
# chkconfig--level35 mysqldoff
# grep mysql/etc/passwd
# useradd -s /sbin/nologin-Mmysql
#
2.1安装编译工具 cmake
#./bootstrap--prefix=/usr/local/cmake
# make
# make install
# /usr/local/cmake/bin/cmake -version
cmakeversion 2.8.10.2
#
2.2 、安装源码mysql
# /usr/local/cmake/bin/cmake \
>-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
>-DSYSCONFDIR=/etc-DMYSQL_DATADIR=/usr/local/mysql/data \
>-DMYSQL_TCP_PORT=3306\
>-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock\
>-DMYSQL_USER=mysql-DEXTRA_CHARSETS=all\
>-DWITH_READLINE=1-DWITH_SSL=system\
>-DWITH_EMBEDDED_SERVER=1\
>-DENABLED_LOCAL_INFILE=1\
>-DWITH_INNOBASE_STORAGE_ENGINE=1
#make &&make install
# ls/usr/local/mysql/
bin docs lib README sql-bench
COPYINGinclude man scriptssupport-files
data INSTALL-BINARYmysql-test share
#
2.3 、配置源码mysql服务
# chownmysql:mysql-R /usr/local/mysql/
初始化授权库
# ls /usr/local/mysql/data/mysql/
#
# pwd
/usr/local/mysql
# ./scripts/mysql_install_db --user=mysql
创建mysql数据库服务主配置文件 /etc/my.cnf
#cdmysql-5.5.13/support-files
# cp my-medium.cnf /etc/my.cnf
启动源码mysql数据库服务
netstat -utnalp | grep:3306
/usr/local/mysql/bin/mysqld_safe--user=mysql&
停止源码mysql数据库服务
# pkill -9 mysqld
把源码mysql数据库服务添加为系统服务能用下面的方式做停 启 操作
(servicemysqldd start|stop|status)
#cdmysql-5.5.13/support-files
# cp mysql.server /etc/init.d/mysqld
# ll /etc/init.d/mysqld
-rw-r--r--1 root root 10650 08-21 10:53 /etc/init.d/mysqldd
# chmod +x /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --list mysqld
mysqldd 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
#
# service mysqld start
StartingMySQL [确定]
# service mysqld status
MySQLrunning (31962) [确定]
# service mysqld stop
Shuttingdown MySQL. [确定]
# service mysqld start
StartingMySQL.. [确定]
#
把源码mysql命令的路径添加到PATH变量里
export PATH=/usr/local/mysql/bin:$PATH
vim/etc/profile
export PATH=/usr/local/mysql/bin:$PATH
:wq
2.4、使用数据库管理员在数据库服务器本机登录
mysql-hlocalhost-uroot -p
password:回车
mysql>grant all on *.* to jim@"%"identifiedby "123";
mysql>quit;
2.5、设置数据库管理员从数据库服务器本机登录的密码
# mysqladmin -hlocalhost -uroot password "888"
# servicemysqlddrestart
#mysql-hlocalhost -uroot-p888
mysql>
3、安装源码php
3.1安装php的扩展功能包
tar-zxvf mhash-0.9.9.9.tar.gz 哈希函数库
cdmhash-0.9.9.9
./configure&&make &&make install
tar-zxvf libiconv-1.13.tar.gz 字符编码转换
cdlibiconv-1.13
./configure&&make && make install
tarzxf libmcrypt-2.5.8.tar.gz
cdlibmcrypt-2.5.8
./configure&&make &&make install
ldconfig -v
cd libltdl
./configure--with-gmetad --enable-gexec --enable-ltdl-install
make&& makeinstall
3.2安装源码php
ln -sv/usr/local/lib/libmcrypt* /usr/lib/
ln -sv/usr/local/lib/libmhash.* /usr/lib/
ldconfig-v
# vim /etc/ld.so.conf
includeld.so.conf.d/*.conf
/usr/local/mysql/lib/
/usr/local/mysql/include/
:wq
#ldconfig -v
# ./configure --prefix=/usr/local/php5nginx--with-config-file-path=/usr/local/php5nginx/etc--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr--enable-xml --disable-rpath --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-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
# make ZEND_EXTRA_LIBS='-liconv'
# make install
# ls /usr/local/php5nginx/
binetc includelibphp sbinvar
#
3.2创建php主配置文件 php.ini
# cdphp-5.4.9
# cpphp.ini-production/usr/local/php5nginx/etc/php.ini
#
nginx
http://localhost/test.php
4、nginx +fast-cgi(让nginx能够解释php页面)
4.1、启动fast-cgi
# cd /usr/local/php5nginx/etc
# cp php-fpm.conf.defaultphp-fpm.conf
4.2、把fpm添加为系统服务
#cdphp-5.4.9/sapi/fpm/
# cp init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x/etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig --list php-fpm
php-fpm 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
# netstat -untlap | grep :9000
#
# service php-fpm start
Startingphp-fpmdone
# netstat -untlap | grep :9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 30117/php-fpm
#
4.3、让nginx 把接收到访问.php文件的请求,转给本机的9000端口
/usr/local/nginx/html
http://nginx_ip_address/test.php
http://nginx_ip_address/one/1.html
# vim /usr/local/nginx/conf/nginx.conf
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_indexindex.php;
69 fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
70 include fastcgi_params;
71 }
:wq
# vim /usr/local/nginx/conf/fastcgi_params
fastcgi_paramSCRIPT_FILENAME $document_root$fastcgi_script_name;
:wq
# /usr/local/nginx/sbin/nginx-t
nginx:the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx:configuration file /usr/local/nginx/conf/nginx.conf test is successful
# /usr/local/nginx/sbin/nginx-s stop
# /usr/local/nginx/sbin/nginx
#
访问php 文件
elinks--dumphttp://localhost/test.php
hello wrold
测试php能否连接mysql数据库服务器?
# service mysqldd status
MySQLrunning (658) [确定]
#
# mysql -hlocalhost -uroot -p999
mysql>grantall on webdb.*towebuser@"localhost" identified by"123";
mysql>quit;
# mysql -hlocalhost -uwebuser -p123
mysql>quit;
# cat /usr/local/nginx/html/linkdb.php
<?php
$linkdb=mysql_connect("localhost","webuser","123");
if($linkdb){
echo "linkdbok!!!";
}else{
echo "linkdb no!!!";
}
?>
#elinks --dumphttp://localhost/linkdb.php
页:
[1]