nginx版本 1.14.0
mysql版本 5.7.20
php版本 5.6.40
wget http://mirrors.aliyun.com/repo/Centos-7.repo -P /etc/yum.repos.d/ #这里安装的是阿里的网络源,epel扩展源,也可以安装阿里的,但是阿里的epel源有些包不全,所以下面就直接用yum安装网络epel源
yum -y install epel-release
ls /etc/yum.repos.d/
yum clean all;yum makecache
2.1安装依赖包
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre*
2.2创建nginx运行用户
useradd -M -s /sbin/nologin nginx
2.3.下载pcre包(放到/usr/local/src下面)
cd /usr/local/src
wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.zip
unzip pcre-8.42.zip
2.4下载nginx并解压安装
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar -zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0
#配置
./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --user=nginx --group=nginx --with-pcre=/usr/local/src/pcre-8.42
2.5 编译安装
make && make install
2.6修改配置文件
vim /usr/local/nginx/conf/nginx.conf
usr/local/nginx/sbin/nginx -t #检查nginx语法是否正确
vim /etc/profile #添加环境变量
source /etc/profile
vim /etc/init.d/nginx
输入以下内容:
#!/bin/bash
# chkconfig: 2345 99 20
#description: nginx-server
nginx=/usr/local/nginx/sbin/nginx
case $1 in
start)
netstat -anptu | grep nginx
if [ $? -eq 0 ]
then
echo "nginx service is already running"
else
echo "nginx Service started successfully "
$nginx
fi
;;
stop)
$nginx -s stop
if [ $? -eq 0 ]
then
echo "nginx service closed successfully"
else
echo "nginx server stop fail,try again"
fi
;;
status)
netstat -anlpt | grep nginx
if [ $? -eq 0 ]
then
echo "nginx server is running"
else
echo "nginx service not started "
fi
;;
restart)
$nginx -s reload
if [ $? -eq 0 ]
then
echo "nginx service restart successfully "
else
echo "nginx server restart failed"
fi
;;
*)
echo "please enter {start restart status stop}"
;;
esac
配置脚本的权限并设置开机启动
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
3.1卸载系统自带的mariadb
yum -y remove mariadb* boost-*
3.2安装依赖包
yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel
3.3下载源码包,并解压
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.20.tar.gz
tar -zxvf mysql-boost-5.7.20.tar.gz
3.4安装
cd mysql-5.7.20/
#配置
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/src/mysql-5.7.20/boost/boost_1_59_0 -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql
#编译安装
make
make install
3.5创建数据库用户和数据目录
useradd -M -s /sbin/nologin -r mysql
mkdir -p /usr/local/mysql/data #创建数据存储目录
chown -R mysql.mysql /usr/local/mysql/ #更改属主数组为MySQL
3.6配置mysql的配置文件
vim /etc/my.cnf
#输入下面的内容
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
symbolic-links=0
user=root
character-set-server=utf8
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/usr/local/mysql/mysqld.pid
[client]
socket=/usr/local/mysql/mysql.sock
3.7配置mysql启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld #复制启动脚本到/etc/init.d
chkconfig --add mysqld #添加到开机启动项
chkconfig mysqld on #添加开机自启动
#配置mysql目录和数据存放目录
vim /etc/init.d/mysqld
vim /etc/profile #配置环境变量,增加mysql
#增加下面这一行
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
3.8安全初始化数据库
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data #这样初始化之后,数据库是没有密码的
/etc/init.d/mysqld start #启动数据库
mysql -uroot #登录数据库修改root用户密码
alter user 'root'@'localhost' identified by '123456'; #修改root密码为123
exit #退出数据库
mysql -uroot -p #重新登录数据库,需要密码
4.1安装依赖包
yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c net-snmp-devel libjpeg-devel php-ldap openldap-devel openldap-servers openldap-clients freetype-devel gmp-devel
4.2下载php源码包(下面的下载地址可以选择你需要的php版本)
cd /usr/local/src
wget http://cn2.php.net/distributions/php-5.6.40.tar.gz
tar -zxf php-5.6.40.tar.gz
cd php-5.6.40
#配置
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-pdo-mysql --with-mysql-sock=/usr/local/mysql/mysql.sock --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-curl --with-gd --with-gmp --with-zlib --with-xmlrpc --with-openssl --without-pear --with-snmp --with-gettext --with-mhash --with-libxml-dir=/usr --with-fpm-user=nginx --with-fpm-group=nginx --enable-xml --enable-fpm --enable-ftp --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-sockets --enable-inline-optimization --enable-maintainer-zts --enable-mbregex --enable-mbstring --enable-pcntl --enable-zip --disable-fileinfo --disable-rpath --enable-libxml --enable-opcache --enable-mysqlnd
make
make install
4.4配置php配置文件
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #移动php配置文件的位置,并修改名称
cp /usr/local/src/php-5.6.40/php.ini-production /usr/local/php/etc/php.ini #复制一份php.ini配置文件
4.5复制php启动脚本,并添加开机启动
cp /usr/local/src/php-5.6.40/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #复制启动脚本
chmod +x /etc/init.d/php-fpm #添加执行权限
chkconfig --add php-fpm #添加开启启动
chkconfig php-fpm on
4.6启动php-fpm
/etc/init.d/php-fpm start
cd /usr/local/nginx/html
vim test.php
在test.php打印phpinfo即可(以下是我的腾讯云的公网ip地址)
注:新买的腾讯云服务器,通过公网ip访问,有可能打不开,这是因为防火墙没有开启80端口,在防火墙开放80端口即可,在腾讯云的控制台的安全组里面也需要开放80端口。
systemctl status firewalld #查看防火墙是否开启
firewall-cmd --list-ports #查看防火墙已经开放的端口
firewall-cmd --zone=public --add-port=80/tcp --permanent #防火墙开放80端口,根据此命名可以开放常用端口,如 3306(mysql), 6379(redis)等等。
systemctl restart firewalld #重启防火墙,配置才生效