一.NGINX的安装步骤
1.在浏览器中找到下载地址进行下载:
wget http://nginx.org/download/nginx-1.16.0.tar.gz
2.然后解压到指定目录中 :
tar -zxvf nginx-1.16.0.tar.gz -C /usr/local/src/
3.下载环境包
yum install openssl openssl-devel zlib zlib-devel pcre pcre-devel
yum install gcc gcc-c++
4.探测目标环境gcc等编辑器是否可用,生成Makefile
./configure
5.进入到下载好的目录中
cd /usr/local/src/nginx-1.16.0/
6.按照生成的Makefile 进行编译
make && make install
7.配置文件存放目录:
cd /usr/local/src/sbin/nginx
8.关闭防火墙,关闭SELinux
systemctl stop firewalld
setemctl 0
9.在浏览器中输入自己的IP进行查看
二.MySQL的安装步骤
1.在浏览器中找到下载地址进行下载
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz
2.下载环境包:
yum -y install cmake bison git ncurses-devel gcc gcc-c++
3.起名,给与权限:
groupadd mysql
useradd -g mysql mysql
4.解压安装包:
tar zxvf mysql-5.6.38.tar.gz
5.创建目录:
mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
6.进入到下载好的目录中:
cd /usr/local/src/mysql-5.6.38/
7.开始编译安装
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DENABLE_DOWNLOADS=1
8.按照生成的makefile进行编译
make && make install
9.修改目录属主权限
chown -R mysql:mysql /usr/local/mysql/data/
chown -R mysql:mysql /usr/local/mysql/
10.数据库初始化
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp
11.给与mysql.cnf可读的权限:
chown -R mysql:mysql my.cnf
12.对mysql进行编辑
vim my.cnf
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = .....
server_id = .....
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp
13.进入指定目录,启动MySQL
cd /usr/local/mysql/support-files
./mysql.server start
mysql启动
cd /usr/local/mysql/bin
./mysql -u root -p
三.PHP的安装步骤
1.在浏览器中找到下载地址进行下载:
wget http://cn2.php.net/distributions/php-5.6.0.tar.xz
2.然后解压到指定目录中:
xz -d php-5.6.0.tar.xz
tar xf php-5.6.0.tar -C /usr/tar xf php-5.6.0.tar -C /usr/ngmulusrc/
3.安装环境包:
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel bz2-devel
(yum install epel-release.noarch )
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install libmcrypt-devel mhash mcrypt
4.创建 www 用户,并给与权限:
groupadd www
useradd -g www -s /sbin/nologin -M www
5.进入到指定目录,进行编译安装:
cd /usr/local/src/php-5.6.0/
#./configure \
--prefix=/usr/local/php56 \
--with-config-file-path=/usr/local/php56/etc \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-opcache \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-readline\
--with-gd
6.按照生成的makefile进行编译
make && make install
如果想重新安装:
make过程中报错,解决错误后,
配置 PHP
1.进入下载好的源码包中:
cd /usr/local/src/php-5.6
配置文件:
cp php.ini-development /usr/local/php56/etc/php.ini
php-fpm 服务
cp /usr/local/php56/etc/php-fpm.conf.default /usr/local/php56/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56 (php-fpm的可执行文件)
chmod +x /etc/init.d/php-fpm56
启动 php-fpm(nginx与 php沟通 )
service php-fpm56 start
Starting php-fpm done
php-fpm 可用参数 start|stop|force-quit|restart|reload|status
添加 PHP 命令到环境变量,进行编辑 /etc/profile:
PATH=$PATH:$HOME/bin
改为:
PATH=$PATH:$HOME/bin:/usr/local/php56/bin
使 PHP 环境变量生效:
source /etc/profile
查看看 PHP 版本
php -v
PHP 5.6.0(cli)(built:Sep23201403:44:18)Copyright(c)1997-2014The PHP GroupZendEngine v2.6.0,Copyright(c)1998-2014ZendTechnologies
执行 vim /usr/local/nginx/nginx.conf 编辑nginx配置文件
然后配置.php请求被传送到后端的php-fpm模块,取消PHP配置块的注释,修改为以下内容:
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;
}
}
nginx.conf第一行,默认是#user nobody; 这里要去掉注释改为user www-data;
表示nginx服务器的权限为www
改完这些保存并退出,重启nginx:
/usr/local/nginx/nginx -s stop
/usr/local/nginx/nginx
然后编辑一个测试的php程序,在nginx下的html目录下创建test.php文件,打印php配置:
<?php
phpinfo();
?>
然后打开浏览器输入对应的地址进行访问,看到输出页面,说明nginx和php都配置成功了
原文地址:https://blog.51cto.com/14375810/2417643