一、nginx安装
1、下载nginx并安装依赖
nginx官网下载最新稳定版本(Stable version),http://nginx.org/en/download.html 。
cd /usr/local/src
wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar -zxvf nginx-1.12.1.tar.gz
安装依赖
yum -y install pcre-devel openssl openssl-devel gcc gcc-c++ ncurses-devel perl
2、编译安装
cd /usr/local/src/nginx-1.12.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
make && make install
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
开启 nginx
/usr/local/nginx/sbin/nginx
二、php7安装
1、安装依赖包
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel epel-release autoconf m4
2、下载php源码
php源码下载地址:http://php.net/downloads.php
cd /usr/local/src
wget http://cn2.php.net/distributions/php-7.1.7.tar.gz
tar zxvf php-7.1.7.tar.gz
cd php-7.1.7
若服务器无nginx用户与组,则添加 useradd nginx
3、编译安装
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--enable-pcntl \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
make && make install
编译说明:--enable-gd-jis-conv \ 这个参数尽量不要添加,不然gd生成图片无法插入中文。中文会被认为是日文。详见php官方bug https://bugs.php.net/bug.php?id=42218
4、配置
添加环境变量
vim /etc/profile 在末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH
执行 source /etc/profile
这时候即可查看php版本 php -v
配置php-fpm(php版本为7.x)
cd /usr/local/src/php-7.1.7
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
配置php-fpm(php版本为5.x)
cp /usr/local/src/php-5.6.29/php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/src/php-5.6.29/php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
/usr/local/php/sbin/php-fpm
启动php-fpm(php版本5.x 在前文中已经启动,所以不需要再启动)
/etc/init.d/php-fpm start
相关优化
查找php.ini位置 php -i |grep php.ini
1、修改 /etc/php.ini 的默认时间区域为 date.timezone = PRC
修改参数后,记得重启php-fpm
5、配置nginx与php
cd /usr/local/nginx/conf
vim nginx.conf
把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
/usr/local/nginx/sbin/nginx -s reload
三、mysql5.6安装
1、先检查有无mariadb的包 #若为centos7以下版本,则检查mysql
rpm -qa|grep mariadb
#若为centos7以下版本 则rpm -qa|grep mysql
若有,则删掉包及依赖 rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64
2、下载 解压mysql
cd /usr/local/src
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64
mv mysql-5.6.33-linux-glibc2.5-x86_64 ../mysql
3、在mysql目录更改组和用户,data目录初始化
cd /usr/local/mysql
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql ./
yum install -y perl-Module-Install.noarch libaio* #centos7以下版本,不需执行这一行命令
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
chown -R root ./
chown -R mysql data
4、复制配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
5、将mysqld服务加入开机自启动项
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
通过chkconfig命令将mysqld服务加入到自启动服务项中 chkconfig --add mysqld
检查是否添加成功 chkconfig --list mysqld
6、开启mysql
service mysqld start
7、连接mysql
/usr/local/mysql/bin/mysql
8、将mysql加入环境变量
vi /etc/profile
在文件最后加上2行代码
MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
再执行命令让其生效 source /etc/profile
试试 mysql ,则可以连接上数据库
9、修改mysql密码,并设置其可远程连接数据库
use mysql;
update user set Password=password('123456') where Host='localhost' and User='root';
delete from user where Password='';
若mysql为5.7版本
update user set authentication_string = password('123456'), password_expired = 'N', password_last_changed = now() where user = 'root';
设置用户为root密码为123456 的用户,可以远程连接mysql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
或 GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //为root用户设置远程能力
flush privileges;