php 7.1.3 mysql_CentOS7 安装NGINX1.16, PHP7.3, MySQL5.7 (lnmp)

文章目录

1.安装 Nginx

1.1 安装依赖

1.2 下载,解压,编译

1.3 设置软链并启动

1.4 配置 nginx

2. 安装 php

2.1 下载解压

2.2 安装依赖

2.3 安装 PHP

2.4 make

2.5 配置PHP

3.安装 MySQL

3.1 安装依赖

3.2 安装 MySQL

3.3 启动MySQL

3.4 配置MySQL

遇到错误

错误1:

错误1:

1.安装 Nginx

1.1 安装依赖

yum -y install gcc gcc-c++ autoconf automake make zlib-devel pcre-devel -y

1.2 下载,解压,编译

wget http://nginx.org/download/nginx-1.16.0.tar.gz

tar -zxvf nginx-1.16.0.tar.gz

cd nginx-1.16.0

./configure --prefix=/usr/local/nginx

make && make install

1.3 设置软链并启动

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

nginx -h

nginx

1.4 配置 nginx

# /etc/local/nginx/conf/nginx.conf

server {

listen      80;

server_name  localhost;

location / {

root  html;

index  index.php index.html index.htm;

}

error_page  500 502 503 504  /50x.html;

location = /50x.html {

root  html;

}

location ~ \.php$ {

root          html;

fastcgi_pass  127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $DOCUMENT_ROOT$fastcgi_script_name;

include        fastcgi_params;

}

...

}

ln -s /usr/local/nginx/html  ~

2. 安装 php

2.1 下载解压

wget https://www.php.net/distributions/php-7.3.4.tar.gz

tar -zxvf php-7.3.4.tar.gz

cd php-7.3.4

2.2 安装依赖

yum groupinstall "Development Tools" -y

yum --enablerepo=epel install bzip2-devel curl-devel libjpeg-turbo-devel libpng-devel libicu-devel libmcrypt-devel libxml2-devel freetype-devel -y

yum install libxslt-devel* -y

yum install openssl openssl-devel -y

2.3 安装 PHP

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/conf.d --enable-bcmath --with-bz2 --with-curl --enable-filter --enable-fpm --with-gd --enable-intl --enable-mbstring --enable-mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --disable-phpdbg --disable-phpdbg-webhelper --enable-opcache --with-openssl --enable-simplexml --enable-xmlreader --enable-xmlwriter --enable-zip --with-zlib --enable-soap --enable-shmop --enable-sockets --enable-sysvmsg --with-openssl-dir=/usr/local/ssl --with-jpeg-dir=/usr/lib64 --with-freetype-dir --with-gettext

1

或者精简点

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-curl --enable-filter --enable-fpm --with-gd --enable-intl --enable-mbstring --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd  --with-openssl --enable-simplexml --with-zlib --enable-sockets

2.4 make

make

make install

2.5 配置PHP

cp php.ini-development /usr/local/php/lib/php.ini

cp sapi/fpm/www.conf  /usr/local/php/etc/php-fpm.d/www.conf

cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php–fpm.conf

#### 2.6 配置php-fpm服务

1. 修改php-fpm.conf的pid

vim /usr/local/php/etc/php-fpm.conf

取消pid前面的注释

pid = run/php-fpm.pid

2. 复制文件并增加执行权限

cp sapi/fpm/init.d.php-fpm.in  /etc/init.d/php-fpm

3. 修改 /etc/init.d/php-fpm 文件

把路径改成绝对路径

php_fpm_BIN=/usr/local/php/sbin/php-fpm

php_fpm_CONF=/usr/local/php/etc/php-fpm.conf

php_fpm_PID=/usr/local/php/var/run/php-fpm.pid

4. 启动

chmod +x /etc/init.d/php-fpm

chkconfig --add php-fpm

chkconfig php-fpm on

5. 搞定!!

service php-fpm stop  |start | restart

3.安装 MySQL

3.1 安装依赖

yum install libaio-devel ncurses-devel cmake gcc gcc-c++ bison -y

3.2 安装 MySQL

# 下载

wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

# 校验校验码

md5sum mysql57-community-release-el7-9.noarch.rpm

# 安装

sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm

sudo yum install mysql-server

3.3 启动MySQL

启动

sudo systemctl start mysqld

sudo systemctl status mysqld

Note: MySQL is automatically enabled to start at boot when it is installed. You can change that default behavior with sudo systemctl disable mysqld

查看默认密码

sudo grep 'temporary password' /var/log/mysqld.log

# 2018-06-28T07:07:04.914495Z 1 [Note] A temporary password is generated for root@localhost: XTk;w145PkgT

3.4 配置MySQL

登录

mysql -uroot -p XTk;w145PkgT

查看密码配置

show variables like "%password%";

设置密码配置长度和安全 设置新密码

set global validate_password_length=0;

set global validate_password_policy=low;

ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

exit;

设置远程登录权限

默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;

配置默认编码为utf8

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]

character_set_server=utf8

init_connect='SET NAMES utf8'

重新启动mysql服务,查看数据库默认编码如下所示:

配置文件:/etc/my.cnf

日志文件:/var/log//var/log/mysqld.log

服务启动脚本:/usr/lib/systemd/system/mysqld.service

socket文件:/var/run/mysqld/mysqld.pid

遇到错误

错误1:

php文件提示错误,提示信息如下:

nginx: connect() failed (111: Connection refused) while connecting to upstream....

解决办法:

找到 /usr/local/php/etc/php-fpm.d/www.conf 取消以下这行当注释

listen.allowed_clients = 127.0.0.1

2. 重启nginx和php-fpm 即可

错误1:

php编译文件提示错误:configure: error: Please reinstall the libzip distribution

解决办法:

安装 libzip支持即可

wget https://nih.at/libzip/libzip-1.2.0.tar.gz

tar -zxvf libzip-1.2.0.tar.gz

cd libzip-1.2.0

./configure

make -j4 && make install

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值