零、写在前面
- 这是为了优化之前的版本,之前的版本请移步 Linux下部署PHP_YAF框架 查看
- 这篇跟之前那篇的区别就是:
1、优化了阅读
,2、加上了:Linux下部署WordPress
一、基本命令
pwd
当前路径ls
当前路径下的所有内容find / -name nginx.conf
查找nginx.conf文件所在的位置php -v
php版本php -m
php扩展Is this ok [y/d/N]:
一律y
二、Linux下安装Mysql
1、安装Mysql
wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
rpm -Uvh mysql57-community-release-el7-7.noarch.rpm
yum install mysql-community-server
yum install mysql-community-client
2、修改默认mysql密码
1)、查看mysql默认密码命令
- 先启动mysql:
systemctl restart mysqld
:启动-start;停止-stop;重启-restart - 再查看mysql密码:
grep 'temporary password' /var/log/mysqld.log
2)、登录mysql
mysql -uroot -p
- 我们输入password时直接输,密码不会显示
3)、修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Test&2018!bbb';
- 一定要包含:数字、字母、特殊字符,否则不给过
3、设置mysql root用户能过远程访问(可以在windows用图形化软件(navicat premium)连接)
show databases; //查看数据库
use mysql; //使用mysql表
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1; //更改用户表[允许所有的ip远程访问]
flush privileges; //强制刷新权限
exit; //退出mysql
4、重启mysql
service mysqld restart
三、Linux下安装PHP
1、更新yum源
首先要更新yum源,不然是默认的老版本,一般都在5.6及以下,但是php7都出来好久了,性能提升50%以上!
2、查看版本并更新
- 查看Linux CentOS 版本命令:
cat /etc/redhat-release
- CentOS版本7.0+:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
- CentOS版本6.0+:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
3、yum安装php
- 安装的拓展如下:
yum install php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel
- 安装命令(安装了一些扩展 redis,mysqlnd…)
yum install php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel
yum install -y memcached redis
- 启动PHP
systemctl start php-fpm
四、Linux下安装nginx
1、安装nginx
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx
2、启动nginx
service nginx start
systemctl start nginx
- 效果图
3、nginx.conf配置项目路径,wordpress的默认入口是根目录下的index.php文件
- nginx.conf配置文件内容:配置端口为8081,项目路径为
/var/www/web/shop/public
server {
listen 8081;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
fastcgi_buffer_size 1M;
fastcgi_buffers 32 512k;
fastcgi_busy_buffers_size 1M;
root /var/www/web/wordpress;
location / {
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/(.*) /index.php?$1 last;
}
}
#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 html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
五、其他
1、Linux下安装apache
- 安装apache:
yum install httpd
- 设置自启:
systemctl enable httpd.service
2、开始结束命令
1、讲解
service application status => 命令符 应用 状态
- 命令符
service
- 应用
nginx|php-fpm|mysql/mysqld|apache|httpd
- 状态
start|stop|reload|restart|status|help
2、使用
- systemctl 命令使用
systemctl #输出已激活单元
systemctl list-units #输出已激活单元
systemctl --failed #输出运行失败的单元
systemctl list-unit-files #查看所有已安装服务
systemctl start nginx #启动nginx
systemctl stop nginx #停止nginx
systemctl restart nginx #重启nginx
systemctl reload nginx #重新加载nginx配置
systemctl status nginx #输出nginx运行状态
systemctl is-enabled nginx #检查nginx是否配置为自动启动
systemctl enable nginx #开机自动启动nginx
systemctl disable nginx #取消开机自动启动nginx
systemctl help nginx #显示nginx的手册页
systemctl daemon-reload #重新载入 systemd,扫描新的或有变动的单元
systemctl reboot #重启
systemctl poweroff #退出系统并停止电源
systemctl suspend #待机
systemctl hibernate #休眠
systemctl hybrid-sleep #混合休眠模式(同时休眠到硬盘并待机
systemctl isolate graphical.target #等价于telinit 3 或 telinit 5
3、安装PHP扩展遇到的问题
1、安装GCC软件套件
- 安装PHP扩展要注意扩展的版本号和php的版本号是否对应
- configure: error: no acceptable C compiler found in $PATH [安装GCC软件套件]
yum install gcc-c++ libstdc++-devel
y (确定)
2、安装OpenSSL
- Cannot find OpenSSL’s <evp.h>
yum install openssl openssl-devel
y (确定)