1.安装nginx
#1.下载rpm包
wget https://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.20.2-1.el7.ngx.x86_64.rpm
#2.安装
rpm -ivh nginx-1.20.2-1.el7.ngx.x86_64.rpm
#3.启动
systemctl start nginx
#4.加入开机启动
systemctl enable nginx
#5.查找nginx的路径
find / -name nginx
2.安装php7.4
#1.添加第三方rpm源
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
#2.安装 这里是安装php相关的拓展模块,可以根据自己的需要进行增删,
#下面列出的模块,除了redis和swoole外,其他基本都是必须模块
yum install -y php74-php-fpm php74-php-cli php74-php-bcmath php74-php-gd php74-php-json php74-php-mbstring php74-php-mcrypt php74-php-mysqlnd php74-php-opcache php74-php-pdo php74-php-pecl-crypto php74-php-pecl-mcrypt php74-php-pecl-geoip php74-php-recode php74-php-snmp php74-php-soap php74-php-xml php74-php-imagick php74-php-pecl-zip php74-php-redis php74-php-swoole
#3.启动
systemctl start php74-php-fpm
#4.添加开机启动
systemctl enable php74-php-fpm
#5.查看版本
cp /usr/bin/php74 /usr/bin/php #如果不复制的话,所有的php 替换成php74
chmod +x /usr/bin/php #文件给与执行权限
php -v
#6.查看已安装模块
php -m
#7.查看配置信息(相当于phpinfo)
php -i
#8.编辑php-fpm的配置 一般来说php-fpm的配置文件都是www.conf,如果不知道文件路径,可以find以下
find / -name www.conf
#查找的结果
/etc/opt/remi/php74/php-fpm.d/www.conf
vim /etc/opt/remi/php74/php-fpm.d/www.conf
#查找到user 和 group 修改为 nginx (这里是nginx.conf中的user参数,不知道的话 在/etc/nginx/nginx.conf中找一下)
#也就是说php-fpm的用户和nginx的用户一致
#将listen_mode 取消注释,并将权限修改为0777
#然后保存,重启php-fpm
结果如下
; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or @php_fpm_prefix@) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000
; Set listen(2) backlog.
; Default Value: 511
;listen.backlog = 511
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server.
; Default Values: user and group are set as the running user
; mode is set to 0660
;listen.owner = nobody
;listen.group = nobody
listen.mode = 0777
3.修改nginx的default.conf
vim /etc/nginx/conf.d/default.conf
#修改结果如下
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
#access_log /var/log/nginx/host.access.log main;
location / {
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 html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$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;
#}
}
修改完成后重启nginx,然后在/usr/share/nginx/html下创建一个index.php的文件,里面加入echo phpinfo()的代码,操作如下
vim /usr/share/nginx/html/index.php
#输入如下内容
<?php
echo phpinfo();
然后在浏览器中输入服务器ip,就能查看服务器的php的配置信息。
4.安装mysql
1 、删除 MariaDBcentos7.6自带的 MariaDB(MariaDB是MySQL的一个分支),与要安装的MySQL有冲
突,需要删除。
# 查询是否安装了
mariadb rpm -aq | grep mariadb
# 删除mariadb。-e 删除指定的套件;--nodeps 不验证套件的相互关联性
rpm -e --nodeps mariadb-libs 12345
2 、安装依赖
yum install perl -y
yum install net-tools -y
3、安装MySQL
# 解压缩
tar xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
# 依次运行以下命令
rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
# 启动数据库
systemctl start mysqld
#查找root密码
grep password /var/log/mysqld.log
#修改 root 口令
# 进入MySQL,使用前面查询到的口令
mysql -u root -p
# 设置口令强度;将root口令设置为12345678;刷新
set global validate_password_policy=0;
set password for 'root'@'localhost' =password('12345678');
flush privileges;
MySQL5.7版本默认设置了 mysql sql_mode = only_full_group_by 属性
找到 my.cnf文件
find / -name my.cnf vi /etc/my.cnf [mysqld] sql_mode=
修改之后重新启动mysql即可
注意:nginx 链接mysql 需要关闭SElinux
通常情况下载安装完CentOS7后,默认情况下SElinux是启用状态。
不关闭会报SQLSTATE[HY000] [2002] Permission denied 错误
[root@eyang02 ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
#如果要临时关闭,可以执行:setenforce 0
[root@eyang02 ~]# setenforce 0
[root@eyang02 ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
#如果要永久关闭,可以修改配置文件/etc/selinux/config,将SELINU置为disabled
[root@eyang02 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
#修改完成后,保存重启,重启后状态如下
[root@eyang02 ~]# sestatus
SELinux status: disabled
/usr/share/nginx/html 目录给了777 权限
php 代码 is_writable 返回 false 的解决办法:
执行
chcon -R -t httpd_sys_content_rw_t /usr/share/nginx/html