CentOS7 安装LNMP(Linux+Nginx+MySQL+PHP)
安装make:
yum -y install gcc automake autoconf libtool make
安装g++:
yum install gcc gcc-c++
1.选定源码目录
可以是任何目录,本文选定的是/usr/local/src
cd /usr/local/src
2.安装PCRE库
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure
make
make install
3.安装zlib库www.zlib.net/zlib-1.2.11.tar.gz
http://zlib.net/zlib-1.2.8.tar.gz 下载最新的 zlib 源码包,使用下面命令下载编译和安装 zlib包:
cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.8
./configure
make
make install
4.安装ssl(某些vps默认没装ssl)
cd /usr/local/src
wget http://www.openssl.org/source/openssl-1.0.2c.tar.gz
tar -zxvf openssl-1.0.2c.tar.gz
./config
make
make install
5.安装nginx
Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:
cd /usr/local/src
wget http://nginx.org/download/nginx-1.4.2.tar.gz
tar -zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure –sbin-path=/usr/local/nginx/nginx
–conf-path=/usr/local/nginx/nginx.conf
–pid-path=/usr/local/nginx/nginx.pid
–with-http_ssl_module
–with-pcre=/usr/local/src/pcre-8.38
–with-zlib=/usr/local/src/zlib-1.2.8
–with-openssl=/usr/local/src/openssl-1.0.1c
make
make install
注意:
–with-pcre=/usr/src/pcre-8.34 指的是pcre-8.34 的源码路径。
–with-zlib=/usr/src/zlib-1.2.8 指的是zlib-1.2.8 的源码路径。
安装成功后 /usr/local/nginx 目录下如下
fastcgi.conf koi-win nginx.conf.default
fastcgi.conf.default logs scgi_params
fastcgi_params mime.types scgi_params.default
fastcgi_params.default mime.types.default uwsgi_params
html nginx uwsgi_params.default
koi-utf nginx.conf win-utf
6.启动
确保系统的 80 端口没被其他程序占用,运行/usr/local/nginx/nginx 命令来启动 Nginx,
netstat -ano|grep 80
启动nginx
/usr/local/nginx/nginx
安装PHP-FPM
安装前准备
centos下执行
yum -y install gcc automake autoconf libtool make
yum -y install gcc gcc-c++ glibc
yum -y install libmcrypt-devel mhash-devel libxslt-devel
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel
zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel
ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel
krb5 krb5-devel libidn libidn-devel openssl openssl-devel
http://www.linuxidc.com/Linux/2011-04/34622.htm
新版php-fpm安装(推荐安装方式)
wget http://cn2.php.net/distributions/php-5.6.18.tar.gz
tar zvxf php-5.6.18.tar.gz
cd php-5.6.18
./configure –prefix=/usr/local/php –enable-fpm –with-mcrypt
–enable-mbstring –disable-pdo –with-curl –disable-debug –disable-rpath
–enable-inline-optimization –with-bz2 –with-zlib –enable-sockets
–enable-sysvsem –enable-sysvshm –enable-pcntl –enable-mbregex
–with-mhash –enable-zip –with-pcre-regex –with-mysql –with-mysqli
–with-gd –with-jpeg-dir
make all install
下面是对php-fpm运行用户进行设置
cd /usr/local/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
vi etc/php-fpm.conf
修改
user = www-data
group = www-data
如果www-data用户不存在,那么先添加www-data用户
groupadd www-data
useradd -g www-data www-data
修改nginx配置文件以支持php-fpm
nginx安装完成后,修改nginx配置文件为,nginx.conf
http://www.nginx.cn/wp-content/uploads/2012/09/nginx.conf_.txt
其中server段增加如下配置,注意标红内容配置,否则会出现No input file specified.错误
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
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;
}
创建测试php文件
创建php文件
在/usr/local/nginx/html下创建index.php文件,输入如下内容
<?php
echo phpinfo();
?>
启动服务
Ngnix:
/usr/local/nginx/nginx 端口:80
Php:
/usr/local/php/sbin/php-fpm 端口:9000
一、安装依赖包.
1、yum install gcc gcc-c++ ncurses-devel
2、下载cmake源码包cmake-2.8.5.tar.gz
解压tar zxvf cmake-2.8.5.tar.gz
./bootstrap
Gmake or make 这里用make就行
Make install
二、解压源码包
1.tar -zxvf mysql-5.6.18.tar.gz
2.
在源码包里,编辑文件 cmd-line-utils/libedit/terminal.c
把terminal_set方法中的 char buf[TC_BUFSIZE]; 这一行注释,再把 area = buf;改为 area = NULL;
更改后如下
protected int terminal_set(EditLine *el, const char *term) { int i; /*char buf[TC_BUFSIZE];*/ char *area; const struct termcapstr *t; sigset_t oset, nset; int lins, cols; –phpfensi.com (void) sigemptyset(&nset); (void) sigaddset(&nset, SIGWINCH); (void) sigprocmask(SIG_BLOCK, &nset, &oset); area = NULL;
然后重新编译即可
三、编译+安装
1.执行cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.6/ -DMYSQL_DATADIR=/usr/local/mysql5.6/data -DSYSCONFDIR=/usr/local/mysql5.6/ -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql5.6/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DMYSQL_USER=mysql
2.make
3.make install
4.创建mysql用户
useradd mysql
四、更换配置文件路径
进入mysql5.4源码包:
#conf
cp support-files/my-default.cnf /usr/local/mysql5.6/my.cnf
五、安装mysql的权限表
进入/usr/local/mysql5.6/scripts/目录下面的,执行
5.1 chmod 777 mysql_install_db
5.2 yum install perl-Module-Install.noarch
./mysql_install_db –basedir=/usr/local/mysql5.6/ –datadir=/usr/local/mysql5.6/data –defaults-file=/usr/local/mysql5.6/my.cnf –user=mysql
# 一定要指定配置文件的路径–defaults-file=/usr/local/mysql5.6/my.cnf
六、更改目录权限
chown -R mysql.mysql /usr/local/mysql5.6
七、MySQL启动
7.1 cp support-files/mysql.server /etc/init.d/mysql
7.2 chmod 777 /etc/init.d/mysql
7.3重命名 mv /etc/my.cnf my.cnf.bak
7.4 service mysql start
7.5 开机自启动
/sbin/chkconfig mysql on
八、登录
/usr/local/mysql5.6/bin/mysql 回车执行
九
Use mysql;
1) 接上步,修改mysql密码(可不做此步,默认无密码)
mysql>UPDATE user SET
password=PASSWORD(\’123456\’)
WHERE user=\’root\’;
2)。允许任意连接
host字段给成%
mysql>UPDATE user SET
host=’%’
WHERE user=\’root\’;
mysql>flush privileges;
PDO 打模块
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
./configure–with-php-config=/usr/local/php/bin/php-config –with-freetype-dir=/usr/local/freetype
打pdo_mysql模块 用以下
./configure –with-php-config=/usr/local/php/bin/php-config –with-pdo-mysql=/usr/local/mysql5.6
extension=pdo.so
extension=pdo_mysql.so