参照链接:http://blog.csdn.net/bravemelon/article/details/64925499
centOS 7 下安装 Nginx
yum -y groupinstall "Development Tools"
yum -y install wget
yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof
1.直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html
2.使用wget命令下载(推荐)。
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
解压
依然是直接命令:
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
配置
1.使用默认配置(推荐)
./configure
2.自定义配置(不推荐)
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录
编译安装
make
make install
查找安装路径:
whereis nginx
启动、停止nginx
cd /usr/local/nginx/sbin/
./nginx
[root@ecs-24--jenjins sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
问题描述:地址已被使用。可能nginx服务卡死了,导致端口占用,出现此错误。
解决:
kill -9 3274
kill -9 3547
或者 killall -9 nginx
从新载入配置文件启动 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
二、修改配置文件
1、以下的配置文件没用的都删除
[root@ecs-24--jenjins conf]# cat nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.jenjins_1.com;
access_log logs/hongfa1.access.log main;
location / {
root /web/hongfa1;
index index.html index.htm;
}
}
server {
listen 8084;
server_name www.jenjins_2.com;
access_log logs/hongfa3.access.log main;
location / {
root /web/hongfa3;
index index.html index.htm;
}
}
server {
listen 8083;
server_name www.jenjins_3.com;
access_log logs/hongfa3.access.log main;
location / {
root /web/hongfa5;
index index.html index.htm;
}
}
}
2、没有搭建本地DNS,就配置hosts解析文件,都是一样的效果
[root@ecs-24--jenjins ~]# cat /etc/hosts
127.0.0.1 ecs-24--jenjins
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 localhost
117.78.44.225 www.jenjins_1.com
117.78.44.225 www.jenjins_2.com
117.78.44.225 www.jenjins_3.com
117.78.44.225 www.jenjins_4.com
3、配置html虚拟机文件
在根目录下创建这几个文件
/web/hongfa4/index.html hongfa4 222222222
/web/hongfa5/index.html <h1>www.hongfa2.com</h1>
/web/hongfa1/index.html <h1>www.hongfa1.com</h>
/web/hongfa3/index.html <h1>www.hongfa3.com</h1>
4、设置防火墙,把80端口映射到 8081,8082,8083 ,8080不能用,因为nginx首页已经占用,而80 端口要占一个,
[root@localhost ]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 这句话非常重要,下面两句可以不执行,要多执行几次
[root@localhost ]# /etc/init.d/iptables save
[root@localhost ]# /etc/init.d/iptables restart ---如果不行,用下面的。
[root@ecs-24--jenjins hongfa1]# systemctl restart firewalld
至此,主机已可访问虚拟机的nginx服务。
下面可以不执行,好像是,不能访问,执行试试,也可以写到iptables配置文件里
iptables -A INPUT -p tcp -m tcp --dport 8084 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 8083 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 8081 -j ACCEPT
5、开始访问
5.1 http://117.78.44.225:80
www.hongfa1.com
5.2 http://117.78.44.225:8081
hongfa4 222222222
5.3 http://117.78.44.225:8083
www.hongfa2.com
5.4 http://117.78.44.225:8084
www.hongfa3.com
三、搭建mysql
http://www.jianshu.com/p/95a103add722
Centos 7.2 编译安装 MySQL 5.7.14
一、环境准备
1、查看系统版本
1
2
3
4
[root@lnmp ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@lnmp ~]# uname -r
3.10.0-327.28.2.el7.x86_64
2、卸载系统自带的mysql/mariadb数据库及boost旧版本
复制代码
rpm -qa | grep mysql
rpm -qa | grep mariadb
rpm -e --nodeps boost-system-1.53.0-25.el7.x86_64
rpm -e --nodeps boost-thread-1.53.0-25.el7.x86_64
rpm -e mariadb-libs-5.5.47-1.el7_2.x86_64
rpm -e --nodeps mariadb-libs-5.5.47-1.el7_2.x86_64
boost官网http://www.boost.org/ ,yum -y install boost boost-devel boost-doc安装的是boost1.53版本
3、准备安装文件
复制代码
[root@lnmp mysql]# ll
total 131096
drwx------ 10 501 games 4096 Aug 17 15:02 boost_1_59_0
-rw-r--r-- 1 root root 83709983 Aug 13 2015 boost_1_59_0.tar.gz
drwxr-xr-x 37 7161 31415 4096 Aug 17 15:48 mysql-5.7.14
-rw-r--r-- 1 root root 50517329 Aug 17 14:38 mysql-5.7.14.tar.gz
说明:mysql5.7系列指定boost版本为boost_1_59_0。
资源下载地址:
[root@snails ~]# wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
[root@snails ~]# wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz
4、依赖包安装
yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio libaio-devel perl-Data-Dumper net-tools
二、安装boost/mysql
1、安装boost
1 tar xvf boost_1_59_0
2 cd boost_1_59_0
3 ./bootstrap.sh --with-libraries=system,filesystem,log,thread --with-toolset=gcc
4 ./b2 toolset=gcc cxxflags="-std=c++11"
5 ./b2 install --prefix=/usr/local/boost
#备注:上面红色字体的内容,参考如下配置;上面绿色字体内容代表使用c++11标准,编译的库要使用统一标准。不使用,去掉绿色字体内容。
复制代码
1 Component configuration:
2 - atomic : not building
3 - chrono : not building
4 - context : not building
5 - coroutine : not building
6 - date_time : not building
7 - exception : not building
8 - filesystem : building
9 - graph : not building
10 - graph_parallel : not building
11 - iostreams : not building
12 - locale : not building
13 - log : building
14 - math : not building
15 - mpi : not building
16 - program_options : not building
17 - python : not building
18 - random : not building
19 - regex : not building
20 - serialization : not building
21 - hongfa4nals : not building
22 - system : building
23 - test : not building
24 - thread : building
25 - timer : not building
26 - wave : not building
#默认安装在/usr/local/lib目录下;头文件在/usr/local/include/boost目录下;install后面可以加参数 --prefix=/usr 来设置安装路径
#如果提示boost版本不对应则卸载boost安装对应版本boost
新建MySQL用户和用户组
[root@snails ~]# groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
预编译
[root@snails ~]# tar -zxvf boost_1_59_0.tar.gz
[root@snails data]# md5sum mysql-5.7.13.tar.gz
8fab75dbcafcd1374d07796bff88ae00 mysql-5.7.13.tar.gz
[root@snails ~]# tar -zxvf mysql-5.7.13.tar.gz
[root@snails data]# mkdir -p /data/mysql
[root@snails data]# cd mysql-5.7.13
[root@snails data]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DWITH_BOOST=../boost_1_59_0 \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1
编译安装
[root@snails mysql-5.7.13]# make -j `grep processor /proc/cpuinfo | wc -l`
#编译很消耗系统资源,小内存可能编译通不过make install
[root@snails mysql-5.7.13]# make install
三、配置mysql
1、创建用户,初始化数据库
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
2、授权mysql数据库目录
chown -R mysql:mysql /usr/local/mysql
3、初始化mysql数据库
/usr/local/mysql/bin/mysqld \
--initialize \
--user=mysql \
--datadir=/usr/local/mysql/data/
4、拷贝配置文件,修改配置文件
复制代码,按照下面的修改一下,修改之后无法加载配置文件,没关系,可能编译有问题
1 cp support-files/my-default.cnf /etc/my.cnf
2 [root@lnmp ~]# cat /etc/my.cnf
3 # For advice on how to change settings please see
4 # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
5 # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
6 # *** default location during install, and will be replaced if you
7 # *** upgrade to a newer version of MySQL.
8 [mysqld]
9 # Remove leading # and set to the amount of RAM for the most important data
10 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
11 # innodb_buffer_pool_size = 128M
12 character_set_server=utf8
13 init_connect='SET NAMES utf8'
14 #skip-grant-tables
15 # Remove leading # to turn on a very important data integrity option: logging
16 # changes to the binary log between backups.
17 # log_bin
18 # These are commonly set, remove the # and set as required.
19 # basedir = .....
20 #datadir = /usr/local/mysql/data
21 # port = .....
22 # server_id = .....
23 # socket = .....
24 # Remove leading # to set options mainly useful for reporting servers.
25 # The server defaults are faster for transactions and fast SELECTs.
26 # Adjust sizes as needed, experiment to find the optimal values.
27 # join_buffer_size = 128M
28 # sort_buffer_size = 2M
29 # read_rnd_buffer_size = 2M
30 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
31 [client]
32 default-character-set=utf8
复制代码
root@ecs-24--jenjins www.test.com]# source /etc/my.cnf -------------没关系,没有影响
bash: [mysqld]: command not found...
5、拷贝启动文件,并授权
1、cp support-files/mysql.server /etc/init.d/mysqld
2、chmod 755 /etc/init.d/mysqld
6 、启动数据库
/etc/init.d/mysqld start
三、更改初始化生成的数据库密码
注:由于5.7版本会初始化设置密码,需要自己修改,跟之前的数据库版本更改方式不一样。
完整的更改MySQL密码的方式如下:
vim /etc/my.cnf 加入skip-grant-tables,免密码登录数据库
[root@ecs-24--jenjins mysql-5.6.17]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
character_set_server=utf8
init_connect='SET NAMES utf8'
skip-grant-tables -------------加上这句话,免密登陆,登陆完再删掉。
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
default-character-set=utf8
重启MySQL数据库
[root@lnmp ~]# /etc/init.d/mysqld restart ----------或者service mysqld start
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
登录数据,修改密码即可,注5.7的password字段改为authentication_string
MySQL
update mysql.user set authentication_string=password('pwd123') where user='root' ;
改完后,注释掉my.cnf里面的skip-grant-tables 这一行,重启MySQL登录验证即可,然后就可以登录数据库进行一些简单的操作了。
[root@lnmp ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.14 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)
四、授权所有用户登陆
mysql> grant all privileges on *.* to 'root'@'%' identified by 'pwd123';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
四、安装php7
Centos7 安装 PHP7最新版的详细教程
http://www.jb51.net/article/109228.htm
方法一、简单安装(通过yum)
1.安装epel-release
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
2.安装PHP7的rpm源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3.安装PHP7
yum install php70w
放法二、编译安装
1.下载php7
wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror
2.解压php7
tar -xvf php7.tar.gz
3.进入php目录
cd php-7.1.1/
4.安装依赖包
yum install epel-release gcc gcc-c++ 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 -y
5.编译配置(如果出现错误,基本都是上一步的依赖文件没有安装所致)
编译前做一下这些,防止出错
[root@ecs-24--jenjins ~]# cd /usr/local/
[root@ecs-24--jenjins local]# mkdir php
[root@ecs-24--jenjins 42]# mount
[root@ecs-24--jenjins 42]# umount /run/user/42/gvfs
./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 \
--with-sqlite3 \
--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 \
--enable-gd-jis-conv \
--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-pdo-sqlite \
--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
6.正式安装
make && make install
编译最后出现错误:collect2: error: ld returned 1 exit status
解决:
[root@ecs-24--jenjins php-7.1.1]# make ZEND_EXTRA_LIBS='-liconv'
[root@ecs-24--jenjins php-7.1.1]# ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
[root@ecs-24--jenjins php-7.1.1]# make && make install
7.配置环境变量
vi /etc/profile
在末尾追加
export PATH=$PATH:/usr/local/php/bin
执行命令使得改动立即生效
source /etc/profile
sed -i '$a\export PATH=$PATH:/usr/local/php/bin' /etc/profile && source /etc/profile
8.配置php-fpm
cp /usr/local/php-7.1.1/php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
如果报错按照下面做
[root@ecs-24--jenjins ~]# find / -name php-fpm.conf.default
find: ‘/run/user/42/gvfs’: Permission denied
[root@ecs-24--jenjins 42]# mount 看最后一行
[root@ecs-24--jenjins 42]# umount /run/user/42/gvfs
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp /usr/local/php-7.1.1/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
9.启动php-fpm
/etc/init.d/php-fpm start
错误:
Starting php-fpm [09-Aug-2014 00:45:40] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address
already in use (98)
[09-Aug-2014 00:45:40] ERROR: FPM initialization failed
failed
解决方法:
netstat -lntup | grep 9000
killall php-fpm
[root@www ~]# service php-fpm start
Starting php-fpm done 启动成功
下面的错误不用管,没有影响
[root@ecs-24--jenjins www.test.com]# source /etc/php.ini -----------------不用管,没有影响
bash: [PHP]: command not found...
-bash: /etc/php.ini: line 2: syntax error near unexpected token `;;'
-bash: /etc/php.ini: line 2: `;;;;;;;;;;;;;;;;;;;'
五、测试访问
[root@localhost ]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT -----------------无法访问就执行这句话
root@localhost ]# /etc/init.d/iptables save
[root@localhost ]# /etc/init.d/iptables restart
[root@ecs-24--jenjins hongfa1]# systemctl restart firewalld
一、全部删了配置文件,赋值下面的。
root@ecs-24--jenjins html]# cat /usr/local/nginx/conf/nginx.conf
user root root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server {
listen 80;
server_name www.test.com;
charset utf-8;
location / {
root /var/www/www.test.com;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/www.test.com$fastcgi_script_name;
include fastcgi_params;
}
}
}
[root@ecs-24--jenjins ~]# mkdir -p /var/www/www.test.com/
[root@ecs-24--jenjins ~]# cd /var/www/www.test.com/
[root@ecs-24--jenjins ~]#touch index.php
[root@ecs-24--jenjins ~]#vi index.php
<?php
phpinfo();
?>
[root@ecs-24--jenjins www.test.com]# chown -R 777 /var/www/www.test.com/
[root@ecs-24--jenjins www.test.com]# vi /etc/hosts
127.0.0.1 ecs-24--jenjins
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 localhost
117.78.44.225 www.test.com
[root@ecs-24--jenjins www.test.com]# curl http://117.78.44.225/index.php
二、测试mysql连接是否成功
[root@ecs-24--jenjins ~]# cd /var/www/www.test.com/
[root@ecs-24--jenjins ~]#touch index.php
[root@ecs-24--jenjins ~]#vi index.php
[root@ecs-24--jenjins www.test.com]# cat index.php
<?php
$conn=mysqli_connect("127.0.0.1","root","123");
if($conn){
echo "连接mysql数据库成功";
}else{
echo "连接数据库失败";
}
?>
[root@ecs-24--jenjins www.test.com]# curl http://117.78.44.225/index.php
连接mysql数据库成功
报错:
原因: centos php7怎么添加mysql支持
php7可以通过pod_mysql或者mysqli来开启mysql的支持php5中mysql扩展,在php7中已经不支持了。
一、正确做法
<?php
$conn=mysqli_connect("127.0.0.1","root","pwd123"); 注意mysqli_connect 多个i
if($conn){
echo "连接mysql数据库成功";
}else{
echo "连接数据库失败";
}
?>
错误的
<?php
$conn=mysql_connect("127.0.0.1","root","pwd123"); 注意mysql_connect 少个i
if($conn){
echo "连接mysql数据库成功";
}else{
echo "连接数据库失败";
}
?>
六:上传web网站
http://www.2cto.com/net/201612/577868.html