一 安装调试环境
环境调试
升级yum
yum update
清理系统原有http php
yum remove httpd* php*
安装
yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake
yum -y install wget http-tools vim
安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等
yum install epel-release -y
二 安装nginx
#查看可安装的nginx
yum list nginx*
#安装nginx
yum install -y nginx
#设置nginx开机启动
chkconfig nginx on
#启动nginx
service nginx start
附: 修改nginx配置文件后,重启报错:
nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)
解决办法:
vim /etc/nginx/conf.d/default.conf
将
listen 80 default_server;
listen [::]:80 default_server;
注释ipv6 on, 改为:
listen 80;
#listen [::]:80 default_server;
查看nginx安装情况
yum list installed | grep nginx
配置nginx:
默认在/etc/nginx/nginx.conf
或者在/etc/nginx/conf.d/default.conf
#
# The default server
#
server {
listen 80 default_server;
#listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
index index.html index.htm index.php;
autoindex off;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
保存重启nginx服务
service nginx restart
注意:
设置中
root /usr/share/nginx/html;
表示网页文件放置的路径
三 安装php7.3.6
请先安装依赖包
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libXpm-devel libwebp libwebp-devel libzip zip unzip
cd /usr/local/src
groupadd www
useradd -g www www
下载php-7.3.0 [直接到官网下载最新版本tar包 https://www.php.net/downloads.php]
wget http://php.net/get/php-7.3.6.tar.gz/from/this/mirror -O php-7.3.6.tar.gz
解压 tar包[cd /usr/local/src ]
$ tar -zxvf php-7.3.6.tar.gz
$ cd php-7.3.6
如果要安装LAMP, 必须先编译安装apache ,在apache安装目录下有apxs,php编译时需要用到参数:
--with-apxs2=/usr/local/httpd/bin/apxs
LAMP安装详情见Apache2.4.37+mysql5.7+PHP7.31最新版LAMP架构+Discuz论坛
配置
./configure --with-fpm-user=www --with-fpm-group=www --prefix=/usr/local/php --with-config-file-path=/usr/local/php/conf --bindir=/usr/local/php/bin --sbindir=/user/local/php/sbin --enable-fpm --with-libxml-dir --enable-debug --with-zlib --disable-rpath --enable-sysvsem --with-curl --enable-mbregex --enable-mbstring --enable-soap --with-pear --disable-phar --disable-tokenizer --enable-ftp --with-mysqli --with-pdo-mysql --with-openssl --with-bz2 --with-jpeg-dir --with-webp-dir --with-png-dir --with-xpm-dir --with-freetype-dir --with-mhash --with-iconv-dir --enable-gd-jis-conv --with-gd --enable-sockets --with-pcre-dir --enable-bcmath --enable-pdo --enable-pcntl --enable-posix
如果配置时参数错误导致配置失败, 务必使用清除命令,后再编译
#错误提示
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
执行
make clean
删除上次的编译结果
再编译
./configure --with-fpm-user=www --with-fpm-group=www --prefix=/usr/local/php --with-config-file-path=/usr/local/php/conf --with-apxs2=/usr/local/httpd/bin/apxs --bindir=/usr/local/php/bin --sbindir=/user/local/php/sbin --enable-fpm --with-libxml-dir --enable-debug --with-zlib --disable-rpath --enable-sysvsem --with-curl --enable-mbregex --enable-mbstring --enable-soap --with-pear --disable-phar --disable-tokenizer --enable-ftp --with-mysqli=mysqlnd --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock --with-openssl --with-bz2 --with-jpeg-dir --with-webp-dir --with-png-dir --with-xpm-dir --with-freetype-dir --with-mhash --with-iconv-dir --enable-gd-jis-conv --with-gd --enable-sockets --with-pcre-dir --enable-bcmath --enable-pdo --enable-zip --enable-json --enable-session --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-posix
安装
make && make install
在之前编译的源码包中,找到 php.ini-production,复制到/usr/local/php/etc下,并改名为php.ini:
$ cp php.ini-production /usr/local/php/etc/php.ini
将php源码编译目录下的 sapi/fpm/init.d.php-fpm 文件拷贝到系统配置 /etc/init.d 目录下并重命名为 php-fpm
[root@localhost php-7.3.6]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.3.6]# chmod 755 /etc/init.d/php-fpm
添加 php-fpm 配置文件
将php安装目录下的 /usr/local/php/etc/php-fpm.conf.default 文件拷贝同目录下并重命名为 php-fpm.conf
[root@localhost php-7.3.6]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
添加 www.conf 配置文件
将php安装目录下的 /usr/local/php/etc/php-fpm.d/www.conf.default 文件拷贝同目录下并重命名为 www.conf
[root@localhost php-7.3.6]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
添加php安装目录到系统环境变量
创建并打开文件php.sh
[root@localhost php-7.3.6]# vim /etc/profile.d/php.sh
添加内容如下:
export PATH=$PATH:/usr/local/php/bin/:/usr/local/php/sbin/
保存并退出
:wq!
使用source立即生效刚刚添加的php环境变量
[root@localhost php-7.3.6]# source /etc/profile.d/php.sh
启动php-fpm
[root@localhost php-7.3.6]# service php-fpm start
看到9000端口也就成功了!!!
设置php开机启动
修改系统配置目录下的 php-fpm 文件可执行权限
[root@localhost php-src-php-7.1.6]# chmod +x /etc/init.d/php-fpm
> 将系统配置目录下的 `php-fpm` 添加到 `系统服务`
[root@localhost php-src-php-7.1.6]# chkconfig --add php-fpm
> 设置 `php-fpm` `系统服务` 为开机启动
[root@localhost php-src-php-7.1.6]# chkconfig php-fpm on
重启后查看端口看看是否存在!
在 /usr/share/nginx/html 路径下创建phpinfo.php
<?php
phpinfo();
// 将会打印出所有的PHP信息
?>
浏览器中打开 http://xxxx.com/phpinfo.php
成功!!!
四 mysql5.7 数据库安装
https://blog.csdn.net/h330531987/article/details/94452368