LNMP ——路之艰辛,感谢智杰同学的帮助
一、MySQL搭建
1.下载软件包
(1)#cd /usr/local/src
(2)#wget 下载免编译的二进制包
(注意这个包是64的,有需要的要找下32位的
)
2.初始化
(1)#tar -zxvf 解压
(2)#mv /usr/local/mysql 挪动位置
(3)#useradd -s /sbin/nologin mysql 建立mysql用户
(4)#cd /usr/local/mysql
(5)#mkdir -p /data/mysql 创建datadir,数据库文件会放在这里面
(6)#chown -R mysql:mysql /data/mysql 更改权限
(7)#./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
3.配置mysql
(1)#cp support-files/my-large.cnf /etc/my.cnf 拷贝配置文件
(2)#cp support-files/mysql.server /etc/init.d/mysqld 拷贝启动脚本
(3)#chmod 755 /etc/init.d/mysqld 修改启动脚本权限
4.修改启动脚本
(1)#vim /etc/init.d/mysqld 需要修改的地方
“basedir=/usr/local/mysql”“datadir=/data/mysql”
(2)#chkconfig --add mysqld 加入开机服务
(3)#chkconfig mysqld on
(4)#service mysqld start 启动MySQL
二、nginx的搭建
1.下载安装包
(1)#cd /usr/local/src
(2)#wget
(3)#tar -zxvf nginx-1.9.6.tar.gz
2.配置编译参数
(1)#cd nginx-1.9.6
(2)#./configure --prefix=/usr/local/nginx --with-pcre --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module
如果遇到“ PCRE library ... not found”解决方法“yum install -y pcre-devel”
如果遇到“PCRE JIT support”解决方法“”
如果遇到“ md5 in system md library ... not found”解决方法“yum install -y zlib-devel”
yum -y install openssl openssl-devel (我遇到的从此包搞定)
3.编译安装
(1)#make
(2)#make install
4.启动nginx,编写启动脚本
(1)#/usr/local/nginx/sbin/nginx
(2)#vim /etc/init.d/nginx
#!/bin/bash# chkconfig: - 30 21# description: http service.# Source Function Library. /etc/init.d/functions# Nginx SettingsNGINX_SBIN="/usr/local/nginx/sbin/nginx"NGINX_CONF="/usr/local/nginx/conf/nginx.conf"NGINX_PID="/usr/local/nginx/logs/nginx.pid"RETVAL=0prog="Nginx"start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL}stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL}reload(){ echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL}restart(){ stop start}configtest(){ $NGINX_SBIN -c $NGINX_CONF -t return 0}case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1esacexit $RETVAL
(3)#chmod a+x /etc/init.d/nginx
(4)#chkconfig --add nginx
(5)#chkconfig nginx on
三、php的搭建
1.下载安装源码包
(1)#cd /usr/local/src
(2)#wget
2.解压并创建账号
(1)#tar -zxvf php-5.6.15.tar.gz
(2)#useradd -s /sbin/nologin php-fpm 在LNMP环境中,php是以一个服务来提供服务的
3.配置编译选项
(1)#cd php-5.6.15
(2)./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-curl
*遇到“ error: xml2-config not found. Please check your libxml2 installation.”,
解决方法“ #yum install -y libxml2-devel ”
*遇到“ error: Cannot find OpenSSL's <evp.h> ”,
解决方法“ #yum install -y openssl openssl-devel ”
*遇到“error: Please reinstall the BZip2 distribution”,
解决方法“ #yum install -y bzip2 bzip2-devel ”
*遇到“error: jpeglib.h not found.”,
解决方法“#yum install -y libjpeg libjpeg-devel”
*遇到“ error: png.h not found.”,
解决方法“#yum install -y libpng libpng-devel”
*遇到“ error: freetype-config not found.”,
解决方法“#yum install -y freetype freetype-devel”
*遇到“ error: mcrypt.h not found. Please reinstall libmcrypt.”,
解决方法“#yum install -y epel-release”
修改"/etc/yum.repos.d/epel.repo”, 将baseurl的注释取消, mirrorlist注释掉。
“#yum install -y libmcrypt-devel”
*遇到“Please reinstall the libcurl distribution”
解决方法“yum install -y libcurl-devel”
4.编译安装
(1)#make
(2)#make install
5.拷贝配置文件和启动脚本
(1)#cp php.ini-production /usr/local/php/etc/php.ini
(2)#cp /usr/local/src/php-5.6.15/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
(3)#mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
(4)#chmod 755 /etc/init.d/php-fpm
(5)#chkconfig --add php-fpm
(6)#service php-fpm start
(7)#chkconfig php-fpm on
四、配置解析php
(1)#vim /usr/local/nginx/conf/nginx.conf 把下面的配置,前面的#删除,并更改fastcgi_param SCRIPT_FILENAME 那一行
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
(2)#/usr/local/nginx/sbin/nginx -s reload
(3)#vim /usr/local/nginx/html/1.php
<?php phpinfo();?>
(4)#curl localhost/1.php
如果在浏览器解析不出来,
iptables -F