Centos 6.5源码搭建lnmp环境

                                         单机环境下搭建LNMP(需要准备的软件pcre、nginx、mysql、php)

本次安装环境为Centos 6.5
软件版本为:(mysql-5.0.45.tar、nginx-0.8.37.tar、pcre-8.32.tar、php-5.6.9.tar)
先在/usr/local/下创建nginx,php,mysql,software目录,然后把安装源上传到software目录下

将安装包解压
tar -zxvf mysql-5.0.45.tar
tar -zxvf nginx-0.8.37.tar
tar -zxvf pcre-8.32.tar
tar -zxvf php-5.6.9.tar

Pcre安装步骤
cd /usr/local/software/pcre-8.32
./configure && make && make install

Nginx安装步骤
添加nginx用户
groupadd www
useradd -g www www
tar zxf nginx-1.5.10.tar.gz
cd /usr/local/software/nginx-1.5.10
./configure –prefix=/usr/local/nginx \
–group=www \
–user=www \
–with-openssl=/usr/local/include \
–with-pcre=/usr/local/software/pcre-8.32/ \
–with-http_stub_status_module
make && make install
nginx部分配置
修改vi /usr/local/nginx/conf/nginx.conf配置文件中
location / {
root html;
index index.html index.htm index.php;
}

fastcgi整合nginx,php

location ~ .php{  
            root           html;  
            fastcgi_pass   127.0.0.1:9000;  
            fastcgi_index  index.php;  
            fastcgi_param  SCRIPT_FILENAME
{              root           html;              fastcgi_pass   127.0.0.1:9000;              fastcgi_index  index.php;              fastcgi_param  SCRIPT_FILENAME
document_root$fastcgi_script_name;
include fastcgi_params;
}
手工编辑nginx开机自启动脚本,将nginx文件放到 /etc/init.d/中
chkconfig –add nginx //将nginx加到服务列表中
chkconfig nginx on //开机自启动nginx

Mysql安装操作步骤
groupadd mysql
usradd -g mysql mysql
tar zxf mysql-5.1.62.tar.gz
cd /usr/local/software/mysql-5.1.62
./configure –prefix=/usr/local/mysql \
–sysconfdir=/etc \
–localstatedir=/var/lib/mysql \
–with-tcp-port=3306 \
–with-unix-socket-path=/var/lib/mysql/mysqld.socket \
–with-mysqld-user=mysql \
–enable-assembler \
–with-charset=utf8 \
–with-extra-charsets=all \
–enable-thread-safe-client \
–with-big-tables \
–with-readline \
–with-ssl \
–with-embedded-server \
–enable-local-infile \
–with-client-ldflags=-all-static \
–with-mysqld-ldflags=-all-static \
–with-debug \
–with-plugins=partition,innobase,myisammrg,myisam
make && make install
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
cp /usr/local/mysql/share/mysql/my-huge.cnf /etc/my.cnf
chmod 755 /etc/init.d/mysqld
chkconfig –add mysqld
/usr/local/mysql/bin/mysql_install_db –user=mysql //一定要先初始化数据库,否则mysql启动不了。
service mysqld start
cp /usr/local/mysql/bin/mysql /bin //将mysql命令复制到bin
安装完成时Mysql无密码用户名为root
mysql -u root //进入mysql数据库
SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘newpass’);
//设置root用户密码其中newpass即为新设置的密码

grant all privileges on . to ‘root’@’%’ identified by ‘wodingni’;
//设置数据库远程访问权限,允许root用户以任何IP登陆
flush privileges;

/etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT //将该代码加入iptables中22端口下面可防止开启防火墙后阻止远程访问

安装PHP步骤
进入php安装目录
./configure –prefix=/usr/local/php \
–with-config-file-path=/usr/local/php/etc \
–with-mysql \
–with-mysqli \
–enable-sysvsem \
–enable-sysvshm \
–enable-pcntl \
–enable-mbregex \
–enable-zip \
–with-pcre-regex \
–with-libxml-dir \
–with-gd \
–with-jpeg-dir \
–with-png-dir \
–with-freetype-dir \
–with-iconv-dir \
–with-zlib-dir \
–enable-sockets \
–enable-soap \
–enable-gd-native-ttf \
–enable-ftp \
–enable-mbstring \
–enable-exif \
–disable-ipv6 \
–disable-debug \
–enable-bcmath \
–with-gettext \
–enable-fpm
make && make install
cp /usr/local/software/php-5.6.9/php.ini-development /usr/local/php/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
/usr/local/php/sbin/php-fpm //启动php
ln -s /usr/local/php/bin/php /usr/bin/
手动编译PHP自启动文件,放入/etc/init.d目录下,
chkconfig –add php-fpm //将php-fpm加到服务列表中
chkconfig php-fpm on //开机自启动php-fpm
在任意路径下使用命令 links 127.0.0.1 出现“welcome nginx”字样则环境搭建成功。
至此LNMP环境搭建完成,如果解析php文件提示找不到时请仔细检查nginx部分的nginx.conf文件配置是否配置正确。
本地可以访问,远程不能访问时请关闭防火墙。service iptables stop

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值