**
一、mysql安装
**
1、在Centos7中默认安装了Mysql的分支mariadb,需要卸载
yum remove mariadb-libs -y或rpm -e mariadb-libs --nodeps
2、下载安装包
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
3、 创建用户和组 解压软件至/usr/local
tar -zxf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
4、创建用户和组
groupadd -r mysql
useradd -M -s /sbin/nologin -g mysql mysql
cd /usr/local/
5、修改目录/usr/local/mysql的属主属组
chown -R mysql.mysql mysql
6、添加环境变量
echo ‘export PATH=/usr/local/mysql/bin:$PATH’ > /etc/profile.d/mysql.sh
echo $PATH//测试一下mysql环境变量
7、建立数据存放目录
mkdir /opt/data
chown -R mysql.mysql /opt/data/
8、初始化数据库
cd
mysqld --initialize --user=mysql --datadir=/opt/data/
//最后一个才是生成的临时密码
9、生成配置文件
[root@localhost ~]# cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF
10、配置服务启动脚本
cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
启动mysql
service mysqld start
[root@localhost ~]# mysql -uroot -p’I1AoatP;WSOy’
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.25
Copyright © 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
**
二、安装Nginx
**
1、安装GCC编译器
yum install gcc gcc-c++ -y
2、下载Nginx并创建用户www
wget http://nginx.org/download/nginx-1.12.2.tar.gz ;useradd -M -s /sbin/nologin www
3、安装支持包并解压Nginx
yum install -y pcre-devel zlib-devel openssl-devel ;tar zxf nginx-1.12.2.tar.gz
4、进入nginx解压目录并正式编译安装nginx
cd nginx-1.12.2/ ;./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module --user=www ;make && make install
–with-http_dav_module #增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法
–with-http_stub_status_module #获取Nginx的状态统计信息
–with-http_addition_module #作为一个输出过滤器,支持不完全缓冲,分部分相应请求
–with-http_sub_module #允许一些其他文本替换Nginx相应中的一些文本
–with-http_flv_module #提供支持flv视频文件支持
–with-http_mp4_module #提供支持mp4视频文件支持,提供伪流媒体服务端支持
–with-http_ssl_module #启用ngx_http_ssl_module
5、优化Nginx执行路径并启动nginx
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ ;nginx
三、安装PHP
1、下载源码包 cd /usr/local/src/
wget https://www.php.net/downloads/php-7.4.6.tar.bz2
2、解压源码包tar zxf php-7.4.6.tar.bz2
cd php-7.4.6
3、配置编译选项:
在编译之前,需要进入源代码目录,对要安装的程序进行各种参数配置,比如安装到什么地方,需要开启哪些功能等。配置工作一般都由源码目录中的configure脚本完成。
./configure --prefix=/usr/local/php --enable-opcache --with-config-file-path=/usr/local/php/etc --with-curl --enable-fpm --enable-gd --with-iconv --enable-mbstring --with-mysqli=mysqlnd --with-openssl --enable-static --enable-sockets --enable-inline-optimization --with-zlib --disable-ipv6 --disable-fileinfo --disable-debug
error: Package requirements (sqlite3 > 3.7.4) were not met
error: Package requirements (sqlite3 > 3.7.4) were not met
No package ‘sqlite3’ found
若看到上面的报错,非常简单:
yum install sqlite-devel -y
error: Package requirements (oniguruma) were not met
error: Package requirements (oniguruma) were not met
No package ‘oniguruma’ found
若看到上面的报错,非常简单:
yum install oniguruma-devel -y
编译PHP
刚才的配置通过后,直接运行 make 进行编译
安装PHP
刚才的编译通过后,先停止PHP-FPM服务:
systemctl stop php-fpm
然后运行 make install 进行安装
四、Nginx整合PHP
[root@localhost etc]# find /usr/local/src/php-7.4.6/ -name “php.ini*”
/usr/local/src/php-7.4.6/php.ini-production
/usr/local/src/php-7.4.6/php.ini-development
通过find命令可以找到两个配置文件,一个是开发环境使用的,一个是生产环境使用的。根据自己的需要,修改配置文件并复制到/usr/local/php/lib/目录下,重启PHP即可。
[root@localhost etc]# mv /usr/local/src/php-7.4.6/php.ini-development ./php.ini
配置文件(如不存在.conf文件则拷贝.default文件为.conf文件)
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost php-fpm.d]# cp www.conf.default ./www.conf
最后启动PHP-FPM服务:
systemctl start php-fpm
进入你的网站根目录执行:cd /usr/local/nginx/html/
vim index.php
echo “<?php phpinfo() ?>” >d.php
打开ip/index.php发现没有解析PHP文件
原来在yum安装Nginx后默认配置中并没有 fastcgi_param SCRIPT_FILENAME d o c u m e n t r o o t document_root documentrootfastcgi_script_name; 这一项,而这一项的意思是指脚本文件请求的路径,也就是说当访问127.0.0.1/index.php的时候,需要读取网站根目录下面的index.php文件,如果没有配置这一配置项时,nginx不回去网站根目录下访问.php文件,所以返回空白
cd /usr/local/nginx/conf
vim fastcgi_params
添加之后重启php-fpm和nginx
nginx和php-fpm启动重启脚本
cd /etc/init.d
vim nginx
#!/bin/bash
#Startup script for Nginx - this script starts and stops the nginx daemon
#chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) #reverse proxy and IMAP/POP3 proxy server # processname: nginx # #config: /usr/local/nginx/conf/nginx.conf # pidfile: #/usr/local/nginx/logs/nginx.pid # Source function library. . #/etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network
#Check that networking is up.
[ “$NETWORKING” = “no” ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c N G I N X C O N F F I L E r e t v a l = NGINX_CONF_FILE retval= NGINXCONFFILEretval=?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc p r o g − Q U I T r e t v a l = prog -QUIT retval= prog−QUITretval=?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc n g i n x − H U P R E T V A L = nginx -HUP RETVAL= nginx−HUPRETVAL=?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case “$1” in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $“Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}”
exit 2
esac
编辑好后保存,执行以下命令
复制代码代码如下:
sudo chmod +x /etc/init.d/nginx
sudo /sbin/chkconfig nginx on
检查一下
sudo /sbin/chkconfig --list nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
完成!可以使用以下命令管理Nginx了
复制代码代码如下:
service nginx start
service nginx stop
service nginx restart
service nginx reload
vim php-fpm
#!/bin/bash
#Startup script for the PHP-FPM server.
#chkconfig: 345 85 15 # description: PHP is an HTML-embedded #scripting language # processname: php-fpm # config: #/usr/local/php/etc/php.ini # Source function library.
. /etc/rc.d/init.d/functions
PHP_PATH=/usr/local
DESC=“php-fpm daemon”
NAME=php-fpm
#php-fpm路径
DAEMON= P H P P A T H / p h p / s b i n / PHP_PATH/php/sbin/ PHPPATH/php/sbin/NAME
#配置文件路径
CONFIGFILE=$PHP_PATH/php/etc/php-fpm.conf
#PID文件路径(在php-fpm.conf设置)
PIDFILE= P H P P A T H / p h p / v a r / r u n / PHP_PATH/php/var/run/ PHPPATH/php/var/run/NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
#Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
rh_start() {
$DAEMON -y $CONFIGFILE || echo -n " already running"
}
rh_stop() {
kill -QUIT cat $PIDFILE
|| echo -n " not running"
}
rh_reload() {
kill -HUP cat $PIDFILE
|| echo -n " can’t reload"
}
case “$1” in
start)
echo -n "Starting $DESC: $NAME"
rh_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
rh_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
rh_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
rh_stop
sleep 1
rh_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
编辑好后保存,执行以下命令
复制代码代码如下:
sudo chmod +x /etc/init.d/php-fpm
sudo /sbin/chkconfig php-fpm on
检查一下
sudo /sbin/chkconfig --list php-fpm
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
完成!可以使用以下命令管理php-fpm了
复制代码代码如下:
service php-fpm start
service php-fpm stop
service php-fpm restart
service php-fpm reload
/etc/init.d/php-fpm start
/etc/init.d/php-fpm stop
/etc/init.d/php-fpm restart
/etc/init.d/php-fpm reload
下载wordpress,wordpress使用到mysql数据库,首先需要在mysql数据库上进行操作。
wget https://wordpress.org/download/wordpress-5.4.1-zh_CN.tar.gz
tar -zxvf wordpress-5.4.1-zh_CN.tar.gz
mv ./ wordpress /usr/local/nginx/html/
mysql -uroot -p123456
mysql> create database wordpress;
mysql>grant all on wordpress.* to test@’%’ identified by ‘123456’;
https://ip/wordpress
按要求安装