一、MYSQL数据库安装
创建用户,下载mysql包
[root@web02 ~]# useradd mysql -s /sbin/nologin -M
[root@web02 ~]# id mysql
uid=1002(mysql) gid=1002(mysql) 组=1002(mysql)
[root@web02 ~]# cd /server/tools/
[root@web02 /server/tools]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/
[root@web02 /server/tools]# tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@web02 /server/tools]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql-5.7.26
[root@web02 /server/tools]# ln -s /application/mysql-5.7.26/ /application/mysql
配置/etc/my.cnf
[root@web02 /server/tools]# rpm -e --nodeps mariadb-libs
[root@web02 /server/tools]# vim /etc/my.cnf
basedir = /application/mysql/
datadir= /application/mysql/data
socket = /tmp/mysql.sock
server_id = 1
port = 3306
log_error = /application/mysql/oldboy_mysql.err
[mysql]
socket = /tmp/mysql.sock
prompt = oldboy [\\d]>
初始化数据库
[root@web02 /server/tools]# rpm -qa mariadb-libs
[root@web02 /server/tools]# yum install libaio-devel -y
[root@web02 /server/tools]# mkdir -p /application/mysql/data
[root@web02 /server/tools]# chown -R mysql.mysql /application/mysql/
[root@web02 /server/tools]# /application/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data
(关闭安全策略) (指定用户) (指定目录) (指定数据目录)
配置启动服务
[root@web02 /application/mysql/support-files]# vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server by oldboy
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@web02 /application/mysql/support-files]# systemctl start mysqld
[root@web02 /application/mysql/support-files]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /etc/systemd/system/mysqld.service.
[root@web02 /application/mysql/support-files]# systemctl status mysqld
配置环境变量
[root@web02 /application/mysql/support-files]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
[root@web02 /application/mysql/support-files]# . /etc/profile
[root@web02 /application/mysql/support-files]# mysql (登录成功即可)
配置MYSQL密码测试连接
[root@web02 ~]# mysqladmin -u root password 'oldboy123'
两种登录方式
交互式登录:
[root@web02 ~]# mysql -uroot -p
Enter password:
非交互登录:
mysql -uroot -poldboy123
====================================================================================
二、PHP的安装
安装PHP库
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y
cd /server/tools/ (上传libiconv-1.16.tar.gz)
tar zxf libiconv-1.16.tar.gz
cd libiconv-1.16
./configure --prefix=/application/libiconv
make && make install
cd ../
yum install libmcrypt-devel mhash mcrypt -y
安装PHP
cd /server/tools/
tar xf php-7.3.5.tar.gz
cd php-7.3.5/
./configure \
--prefix=/application/php-7.3.5 \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/application/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-gd \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp \
--enable-opcache=no
make && make install
echo $?
0 (表示成功)
用户统一
[root@web02 /server/tools/php-7.3.5]# useradd nginx -u 1111 -s /sbin/nologin -M
[root@web02 /server/tools/php-7.3.5]# id nginx
uid=1111(nginx) gid=1111(nginx) 组=1111(nginx)
[root@web02 /server/tools/php-7.3.5]# vim /application/nginx/conf/nginx.conf
worker_processes 1;
user nginx nginx; (编译的时候就改用nginx)
[root@web02 ~]# ln -s /application/php-7.3.5/ /application/php
配置解析器php.ini
[root@web02 /application/php]# cd /server/tools/php-7.3.5/
[root@web02 /server/tools/php-7.3.5]# ls php.ini-*
php.ini-development php.ini-production
[root@web02 /server/tools/php-7.3.5]# cp php.ini-development /application/php/lib/php.ini
[root@web02 /server/tools/php-7.3.5]# ls -l /application/php/lib/php.ini
-rw-r--r-- 1 root root 71648 5月 6 11:51 /application/php/lib/php.ini
配置PHP FPM
[root@web02 /server/tools/php-7.3.5]# cd /application/php/etc/
[root@web02 /application/php/etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
[root@web02 /application/php/etc]# cp php-fpm.conf.default php-fpm.conf
[root@web02 /application/php/etc]# cd php-fpm.d/
[root@web02 /application/php/etc/php-fpm.d]# ls
www.conf.default
[root@web02 /application/php/etc/php-fpm.d]# cp www.conf.default www.conf
[root@web02 /application/php/etc/php-fpm.d]# ls
www.conf www.conf.default
启动PHP服务
[root@web02 /application/php/etc/php-fpm.d]# /application/php/sbin/php-fpm
[root@web02 /application/php/etc/php-fpm.d]# netstat -lntup|grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 12214/php-fpm: mast
设置开机自启
[root@web02 /application/php/etc/php-fpm.d]# tail -2 /etc/rc.local
/application/nginx/sbin/nginx
/application/php/sbin/php-fpm
配置nginx转发php请求
[root@web02 /application/nginx/conf/extra]# cat 03_blog.conf
server {
listen 80;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
测试Nginx连接php
[root@web02 /application/nginx/conf]# echo "<?php phpinfo(); ?>" > ../html/blog/test_info.php
[root@web02 /application/nginx/conf]# cat ../html/blog/test_info.php
<?php phpinfo(); ?>
[root@web02 /application/nginx/conf]# /application/php/bin/php /application/nginx/html/blog/test_info.php
Windows系统上浏览器运行blog.etiantian.org/test_info.php
测试PHP连接MYSQL
[root@web02 /application/nginx/html/blog]# cat /application/nginx/html/blog/test_mysql.php
<?php
//$link_id=mysqli_connect('主机名','用户','密码');
$link_id=mysqli_connect('localhost','root','oldboy123') or mysql_error();
if($link_id){
echo "mysql successful by oldboy.\n";
}else{
echo mysql_error();
}
?>
[root@web02 /application/nginx/html/blog]# /application/php/bin/php /application/nginx/html/blog/test_mysql.php
mysql successful by oldboy.