下载php 7.3.0
cd /usr/local/src
wget http://cn2.php.net/distributions/php-7.3.0.tar.bz2
tar -zxf php-7.3.0.tar.bz2
下载mysql 5.6,编译过程需要这个包里的一些文件
wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
tar -zxf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.6.43-linux-glibc2.12-x86_64 /usr/local/mysql5.6
cd /usr/local/src/php-7.3.0
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql5.6 --with-mysqli=/usr/local/mysql5.6/bin/mysql_config --with-pdo-mysql=/usr/local/mysql5.6 --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
可以看到第二行,第三行都用到/usr/local/mysql5.6这个路径
编译过程可能会出错,显示缺失一些包,用yum安装,其中包括
gcc; libxml2-devel; openssl-devel; libcurl-devel; libpng-devel; freetype-devel
安装时多数选择devel包
make
这里指的目录是2. 配置选项中第一行指定的目录
make install
cd /usr/local/php-fpm/etc
cp php-fpm.conf.default php-fpm.conf
文件里语句只是include了另外一个配置文件(pool文件);
如果是旧版php,如php5.6,没有单独的pool文件,pool的设置都放置在php-fpm.conf里;
[root@tanyvlinux php-fpm.d]# grep ^[^\;] ../php-fpm.conf |grep ^[^$]
[global]
include=/usr/local/php-fpm/etc/php-fpm.d/*.conf
cd /usr/local/src/php-7.3.0
cp php.ini-development /usr/local/php-fpm/etc/php.ini
文件夹里还有一个配置文件php.int-production用于生产环境
cd /usr/local/src/php-7.3.0/sapi/fpm
cp /init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cd /usr/local/php-fpm/etc/php-fpm.d
cp www.conf.default www.conf
pool文件默认内容如下:
(该文件用于增加pool,修改端口,设置错误日志排查问题,open_basedir等)
[root@tanyvlinux php-fpm.d]# grep ^[^\;] www.conf |grep ^[^$]
[www]
user = php-fpm
group = php-fpm
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
useradd php-fpm
service php-fpm start
netstat -antp
侦听9000端口
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 36226/php-fpm: mast
make
/usr/local/src/php-5.6.39/ext/mysql/php_mysql.c: 在函数‘php_mysql_do_connect’中:
/usr/local/src/php-5.6.39/ext/mysql/php_mysql.c:725:36: 错误:‘MYSQL_PORT’未声明(在此函数内第一次使用)
int hashed_details_length, port = MYSQL_PORT;
^
/usr/local/src/php-5.6.39/ext/mysql/php_mysql.c:725:36: 附注:每个未声明的标识符在其出现的函数内只报告一次
make: *** [ext/mysql/php_mysql.lo] 错误 1
上面是一个错误,要把MYSQL_PORT全部改成0,可以通过这个错误;
----------------------------------------------------------------------------------
In file included from /usr/local/src/php-5.6.39/ext/mysqli/mysqli.c:34:0:
/usr/local/src/php-5.6.39/ext/mysqli/php_mysqli_structs.h:82:21: fatal error: my_list.h: No such file or directory
#include
In file included from /usr/local/src/php-5.6.39/ext/mysqli/mysqli.c:34:0:
/usr/local/src/php-5.6.39/ext/mysqli/php_mysqli_structs.h:83:22: fatal error: m_string.h: No such file or directory
#include
In file included from /usr/local/src/php-5.6.39/ext/mysqli/php_mysqli_structs.h:83:0,
from /usr/local/src/php-5.6.39/ext/mysqli/mysqli.c:34:
/usr/local/mysql/include/mysql/m_string.h:37:28: fatal error: lex_string.h: No such file or directory
#include "lex_string.h"
上面是另外三个错误,没有相关的文件;
https://dev.mysql.com/doc/dev/mysql-server/8.0.11/m__string_8h_source.html
上面链接可以下载这些文件,手动新建文件放进去目录/usr/local/mysql/include/mysql/放完一个,下一个依赖又出问题,所以编译参数需要改成mysql解压包的路径,这样可以解决问题。
#!/bin/bash
# need to download the php file and change the tar phase
# need a mysql5.6 file in /usr/local/
cd /usr/local/src
# wget -c http://cn2.php.net/distributions/php-5.6.39.tar.bz2
yum install -y bzip2
sleep 10
tar -jxvf php-7.3.0.tar.bz2
sleep 5
mv php-7.3.0 php7.3
cd php7.3/
yum install -y gcc-plugin-devel.x86_64
yum install -y libxml2-devel
yum install -y openssl-devel.x86_64
yum install -y libcurl-devel
yum install -y libjpeg-turbo-devel
yum install -y libpng-devel
yum install -y freetype-devel
yum install -y epel-release
yum install -y libmcrypt-devel
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql5.6 --with-mysqli=/usr/local/mysql5.6/bin/mysql_config --with-pdo-mysql=/usr/local/mysql5.6 --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
make
make install
sleep 10
cp /usr/local/src/php7.3/php.ini-production /usr/local/php-fpm/etc/php.ini
cp /usr/local/src/php7.3/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chkconfig --add php-fpm
chmod 755 /etc/init.d/php-fpm
useradd -s /sbin/nologin php-fpm
mv /usr/local/php-fpm/etc/php-fpm.conf.default /usr/local/php-fpm/etc/php-fpm.conf
mv /usr/local/php-fpm/etc/php-fpm.d/www.conf.default /usr/local/php-fpm/etc/php-fpm.d/www.conf
service php-fpm start
if [ $? -eq 0 ]; then
echo "php-fpm installed successfully"
else
echo "fault"
fi
cd /usr/local/src
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
/usr/local/nginx/sbin/nginx
rm -rf /usr/local/nginx
pkill nginx
vi /etc/yum.repos.d/nginx.repo
粘贴:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
保存
/yum install -y nginx
systemctl start nginx
配置文件路径为
/etc/nginx
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
这个是下载安装nginx yum源的命令,跟自建源文件是一样的,之后可以yum安装。
最新测试yum 安装了nginx-1.16,编译安装没有找到conf.d目录(放置虚拟主机配文件的目录)。
nginx服务打开后就可以通过本地网络的另一台主机访问这个服务
在浏览器输入nginx服务器的IP,会看到如下界面:
如果不能显示,原因应该是默认打开了防火墙,可以关闭或打开端口
关闭firewalld服务: systemctl stop firewalld
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
客户端访问设置 | DNS | 服务器IP | nginx侦听配置 |
---|---|---|---|
域名1 | 指向公网IP1 | 公网IP1 | 域名1+默认端口80 |
域名2 | 指向公网IP1 | 公网IP1 | 域名2+默认端口80 |
域名1+设定端口 | 指向公网IP1 | 公网IP1 | 域名1+设定端口 |
192.168.87.133 www.tany.com
最基础的虚拟主机配置文件tany.conf
server {
listen 80 ;
server_name www.tany.com;
location / {
root /data/wwwroot/tany.com/; #网站的根目录,名字对应容易查找,里面新建文本文件index.html;
index index.html index.htm; #进入目录后,会访问的文件名;
}
}
/usr/sbin/nginx -t
/usr/sbin/nginx -s reload
listen 80 default_server;
listen 80 default_server;
server_name www.aaa.com;
deny all; #将整个配置文件deny, www.aaa.com也是不能访问的;另外配置一个www.tany.com的虚拟主机文件,即打开一个从www.tany.com访问的入口;
虚拟主机配置文件server_name 可以是*.aaa.com 也可以是 www.aaa.*
前者可以匹配www.aaa.com blog.aaa.com bbs.aaa.com
后者可以匹配www.aaa.cn www.aaa.com www.aaa.cc
这就是泛解析。