一、搭建LNMP平台
案例需求:在ip地址 192.168.1.10的服务器上搭建LNMP平台
系统环境准备:
配置固定Ip地址、关闭 iptables selinux
配置yum源
安装开发库软件包组 和 开发工具软件包组
编译工具 gcc gcc-c++ make
service httpd stop;chkconfig --level 35 httpd off
LNMP简介
LNMP 是网站运行平台
L Linux操作系统 (RHEL5 )
N Nginx 网站服务
M MySQL 数据库服务
P PHP动态网站编程语言
注:PHP一定是安装再MYSQL之前
rpm包安装 rpm -ivh xxx.rpm
源码包安装 *
1、安装源码nginx
yum -y install pcre-devel
[root@www nginx-1.2.0]# useradd -s/sbin/nologin -M www
[root@localhost nginx-1.2.0]# ./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 \
[root@localhost nginx-1.2.0]#make
[root@localhost nginx-1.2.0]#make install
[root@www ~]# ls /usr/local/nginx/
conf html logs sbin
启动服务
[root@www ~]# /usr/local/nginx/sbin/nginx
访问nginx服务
[root@www ~]# elinks --dump http://localhost
Welcome tonginx!
2、安装源码mysql
[root@www ~]# rpm -qa | grep -i mysql-server
[root@www ~]# mv /etc/my.cnf /etc/my.cnf.bak
[root@www ~]# service mysqld stop
[root@www ~]# chkconfig --level 35 mysqld off
[root@www ~]# grep mysql /etc/passwd
[root@www ~]# useradd -s /sbin/nologin -M mysql
[root@www ~]#
2.1 安装编译工具 cmake
[root@www cmake-2.8.10.2]#./bootstrap --prefix=/usr/local/cmake
[root@www cmake-2.8.10.2]# make
[root@www cmake-2.8.10.2]# make install
[root@www local]# /usr/local/cmake/bin/cmake -version
cmakeversion 2.8.10.2
[root@www local]#
2.2 、安装源码mysql
[root@localhost mysql-5.5.13]# /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
[root@localhost mysql-5.5.13]#make && make install
[root@www ~]# ls /usr/local/mysql/
bin docs lib README sql-bench
COPYING include man scripts support-files
data INSTALL-BINARY mysql-test share
[root@www ~]#
2.3 、配置源码mysql服务
[root@www ~]# chown mysql:mysql -R /usr/local/mysql/
初始化授权库
[root@www ~]# ls /usr/local/mysql/data/mysql/
[root@www ~]#
[root@www mysql]# pwd
/usr/local/mysql
[root@www mysql]# ./scripts/mysql_install_db --user=mysql
创建mysql数据库服务主配置文件 /etc/my.cnf
[root@www~]# cd mysql-5.5.13/support-files
[root@wwwsupport-files]# cp my-medium.cnf /etc/my.cnf
启动源码mysql数据库服务
netstat -utnalp | grep :3306
/usr/local/mysql/bin/mysqld_safe --user=mysql &
停止源码mysql数据库服务
[root@www support-files]# pkill -9 mysqld
把源码mysql数据库服务添加为系统服务能用下面的方式做停 启 操作
(service mysqldd start|stop|status)
[root@www ~]# cd mysql-5.5.13/support-files
[root@www support-files]# cp mysql.server /etc/init.d/mysqld
[root@www support-files]# ll /etc/init.d/mysqld
-rw-r--r--1 root root 10650 08-21 10:53 /etc/init.d/mysqldd
[root@www support-files]# chmod +x /etc/init.d/mysqld
[root@www support-files]# chkconfig --add mysqld
[root@www support-files]# chkconfig --list mysqld
mysqldd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@www support-files]#
[root@www support-files]# service mysqld start
StartingMySQL [确定]
[root@www support-files]# service mysqld status
MySQLrunning (31962) [确定]
[root@www support-files]# service mysqld stop
Shuttingdown MySQL. [确定]
[root@www support-files]# service mysqld start
StartingMySQL.. [确定]
[root@www support-files]#
把源码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、设置数据库管理员从数据库服务器本机登录的密码
[root@www ~]# mysqladmin -hlocalhost -uroot password "888"
[root@www ~]# service mysqldd restart
[root@www ~]#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 && make install
3.2 安装源码php
ln -sv/usr/local/lib/libmcrypt* /usr/lib/
ln -sv/usr/local/lib/libmhash.* /usr/lib/
ldconfig -v
[root@www db1]# vim /etc/ld.so.conf
includeld.so.conf.d/*.conf
/usr/local/mysql/lib/
/usr/local/mysql/include/
:wq
[root@www ~ ]# ldconfig -v
[root@www php-5.4.9]# ./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
[root@www php-5.4.9]# make ZEND_EXTRA_LIBS=‘-liconv‘
[root@www php-5.4.9]# make install
[root@www php5nginx]# ls /usr/local/php5nginx/
bin etc include lib php sbin var
[root@www php5nginx]#
3.2 创建php主配置文件 php.ini
[root@www ~ ] # cd php-5.4.9
[root@www php-5.4.9]# cp php.ini-production /usr/local/php5nginx/etc/php.ini
[root@www php-5.4.9]#
nginx
http://localhost/test.php
4、nginx + fast-cgi (让nginx能够解释php页面)
4.1、启动fast-cgi
[root@www mysql]# cd /usr/local/php5nginx/etc
[root@www etc]# cp php-fpm.conf.default php-fpm.conf
4.2、把fpm添加为系统服务
[root@www ~]# cd php-5.4.9/sapi/fpm/
[root@www fpm]# cp init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@www fpm]# chmod +x /etc/rc.d/init.d/php-fpm
[root@www fpm]# chkconfig --add php-fpm
[root@www fpm]# chkconfig --list php-fpm
php-fpm 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用6:关闭
[root@www fpm]# netstat -untlap | grep :9000
[root@www fpm]#
[root@www fpm]# service php-fpm start
Startingphp-fpm done
[root@www fpm]# netstat -untlap | grep :9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 30117/php-fpm
[root@www fpm]#
4.3、让nginx 把接收到访问.php文件的请求,转给本机的9000端口
/usr/local/nginx/html
http://nginx_ip_address/test.php
http://nginx_ip_address/one/1.html
[root@www ~]# vim /usr/local/nginx/conf/nginx.conf
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 include fastcgi_params;
71 }
:wq
[root@www conf]# vim /usr/local/nginx/conf/fastcgi_params
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
:wq
[root@www ~]# /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
[root@www ~]# /usr/local/nginx/sbin/nginx -s stop
[root@www ~]# /usr/local/nginx/sbin/nginx
[root@www ~]#
访问php 文件
elinks --dump http://localhost/test.php
hello wrold
测试php能否连接mysql数据库服务器?
[root@www html]# service mysqldd status
MySQLrunning (658) [确定]
[root@www html]#
[root@www html]# mysql -hlocalhost -uroot -p999
mysql>grant all on webdb.* to webuser@"localhost" identified by "123";
mysql>quit;
[root@www html]# mysql -hlocalhost -uwebuser -p123
mysql>quit;
[root@www html]# cat /usr/local/nginx/html/linkdb.php
<?php
$linkdb=mysql_connect("localhost","webuser","123");
if($linkdb){
echo "linkdb ok!!!";
}else{
echo "linkdb no!!!";
}
?>
[root@www html]#elinks --dump http://localhost/linkdb.php
原文地址:http://kupig.blog.51cto.com/8929318/1580198