CentOS6.x编译安装LNMP(Linux+Nginx+Mysql+PHP)

简介:
+关注继续查看

一、准备依赖包及扩展组件

1
yum install -y gcc gcc-c++ make curl-devel kernel-headers glibc glibc-headers zlib zlib-devel openssl openssl-devel pcre-devel perl compat* php-common ncurses-devel libtool* libxml2 libxml2-devel

二、安装nginx

1
2
3
4
5
6
7
8
9
groupadd nginx
useradd -g nginx -s /sbin/nologin nginx
tar zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
 ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
--with-http_ssl_module --with-http_gzip_static_module
--with-http_stub_status_module
make && make install
/usr/local/nginx/sbin/nginx #启动nginx

Nginx启动、停止、重启等SysV管理脚本,方便使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
vi /etc/init.d/nginx
#!/bin/bash
# chkconfig: 345 99 20
# description: Nginx service control script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
echo "Nginx service start success."
;;
stop)
kill -s QUIT $(cat $PIDF)
echo "Nginx service stop success."
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
echo"reload Nginx config success."
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
1
2
3
4
chmod +x /etc/init.d/nginx
service nginx start
chkconfig --add nginx
chkconfig nginx on

测试:http://127.0.0.1 #出现欢迎nginx页面成功

三、安装mysql

1、创建mysql组和用户

1
2
groupadd mysql
useradd –g mysql -s /sbin/nologin mysql

2、安装mysql

1
2
3
4
5
6
tar zxvf mysql-5.5.30.tar.gz
cd mysql-5.5.30
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/usr/local/mysql/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data
make && make install

3、配置mysql 

1
2
3
4
5
6
7
8
9
10
11
12
13
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql #初始化数据库
cp support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile #添加执行命令环境变量
source /etc/profile #生效环境变量
chmod +x /etc/init.d/mysqld
chown -R root.mysql /usr/local/mysql/
chown -R mysql:mysql mysql/data/ #赋予数据存放目录权限
mysqld_safe --user=mysql& #启动mysql
rm -rf /etc/my.cnf   #删除mysql以前的配置文件,否则有时会起不来
service mysqld start
mysqladmin -u root password '123456'#设置root登录密码
chkconfig mysqld on

四、安装php和配置php-fpm

1、安装gd库

1
yum install –y gd php-gd freetype freetype-devel libpng libpng-devel libjpeg*

2、安装php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
tar zxvf php-5.4.tar.gz
./configure --prefix=/usr/local/php \
-with-config-file-path=/usr/local/php/etc \
-with-mysql=/usr/local/mysql \
-with-mysqli=/usr/local/mysql/bin/mysql_config \
-with-mysql-sock=/tmp/mysql.sock \
-with-pdo-mysql=/usr/local/mysql \
-with-gd -with-zlib -with-iconv -enable-zip -enable-pdo \
-enable-xml -with-openssl -with-curl -enable-bcmath \
-enable-ftp -enable-xml -with-openssl -with-curl \
-enable-bcmath -enable-ftp -enable-mbstring -enable-fpm \
-with-fpm-user=nginx -with-fpm-group=nginx -enable-shmop \
-enable-sysvsem -enable-mbregex -enable-gd-native-ttf \
-enable-pcntl -enable-sockets -with-xmlrpc -enable-soap \
-without-pear -with-gettext -enable-session
make && make install

3、配置php

1
2
3
4
cp php.ini-production /usr/local/php/etc/php.ini
vi /usr/local/php/etc/php.ini
date.timezone = Asia/Shanghai #设置时区
expose_php = OFF #禁止显示版本信息

4、置php-fpm

1
2
3
4
5
6
7
8
9
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
user = nginx
group = nginx
pid = run/php-fpm.pid
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
service php-fpm start
chkconfig php-fpm on

五、nginx和php整合

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
vi /usr/local/nginx/conf/nginx.conf #修改并去掉以下注释
user nginx nginx;
error_log logs/error.log;
worker_processes 4; #默认创建子进程个数
events {
 worker_connections 1024; #一个子进程最大连接数
}
pid logs/nginx.pid;
...................
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; #SCRIPT_FILENAME后面写网站根目录
    include fastcgi_params;
 }
...................
1
2
3
4
/usr/local/nginx/sbin/nginx -t #测试语法是否正确
service nginx restart
chown -R nginx /usr/local/nginx/html
chmod 744 -R /usr/local/nginx/html

六、测试

1
2
3
4
5
6
service nginx restart
service php-fpm restart
vi index.php
<?php
phpinfo();
?>

http://127.0.0.1,可以看到相关的配置信息!



本文转自 李振良OK 51CTO博客,原文链接:http://blog.51cto.com/lizhenliang/1290439,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
3天前
|
应用服务中间件 Linux nginx
百度搜索:蓝易云【linux系统服务器,nginx日志切割保存教程。】
最后,确保定期检查和清理旧的日志文件,以免占用过多的磁盘空间。您可以使用crontab或其他定时任务工具来定期运行清理命令,例如删除超过一定时间的旧日志文件。
79 0
|
7天前
|
JavaScript 前端开发 应用服务中间件
linux+nginx+前后端部署
linux+nginx+前后端部署
26 0
|
8天前
|
应用服务中间件 Linux 网络安全
Linux配置Nginx SSL支持Https配置教程
Linux配置Nginx SSL支持Https配置教程
|
8天前
|
应用服务中间件 Linux nginx
Linux安装Nginx
Linux安装Nginx
|
10天前
|
Ubuntu 应用服务中间件 Linux
linux安装nginx
linux安装nginx
|
12天前
|
缓存 应用服务中间件 网络安全
Linux 配置 Nginx 服务完整详细版
Linux 配置 Nginx 服务完整详细版
56 1
|
13天前
|
缓存 应用服务中间件 Linux
百度搜索:蓝易云【Linux系统Nginx优化与防盗链详细教程】
这些是关于Nginx优化和防盗链的基本教程。根据实际需求和具体情况,您可能需要进行更多的配置和调整。在修改Nginx配置文件之前,请确保您对配置语法和操作有一定的了解,并备份原始配置文件以防意外情况发生。
156 1
|
13天前
|
缓存 应用服务中间件 网络安全
Linux 配置 Nginx 服务完整详细版
当你需要配置Nginx服务器来托管网站或应用程序时,以下是一些基本步骤和示例配置,以帮助你入门。请注意,Nginx的配置可以非常灵活,可以根据你的具体需求进行自定义。以下示例假设你已经在服务器上安装了Nginx。
73 0
|
15天前
|
Ubuntu 应用服务中间件 Linux
Linux使用Nginx搭建图片服务器
Linux使用Nginx搭建图片服务器
23 0
相关产品
云迁移中心
推荐文章
更多