centos7 安装 php7.3 mysql5.6 nginx1.6
第一步 安装nginx
yum -y install epel-release lrzsz zip unzip wget tree git dpkg pcre pcre-devel openssl openssl-devel gd-devel zlib-devel gcc
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null
yum repolist
yum clean all
sed -i 's/^SELINUX=.*$/SELINUX=disabled/g' /etc/selinux/config
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar -xf nginx-1.16.0.tar.gz
cd nginx-1.16.0
useradd -s /sbin/nologin -M nginx
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre --with-http_gzip_static_module --with-http_dav_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module
make && make install
ln -sv /usr/local/nginx/sbin/nginx /usr/sbin/nginx
nginx
ss -ntl
nginx开机启动脚本
vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 2
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -3 $(cat $PIDF)
;;
restart)
$0 stop &> /dev/null
if [ $? -ne 0 ] ; then continue ; fi
$0 start
;;
reload)
kill -1 $(cat $PIDF)
;;
*)
echo "Userage: $0 { start | stop | restart | reload }"
exit 1
esac
exit 0
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig --list
chkconfig nginx on
第二步 安装php7.3
yum install bzip2 bzip2-devel libcurl-dev libcurl-dev curl-devel postgresql-devel libxslt-devel
yum remove libzip
cd /usr/local/src
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -xf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make &&make install
#添加搜索路径到配置文件
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
#然后 更新配置
ldconfig -v
useradd -s /sbin/nologin php-fpm
wget https://www.php.net/distributions/php-7.3.8.tar.gz
tar -xf php-7.3.8.tar.gz
cd php-7.3.8
./configure --prefix=/usr/local/php --sysconfdir=/usr/local/php/etc --with-config-file-path=/usr/local/php/etc/ --with-fpm-user=php-fpm --with-fpm-group=php-fpm --enable-fpm --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --with-gd --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql --with-mysqli --with-jpeg-dir=/usr --with-png-dir=/usr --with-openssl --with-libdir=/lib/x86_64-linux-gnu/ --enable-ftp --with-gettext --with-xmlrpc --with-xsl --enable-opcache --with-iconv --with-xpm-dir=/usr
make && make install
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/src/php-7.3.8/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
chkconfig --list
ln -s /usr/local/php/bin/php /usr/sbin/php
php -v
service php-fpm start
PHP优化配置
注释符:较新的版本中,已经完全使用;进行注释
#:纯粹的注释信息
;:用于注释可启用的directive
vim /usr/local/php/etc/php.ini
max_execution_time= 30 最长执行时间30s
memory_limit 128M 生产不够,可调大
display_errors off 调试使用,不要打开,否则可能暴露重要信息
display_startup_errors off 建议关闭
post_max_size 8M 最大上传数据大小,生产可能临时要调大,比下面项要大
upload_max_filesize 2M 最大上传文件,生产可能要调大
max_file_uploads = 20 同时上传最多文件数
date.timezone =Asia/Shanghai 指定时区
short_open_tag=on 开启短标签,如<? phpinfo();?>
第三步安装mysql5.6
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server
rpm -qa |grep mysql
systemctl start mysqld.service
ss -ntl
ystemctl enable mysqld
设置密码 。
mysql5.6 安装完成后,它的 root 用户的密码默认是空的,我们需要及时用 mysql 的 root 用户登录(第一次直接回车,不用输入密码),并修改密码。
# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("这里输入root用户密码") where User='root';
mysql> flush privileges;
设置远程主机登录
mysql> GRANT ALL PRIVILEGES ON *.* TO 'your username'@'%' IDENTIFIED BY 'your password';
mysql开启慢日志查询功能
Linux系统下是编辑/etc/my.cnf
注意:[mysqld]下面添加
#mysql慢日志开启
slow_query_log=ON
slow_query_log_file=/var/lib/mysql/mysql-slow.log
long_query_time=1
然后,重启mysql服务使之生效:
service mysqld restart
接下来就可以通过slow_query_log_file指定的日志路径查看慢查询记录了