1.Nginx安装的方式参考Nginx的安装
记得将下面行的注释取掉
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
d
o
c
u
m
e
n
t
r
o
o
t
document_root
documentrootfastcgi_script_name; #记得将/scripts改为$document_root,不然会访问不到。
include fastcgi_params;
}
#$document_root就是针对/usr/local/nginx/html目录下的php文件进行解析。
2.安装mariadb
yum install MariaDB-client MariaDB-common MariaDB-compat MariaDB-devel MariaDB-server MariaDB-shared galera redhat-lsb-core -y (建议更换yum源)
# vim /etc/my.cnf (编辑这几处即可)
#指的是mysql服务端
port = 3306 #指定运行端口
socket = /data/mydata/mysql.sock #指定sock
default-character-set = utf8 #指定字符集
log-error = /data/logs/mysql/mysql-error.log #指定错误日志(路劲自定义)
datadir = /data/mydata #指定数据库存放路劲(路劲自定义)
[client]
default-character-set = utf8
port = 3306
socket = /data/mydata/mysql.sock
#创建mysql
# id mysql #存在的话,就不用创建,(用户的创建方式:groupadd -g 27 mysqle ; useradd -g 27 -s /sbin/nologin mysql)
uid=27(mysql) gid=27(mysql) 组=27(mysql)
#创建主要目录并且授权
# mkdir -p /data/logs/mysql /data/mydata #创建日志目录及数据库存放路劲
# chown mysql.mysql /data/mydata/ /data/logs/mysql/ #授权给mysql(Mariaadb默认以mysql用户运行的)
# ln -s /data/mydata/mysql.sock /var/lib/mysql/mysql.sock #建立软连接(具体啥用我忘记了,建立一个放着也行)
#初始化
# mysql_install_db --defaults-file=/etc/my.cnf --user=mysql #初始化(但是保证/etc/my.cnf文件已创建并且进行授权)
#systemctl mariadb start
# mysql -uroot -e "delete from mysql.user where user=''" #删除用户 这个用户是' '
# mysqladmin -uroot password "你的密码" #设置root密码(mysqladmin是执行管理操作的客户端程序)
# mysqladmin -uroot -h 127.0.0.1 password "你的密码"
# mysql -uroot -p -e "delete from mysql.user where password=''" #删除'' 空密码
测试:
3.安装php
安装依赖
# yum -y install libxml2.x86_64 libxml2-devel.x86_64 openssl-devel libcurl-devel freetype.x86_64 freetype-devel.x86_64 libpng-devel libjpeg-devel libmcrypt-devel bison bison-devel libicu-devel libicu libwebp libwebp-devel sqlite-devel oniguruma-devel oniguruma
下载php7安装包及对应的需求包
# wget https://github.com/skvadrik/re2c/archive/1.2.1.tar.gz (re2c是一个用于C和C ++的免费开源词法分析器。)
# wget https://www.php.net/distributions/php-7.3.9.tar.gz
#创建对应目录
# mkdir -p /opt/app/ #用于存放主程序的地方(用户可以自定义)
# mkdir -m 777 -p /data/logs/php/ #指定php日志存放位置
解压re2c并安装
# tar xf re2c-0.16.tar.gz
# cd re2c-0.16
# ./configure
# make && make install
解压php并安装
# tar xf php-7.3.9.tar.gz
#cd /opt/src/php-7.3.9
#./configure --prefix=/opt/app/php7 --with-config-file-path=/opt/app/php7/etc --with-config-file-scan-dir=/opt/app/php7/etc/ini.d --enable-fpm --with-pdo-mysql --with-mysqli --with-pdo-mysql --with-freetype-dir=/usr/ --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-pcre-regex --enable-exif --enable-bcmath --with-curl --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-webp-dir --with-openssl --with-mhash --enable-pcntl --enable-sockets --enable-zip --enable-soap --with-gettext --enable-opcache --without-pear --enable-intl
# make
# make install
报错1:原因是需要安装更高版本的libzip库
configure: error: Please reinstall the libzip distribution
解决:安装更高版本的libzip库
# wget https://libzip.org/download/libzip-1.5.2.tar.gz
# tar xf libzip-1.5.2.tar.gz
# cd libzip-1.5.2
# cat INSTALL.md #查看安装方法
# mkdir build
# cd build/
# cmake … #报错的话,就参照下面的报错进行解决
# make
# make install
报错2:原因是cmake版本过低
解决方法:是安装更高版本的cmake
# yum remove cmake -y
# cd /opt/src/
# wget https://cmake.org/files/v3.6/cmake-3.6.0-Linux-x86_64.tar.gz
# tar xf cmake-3.6.0-Linux-x86_64.tar.gz #是个二进制文件,直接添加到环境变量即可
# vim ~/.bashrc
export PATH=$PATH:/opt/src/cmake-3.6.0-Linux-x86_64/bin
# source ~/.bashrc #到此就解决了cmake加载的问题
报错3:找不到please
configure: error: off_t undefined; check your library configuration
#解决方法
# echo ‘/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64’>>/etc/ld.so.conf
# ldconfig -v
生成配置文件
# cp /opt/app/php7/etc/php-fpm.conf.default /opt/app/php7/etc/php-fpm.conf
# cp /opt/app/php7/etc/php-fpm.d/www.conf.default /opt/app/php7/etc/php-fpm.d/www.conf
# cp /opt/src/php-7.3.9/php.ini-production /opt/app/php7/etc/php.ini
创建systemctl启动脚本
# ln -s /opt/app/php7/sbin/php-fpm /usr/bin/
# vim /etc/systemd/system/php7-fpm.service
{Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/opt/app/php7/var/run/php-fpm.pid
ExecStart=/opt/app/php7/sbin/php-fpm --nodaemonize --fpm-config /opt/app/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
启动并且设置开机启动
# systemctl daemon-reload
# systemctl start php7-fpm
# systemctl enable php7-fpm
``