1、检查selinux是否为关闭状态,不为disable需要改为disable。
SELINUX=disabled
不为disabled 的话,则修改为 SELINUX=disabled。
2、检查环境下有没有安装过低版本的
rpm -qa|grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64
rpm -qa|grep nginx
rpm -qa|grep php
从上可获知Linux下yum过一个 mysql-libs-5.1.73-8.el6_8.x86_64,等下安装MySQL5.6版本的时候,先做卸载就可以。
3、可以查看有没有mysql nginx php等相关的命令 ,有可能是源码安装过的,若有也需要卸载掉。
whereis nginx
whereis php
whereis mysql
4、关闭防火墙
刚刚新安装的系统默认的是关闭iptables的
centos 6.9默认的是nginx1.10版本,想安装nginx更高的版本可以下载nginx官网yum源进行安装,这里省略自己查看其它版本安装的参考吧。
1、删除系统自带的软件包
yum remove httpd php
2、安装nginx
yum install -y nginx
3、设置nginx开机启动
chkconfig nginx on
4、启动nginx
service nginx start
输入命令 nginx -t,这是一个判断nginx配置文件格式是否正确的命令,可以用来查找nginx配置文件的路径;
[root@Server-55e30ab1-b924-43b7-94e4-4a7c59208282 html]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
但是这里出现的配置文件是主配置文件,注意配置文件是否有扩展
[root@Server-55e30ab1-b924-43b7-94e4-4a7c59208282 html]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;###这里就出现了扩展,其他参数去扩展配置文件配置!!
}
1、检查MySQL是否有相关包
whereis mysql
mysql: /usr/lib64/mysql /usr/share/mysql
rpm -qa|grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64
卸载mysql-libs-5.1.73-8.el6_8.x86_64
yum remove mysql-libs
2、清空dbcache
yum clean dbcache
3、下载MySQL rpm安装包
wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
4、 安装MySQL安装源
使用rpm -ivh mysql-community-release-el6-5.noarch.rpm安装下载的rpm文件~
rpm -ivh mysql-community-release-el6-5.noarch.rpm
5、安装mysql-community-server
使用yum install mysql-community-server安装MySQL server。
yum install mysql-community-server
6、启动MySQL服务
service mysqld start
7、修改mysql密码
修改密码~
使用update user set password=PASSWORD("YOUR_PASSWORD") where user='root';修改root账号密码~
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> update user set password=PASSWORD("YOUR_PASSWORD") where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
密码验证
重新登录mysql服务
至此,MySQL安装完毕~
检查当前安装的PHP包
yum list installed | grep php
如果有安装的PHP包,先删除他们, 如:
yum remove php.x86_64 php-cli.x86_64 php-common.x86_64
配置安装包源:,根据具体Linux系统版本安装源。
Centos 5.X
rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
CentOs 6.x
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
CentOs 7.X
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
如果想删除上面安装的包,重新安装
rpm -qa | grep php
rpm -e [上面搜索到的包即可]
执行安装
yum -y install php56w.x86_64
yum -y --enablerepo=webtatic install php56w-devel
yum -y install php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64
安装PHP FPM
yum -y install php56w-fpm
#设置php-fpm开机启动
chkconfig php-fpm on
#启动php-fpm
/etc/init.d/php-fpm start
[root@localhost nginx]# cp /etc/nginx/conf.d/default.conf{,.bak}
[root@Server- ~]# cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
[root@localhost nginx]# service nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
[root@localhost nginx]# service php-fpm restart
Stopping php-fpm: [ OK ]
Starting php-fpm:
[root@localhost ~]# cd /usr/share/nginx/html/
[root@localhost html]# vim index.php
[root@localhost html]# chown nginx.nginx /usr/share/nginx/html/ -R #设置目录所有者
在客户端浏览器输入服务器IP地址,可以看到相关的配置信息!
安装过程可能会碰到一些问题,记录在另外一篇博客
https://blog.csdn.net/weixin_40283570/article/details/81477390
备注
nginx默认站点目录是:/usr/share/nginx/html/
权限设置:chown nginx.nginx/usr/share/nginx/html/ -R
MySQL数据库目录是:/var/lib/mysql
权限设置:chown mysql.mysql -R /var/lib/mysql
nginx 配置文件 :/etc/nginx/conf.d/default.conf
php-fpm 配置文件 :/etc/php-fpm.d/www.conf