对于一个Linux小白来说,想要非界面话安装一套环境实属不易。之前在很多地方看到过,wp最适应最快的环境是Linux,但是始终没有勇气去碰触,这段时间,我觉得应该学习一下Linux,在学习之初,先搭建这样一套环境。以下是具体的流程:
一、目前php最高稳定版本是7.2,wordpress中也建议采用该版本。若直接采用centos中的yum安装:sudo yum -y install php,默认安装版本是5.4,而我最初也是这样安装的,而我需要的php7.2,所以我必须先卸载php5.4才能安装php7.2。若你也需要卸载之前版本,请移步这篇文章xxxx
二、手动更新rpm:
- 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
然后可以利用 sudo yum list php*查看目前都有php的什么版本了,可以发现从4-7.2的版本都有,7.2版本名为72w,因此安装该版本即可:
- sudo yum -y install php72w
但安装完毕后,输入php -v发现并没有该命令,而且如果用rpm -qa|grep php查看的话,只有一个mod_php72w开头的一个小包,这是因为php72w只是安装了php最小的库,一些应用包还未安装。
三、安装一些拓展包即可:
- yum -y install php72w-cli php72w-common php72w-devel php72w-mysqlnd
对于wordpress应用,可能还需安装如下包:
- sudo yum -y install php72w-gd php72w-imap php72w-ldap php72w-odbc php72w-pear php72w-xml php72w-xmlrpc php72w-fpm php72w-mbstring php72w-pdo
然后输入php -v出现如下信息,就代表已经安装完毕:
这里特别注意一个问题,上面的安装的包里面包含了一个php-fpm,这个是需要启动的,不启动会打不开网站。所以安装php的最后一步要启动以下php-fpm,并设置为开机启动。启动命令如下:
- systemctl start php-fpm
- systemctl enable php-fpm
详情参阅https://www.inqingdao.cn/585.html
一、安装nginx
- yum install nginx
二、启动nginx服务
- systemctl start nginx
除了systemctl start nginx之外,常用的相关命令还有systemctl stop nginx、systemctl restart nginx、systemctl status nginx
三、测试nginx是否安装成功
浏览器输入ip地址或者域名(已经解析过的域名),如下图所示,则安装成功。
四、配置nginx.conf
编辑/etc/nginx/nginx.conf,命令为:
- vi /etc/nginx/nginx.conf
将原先此文件内容删除,将以下内容复制到此文件中
- # nginx运行的用户名
- user nginx;
- # nginx启动进程,通常设置成和cpu的数量相等,这里为自动
- worker_processes auto;
- # errorlog文件位置
- error_log /var/log/nginx/error.log;
- # pid文件地址,记录了nginx的pid,方便进程管理
- pid /run/nginx.pid;
- # Load dynamic modules. See /usr/share/nginx/README.dynamic.
- # 用来加载其他动态模块的配置
- include /usr/share/nginx/modules/*.conf;
- # 工作模式和连接数上限
- events {
- # 每个worker_processes的最大并发链接数
- # 并发总数:worker_processes*worker_connections
- worker_connections 1024;
- }
- # 与提供http服务相关的一些配置参数类似的还有mail
- http {
- # 设置日志的格式
- 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记录访问的用户、页面、浏览器、ip和其他的访问信息
- access_log /var/log/nginx/access.log main;
- # 这部分下面会单独解释
- # 设置nginx是否使用sendfile函数输出文件
- sendfile on;
- # 数据包最大时发包(使用Nagle算法)
- tcp_nopush on;
- # 立刻发送数据包(禁用Nagle算法)
- tcp_nodelay on;
- # 链接超时时间
- keepalive_timeout 65;
- # 这个我也不清楚…
- types_hash_max_size 2048;
- # 引入文件扩展名与文件类型映射表
- include /etc/nginx/mime.types;
- # 默认文件类型
- default_type application/octet-stream;
- # Load modular configuration files from the /etc/nginx/conf.d directory.
- # See http://nginx.org/en/docs/ngx_core_module.html#include
- # for more information.
- #include /etc/nginx/conf.d/*.conf;
- # http服务上支持若干虚拟主机。
- # 每个虚拟主机一个对应的server配置项
- # 配置项里面包含该虚拟主机相关的配置。
- server {
- listen 80 default_server;
- listen [::]:80 default_server;
- # 这里改动了,也可以写你的域名
- server_name c21.inqingdao.cn;
- root /usr/share/nginx/html;
- # Load configuration files for the default server block.
- include /etc/nginx/default.d/*.conf;
- location / {
- # 这里改动了 定义首页索引文件的名称
- index index.php index.html index.htm;
- }
- error_page 404 /404.html;
- location = /40x.html {
- }
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- }
- # 这里新加的
- # PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.
- # Fastcgi服务器和程序(PHP,Python)沟通的协议.
- location ~ \.php$ {
- # 设置监听端口
- fastcgi_pass 127.0.0.1:9000;
- # 设置nginx的默认首页文件(上面已经设置过了,可以删除)
- fastcgi_index index.php;
- # 设置脚本文件请求的路径
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- # 引入fastcgi的配置文件
- include fastcgi_params;
- }
- }
- }
当然,这个配置文件可以根据自己的网站就进行修改。
一、CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载。
补充yum源(1)
- wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
补充yum源(2)
- rpm -ivh mysql-community-release-el7-5.noarch.rpm
二、安装MySql
- yum install mysql-community-server
三、成功安装之后启动mysql服务
- systemctl start mysqld
四、登录并修改密码(推荐方法一)
方法一:
默认mysql安装后,没有密码,我们用root登录以后,设置一下root密码即可。
- mysql -u root -p
弹出输入密码框,回车即可,没有密码。然后会 进入mysql命令行中,我们执行
- set password for root@localhost=password(‘123456‘);
123456是我们要设置的密码,最后我们刷新下mysql表权限
- flush privileges;
最后退出mysql即可。
方法二:
先修改mysql配置文件使其可以无密码登录,让后修改密码,之后便复原配置文件,修改/etc/my.cnf命令:
- vim /etc/my.cnf
进入编辑文件后,在配置文件相应位置添加skip-grant-tables
- [root@izm5ej51mjmct3z ~]# vim /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
- [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
- #
- # Remove leading # to turn on a very important data integrity option: logging
- # changes to the binary log between backups.
- # log_bin
- #
- # 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
- datadir=/var/lib/mysql
- socket=/var/lib/mysql/mysql.sock
- skip-grant-tables 此处!!!!!!
- # Disabling symbolic-links is recommended to prevent assorted security risks
- symbolic-links=0
保存退出,然后重启mysql服务
- systemctl restart mysql
即可免密登录,命令行输入mysql直接登录,然后选择mysql数据库,输入下列命令重置密码,’新密码’即为所设置密码
- USE mysql
- mysql> UPDATE user SET Password = ‘新密码’ WHERE User = ‘root’;
修改完成后输入exit退出mysql,重新回到/etc/my.cnf该文件删除之前添加语句保存退出即可。