本文章是自己在配置服务器环境的时候摸索总结的方法,都是自己亲测可用的,在此做个分享。免得时间长了,忘记了。文章写于一年前,个人服务器关闭才搬迁到这里的。
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
sudo yum install -y nginx
sudo systemctl start nginx.service
sudo systemctl enable nginx.service #设置开机启动
systemctl is-enabled nginx.service;echo $? #显示 enbaled 则设置开机启动成功
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum localinstall mysql-community-release-el7-5.noarch.rpm -y
yum repolist all | grep mysql
vi /etc/yum.repos.d/mysql-community.repo
打开文件看到如下代码
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
其中 enabled=0
是指禁用, enabled=1
指启用, 任何时候,只能启用一个版本。修改 5.6 为禁用,启用 5.7,即修改[mysql56-community]
下的 enabled=0
,[mysql57-community]
下的 enabled=1
关闭文件后再次执行 yum repolist all | grep mysql
可以发现5.7版本的打开了
yum install mysql-community-server -y
此处的安装需要等待一段时间,若网速慢则需要的时间更长.
rpm -qi mysql-community-server.x86_64 0:5.6.24-3.el7 #查看详细信息
systemctl start mysqld #启动 MySQL
systemctl status mysqld #查看 MySQL 状态
systemctl stop mysqld #关闭mysql
/var/log/mysqld.log
中,执行grep "password" /var/log/mysqld.log
获取密码。 成功登录则代表 MySQL 安装成功。 由于登陆密码是默认密码是不允许直接使用的需要修改root密码,数据库中执行 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
修改密码,newpass表示自己设置的新密码,对密码要求包含数字、大小写字母、特殊符号四种,否则不能通过/etc/my.cnf
文件 [mysqld]
character_set_server = utf8 #注意写在[mysqld]下面,不能随便放,下面的同理
[mysql]
default-character-set = utf8
SHOW VARIABLES LIKE 'character%';
命令,可以看到字符集已经变成 UTF-8yum -y install gcc gcc-c++ libxml2 libxml2-devel autoconf automake pcre-devel zlib zlib-devel bzip2 bzip2-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel curl-devel expat-devel gettext-devel zlib-devel
以上的依赖包有这个可能安装不了libmcrypt libmcrypt-devel libtidy libtidy-devel
,貌似也没有影响
mkdir /home/download && cd /home/download #下载到任何地方都可以
wget http://cn2.php.net/distributions/php-7.2.0.tar.gz #当时下载的7.2,可下载更高版本
tar -zxvf php-7.2.0.tar.gz
cd php-7.2.0
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-opcache --with-gd --with-iconv --with-zlib --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-calendar --with-openssl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --with-curl --with-jpeg-dir --with-freetype-dir --with-mysqli --enable-embedded-mysqli --with-pdo-mysql
make && make install
sudo cp php.ini-production /usr/local/php/etc/php.ini
sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
sudo chmod +x /etc/init.d/php-fpm
sudo cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
sudo cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
sudo cp /usr/local/php/bin/php /usr/bin/php
/usr/local/php/bin/php -v
显示下面的结果表示安装完成PHP 7.1.4 (cli) (built: May 1 2017 00:26:16) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _; #这里可以配置域名
root /var/www; #这里配置项目目录
index index.php index.html index.htm;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ \.php$ {
root /var/www; #这里配置项目目录和上面一样
fastcgi_pass 127.0.0.1:9000;
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
service nginx restart #重启 Nginx
service php-fpm restart # 重启 php-fpm