Linux下lnmp源码搭建

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

一:lnmp介绍:

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器

Mysql是一个小型关系型数据库管理系统。

PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。

二:搭建过程:

[root@lyt ~]# mkdir /mnt/cdrom

[root@lyt ~]# mount /dev/cdrom /mnt/cdrom/

[root@lyt ~]# cd /mnt/cdrom/Server/

[root@lyt Server]# vim /etc/yum.repos.d/rhel-debuginfo.repo

image

这里需要安装pcre正则函数库

[root@lyt Server]# ll pcre*

image

[root@lyt Server]# yum list all |grep pcre       #查看pcre的相关信息

image

[root@lyt Server]# yum install pcre-devel

安装libevent:(事件触发的网络库)

[root@lyt Server]# cd

[root@lyt ~]# tar  -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/

[root@lyt ~]# cd /usr/local/src/

[root@lyt src]# cd libevent-2.0.16-stable/

[root@lyt libevent-2.0.16-stable]# ./configure           #检测预编译环境

[root@lyt libevent-2.0.16-stable]# make            #编译

[root@lyt libevent-2.0.16-stable]# make install

[root@lyt libevent-2.0.16-stable]# vim /etc/ld.so.conf.d/libevent.conf           #编辑该文件如图:

image

[root@lyt libevent-2.0.16-stable]# ldconfig –v      #手动调用库文件

[root@lyt libevent-2.0.16-stable]# ldconfig -pv |grep libevent         #查看调用/usr/local/lib中的库文件

image

[root@lyt libevent-2.0.16-stable]# cd

Nginx安装:

[root@lyt ~]# tar -zxvf nginx-1.0.11.tar.gz -C /usr/local/src/

[root@lyt ~]# cd /usr/local/src/

[root@lyt src]# cd nginx-1.0.11/

[root@lyt nginx-1.0.11]# groupadd -r nginx          #创建系统组gninx,-r表示系统

[root@lyt nginx-1.0.11]# useradd -r -g nginx -s /bin/false -M nginx       #创建一个系统账号nginx,加入系统组nginx,-M表示系统账号不需要创建家目录。使用/bin/false    ,-s表示shell。也可以使用-s  /sbin/nologin

[root@lyt nginx-1.0.11]# ./configure \

image

[root@lyt nginx-1.0.11]# mkdir -pv /var/tmp/nginx/client       #创建目录。(在上个图片中没有创建记录客户端信息的目录)

[root@lyt nginx-1.0.11]# make

[root@lyt nginx-1.0.11]# make install

[root@lyt nginx-1.0.11]# nginx        #启动nginx服务

image

安装mysql绿色软件:

[root@lyt nginx-1.0.11]# cd

[root@lyt ~]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local

[root@lyt ~]# cd /usr/local

[root@lyt local]# cd mysql-5.5.15-linux2.6-i686/

[root@lyt mysql-5.5.15-linux2.6-i686]# cat INSTALL-BINARY  | less       #利用管道分页查看INSTALL-BINARY文件

image

[root@lyt local]# groupadd mysql           #创建一个mysql组

[root@lyt local]# useradd -r -g mysql mysql           #创建一个mysql用户,并将其加入到mysql组中

[root@lyt local]# cd /usr/local/

第四部拆包文件已经执行过,这里不再执行

[root@lyt local]# ln -s mysql-5.5.15-linux2.6-i686/ mysql         #创建一个符号连接mysql,指向mysql-5.5.15-linux2.6-i686

[root@lyt local]# cd mysql

[root@lyt mysql]# chown -R mysql .        #将mysql下所有的文件的所属用户全都改为mysql。

[root@lyt mysql]# chgrp -R mysql .         #将mysql下所有的文件的所属组全都改为mysql。

[root@lyt mysql]# scripts/mysql_install_db --user=mysql           #使用scrpts初始化脚本,用刚才创建的mysql用户运行,安装数据库mysql

[root@lyt mysql]# chown -R root  .           #将所属用户改为root用户

[root@lyt mysql]# chown -R mysql data         #将data目录的所属用户改为mysql

[root@lyt mysql]# cp  support-files/my-medium.cnf   /etc/my.cnf

[root@lyt mysql]# bin/mysqld_safe --user=mysql &         #启动mysql

[root@lyt mysql]# netstat -tupln |less       #查看端口号

image

[root@lyt mysql]# cp   support-files/mysql.server    /etc/init.d/mysqld          #将mysql.server 拷贝到/etc/init.d/下,改名为mysqld,此命令拷贝成

功后可以使用service  mysqld restart指令。

[root@lyt mysql]# chkconfig --add mysqld      #将mysql服务加入到chkconfig中,可以使用chkconfig来管理

[root@lyt ~]# vim /etc/ld.so.conf        #查看该文件

image

[root@lyt mysql]# cd /etc/ld.so.conf.d/

由于mysql的库文件存在于/usr/local/mysql/lib文件中,而系统的库文件存放于/usr/lib或者/lib中,所以需要创建/etc/ld.so.conf.d/mysql.conf文件,当系统启动时调用/usr/local/mysql/lib中的库文件。

[root@lyt ld.so.conf.d]# vim mysql.conf           #创建mysql.conf文件,系统启动时可以调用/usr/local/mysql/lib下的库文件

image

[root@lyt ld.so.conf.d]# ldconfig -v |grep mysql           #查看mysql的系统调用

image

由于mysql的头文件存在于/usr/local/mysql/include文件中,而系统的头文件存放于/usr/include中,所以需要在/usr/include中创建连接,当系统启动时调用/usr/local/mysql/include中的头文件

[root@lyt ld.so.conf.d]# cd /usr/include/

[root@lyt include]# ln -s /usr/local/mysql/include/  mysql #创建一个字符连接mysql,连接到/usr/local/mysql/include

安装php:

[root@lyt include]# cd

[root@lyt ~]# tar -jxvf php-5.3.7.tar.bz2 -C /usr/local/src/

[root@lyt ~]# cd /usr/local/src/

[root@lyt src]# cd php-5.3.7/

[root@lyt php-5.3.7]#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm  --with-libevent-dir=/usr/local --with-

mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml

--with-iconv-dir=/usr/local

[root@lyt php-5.3.7]# make   

[root@lyt php-5.3.7]# make install

[root@lyt php-5.3.7]# cp php.ini-production /usr/local/php/etc/php.ini

[root@lyt php-5.3.7]# cp  /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf

[root@lyt php-5.3.7]# cd /usr/local/php/etc/

[root@lyt etc]# vim php-fpm.conf        #编辑该文件,启用如下行

image

image

image

image

image

image

[root@lyt etc]# /usr/local/php/sbin/php-fpm &         #启动fastcgi

[root@lyt etc]# vim /etc/nginx/fastcgi.conf

image

保证两个文件相同(fastcgi.conf 和 fastcgi_params)

[root@lyt etc]# cd /etc/nginx/

[root@lyt nginx]# cat fastcgi.conf>fastcgi_params         #将fastcgi.conf中的内容重定向到fastcgi_params

[root@lyt nginx]# vim /etc/nginx/nginx.conf

image

[root@lyt nginx]# cd /usr/html/

[root@lyt html]# vim index.html

image

[root@lyt html]# mv index.html index.php         #重命名

[root@lyt html]# vim /etc/nginx/nginx.conf

image

[root@lyt html]# pkill -1 nginx

image

[root@lyt html]# vim /usr/html/index.php

image

[root@lyt html]# pkill -1 nginx

image

[root@lyt html]# /usr/local/mysql/bin/mysqladmin -u root -p password '123'           #为数据库创建密码

[root@lyt html]# /usr/local/mysql/bin/mysql -u root –p      #使用密码登录数据库

image

image

[root@lyt html]# vim /usr/html/index.php

image










本文转自 liuyatao666 51CTO博客,原文链接:http://blog.51cto.com/5503845/980000,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
5月前
|
运维 网络协议 Linux
腾讯T6-9首发“Linux内核源码底层原理开发进阶笔记”,差距不止一点点哦
腾讯T6-9首发“Linux内核源码底层原理开发进阶笔记”,差距不止一点点哦
|
6月前
|
存储 Java Linux
【深入研究Hotspot源码与Linux内核】
【深入研究Hotspot源码与Linux内核】
|
4月前
|
Linux 应用服务中间件 PHP
Linux下搭建PHP环境-源码编译安装PHP7.2
Linux下搭建PHP环境-源码编译安装PHP7.2
153 0
|
4天前
|
Linux 开发工具 Android开发
Docker系列(1)安装Linux系统编译Android源码
Docker系列(1)安装Linux系统编译Android源码
7 0
|
3月前
|
Linux 调度 索引
Linux内核源码的组织结构
Linux内核源码的组织结构
|
3月前
|
算法 Java Linux
linux源码解读系列
linux源码解读系列
|
3月前
|
Linux Android开发
Linux内核学习(五):linux kernel源码结构以及makefile分析
Linux内核学习(五):linux kernel源码结构以及makefile分析
78 0
|
4月前
|
小程序 Linux 开发工具
手把手教你如何在Linux下写进度条小程序(附源码)
手把手教你如何在Linux下写进度条小程序(附源码)
|
4月前
|
消息中间件 Java Shell
Linux【脚本 03】shell脚本离线安装配置集结JDK+InfluxDB+Zookeeper+Kafka(安装文件及脚本源码网盘分享)
Linux【脚本 03】shell脚本离线安装配置集结JDK+InfluxDB+Zookeeper+Kafka(安装文件及脚本源码网盘分享)
28 0
|
4月前
|
关系型数据库 MySQL Shell
MySQL【实践 01】Linux 环境 MySQL 数据库备份 shell 脚本(脚本源码及说明+定时任务配置+数据库恢复测试)粘贴可以
MySQL【实践 01】Linux 环境 MySQL 数据库备份 shell 脚本(脚本源码及说明+定时任务配置+数据库恢复测试)粘贴可以
52 0