一、安装前的准备
1.环境准备
CentOS 6.x 64位
关闭SELinux和iptables
保证能正常连接互联网
2.配置网络yum源
(1)先将系统的yum配置文件备份拷贝到其他目录
cp /etc/yum.repo.d/* ~/bak
(2)下载阿里云的yum源
#base源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
#epel源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/epel-6.repo
#下载完成后的操作:
yum clean all #清除原有的缓存
yum makecache #建立新的缓存列表
yum update #将所有能更新的软件更新(非必选)
(3)安装编译软件和依赖
yum install -y gcc* pcre-devel opensll openssl-devel zlib-devel ncurses-devel cmake bison libxml2-devel libpng-devel
(4)nginx、mysql、php源码包下载地址:
Nginx:http://nginx.org/en/download.html
MySQL:https://dev.mysql.com/downloads/mysql/
PHP:http://www.php.net/
#版本选用:
#Nginx: 1.12.* #选用软件的稳定版即可
#Mysql: 5.5.* #5.5 以上版本需要 1G 以上的内存,否则无法安装
#PHP: 5.6*
二、源码软件安装
1.nginx
#创建存放源码包的目录
mkdir /lnmp
(1)下载nginx源码包
wget http://nginx.org/download/nginx-1.12.2.tar.gz
(2)创建用于运行nginx的用户
useradd -r -s /sbin/nologin nginx
(3)解压nginx并安装
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
2.mysql
(1)下载:
wget https://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.62.tar.gz
(2)创建用于运行mysql的用户
useradd -r -s /sbin/nologin mysql
(3)解压缩并安装
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
make && make install
#创建软连接
ln -s /usr/local/mysql/bin/* /usr/local/bin/
(4)修改目录权限
#cd /usr/local/mysql/
chown -R root .
chown -R mysql data/
(5)生成mysql配置文件
cp -a /lnmp/mysql-5.5.62/support-files/my-medium.cnf /etc/my.cnf
(6)初始化,生成授权表
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql
#初始化成功的标准:两个ok
(7)生成mysql的启动和自启动管理脚本
cd /lnmp/mysql-5.5.62/support-files/
cp -a mysql.server.sh /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
#设置密码
mysqladmin -uroot password 123456
3.PHP
(1)下载:
wget http://tw2.php.net/distributions/php-5.6.38.tar.gz
(2)解压缩并安装
./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets --with-pdo-mysql=/usr/local/mysql --with-gd --without-pear --enable-fpm
make && make install
(3)生成php配置文件
cp -a /lnmp/php-5.6.38/php.ini-production /usr/local/php/etc/php.ini
(4)创建软连接
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
4.配置nginx连接php
cd /usr/local/php/etc/
(1)生成php-fpm的配置文件,并修改参数
cp -a php-fpm.conf.default php-fpm.conf
#vim php-fpm.conf
pid = run/php-fpm.pid
#取消注释
user = nginx
group = nginx
pm.start_servers = 2
#启动时开启的进程数(默认值)
pm.min_spare_servers = 1
#最少空闲进程数(默认值)
pm.max_spare_servers = 3
#最多空闲进程数(默认值)
(2)修改nginx的配置文件,使其识别.php后缀的
#vim /usr/local/nginx/conf/nginx.conf
#取消以下几行的注释,并修改include选项的后缀位fastcgi.conf
#65行-71行
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
(3)测试:重启nginx,创建php测试文件
location / {
root html;
index index.html test.php index.htm;
}
nginx启动脚本下载:
https://yz231.lanzous.com/iwlvFfrrh6h