Centos9部署LAMP

配置LAMP

参考文档

https://blog.csdn.net/weixin_51432789/article/details/112254685

首先安装

yum install -y libxml2-devel

安装apr-1.7.4

解压

tar xf apr-1.7.4.tar.gz

安装以来

yum -y install gcc 

cd apr-1.7.4/

预编译

./configure --prefix=/usr/local/apr ; echo $?

编译

make ; echo $?

安装

make install ; echo $?

安装 apr 成功后的提示信息如下。

Centos9部署LAMP_第1张图片

安装apr-util

解压

tar xf apr-util-1.6.3.tar.gz

下载依赖

 yum -y install expat-devel

cd apr-util-1.6.3/

预编译

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr ; echo $?

编译安装

make && make install ; echo $?

安装httpd

下载依赖

yum -y install bzip2

yum -y install pcre-devel

yum install openssl-devel -y

解压

tar xf httpd-2.4.58.tar.bz2

cd httpd-2.4.58

预编译

./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util ; echo $?

编译

make ; echo $?

安装

make install ; echo $?

编译php

下载相关依赖

yum -y install php-mcrypt \

libmcrypt \

libmcrypt-devel \

autoconf \

freetype \

gd \

libmcrypt \

libpng \

libpng-devel \

libjpeg \

libxml2 \

libxml2-devel \

zlib \

curl \

curl-devel \

re2c \

php-pear ; echo $?

yum -y install perl

dnf -y groupinstall 'Development Tools'

dnf -y install wget libxml2-devel sqlite-devel bzip2-devel libcurl-devel libffi-devel libpng-devel libwebp-devel libjpeg-devel oniguruma libzip

yum -y install net-tools

yum -y install perl*

下载oniguruma

wget https://dl.rockylinux.org/pub/rocky/9/devel/x86_64/os/Packages/o/oniguruma-devel-6.9.6-1.el9.5.x86_64.rpm

下载libzip

wget https://dl.rockylinux.org/pub/rocky/9/devel/x86_64/os/Packages/l/libzip-devel-1.7.3-7.el9.x86_64.rpm 

安装oniguruma

yum -y localinstall oniguruma-devel-6.9.6-1.el9.5.x86_64.rpm

安装libzip

yum -y localinstall libzip-devel-1.7.3-7.el9.x86_64.rpm

解压PHP

tar xf php-8.2.12.tar.gz

修改第一行

进入该文件vi /usr/local/apache/bin/apxs修改第一行为以下内容

#!/usr/bin/perl -w

添加环境变量

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

安装依赖

yum -y install freetype-devel

yum install readline-devel

预编译

./configure --prefix=/usr/local/php8 \

--with-config-file-path=/usr/local/php8/etc \

--with-mysql=/usr/local/mysql/ \

--with-apxs2=/usr/local/apache/bin/apxs \

--enable-fpm \

--enable-debug \

--disable-rpath \

--enable-shared \

--enable-soap \

--with-openssl \

--enable-bcmath \

--with-iconv \

--with-bz2 \

--enable-calendar \

--with-curl \

--enable-exif \

--enable-ftp \

--enable-gd \

--with-jpeg \

--with-zlib-dir \

--with-freetype \

--with-gettext \

--enable-mbstring \

--enable-pdo \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-readline \

--enable-shmop \

--enable-simplexml \

--enable-sockets \

--with-zip \

--enable-mysqlnd-compression-support \

--with-pear \

--enable-pcntl \

--enable-opcache \

--enable-posix;echo $?

编译安装

make  ;  make install  ;  echo $?

编译安装的时候多给虚拟机cup资源。

修改php配置

增加变量

vim +$ /etc/profile

export PATH=$PATH:/usr/local/php8/bin/

刷新

source /etc/profile

修改配置文件名称

具体步骤

1.php.ini

查找php.ini-development 文件

[root@lnmp-152 ~]# find / -type f -name php.ini-development

查找php.ini-development文件 将该文件拷贝为/usr/local/php831/lib/php.ini

2.php-fpm.conf

查找php-fpm.conf.default文件

[root@bj-web131 php-8.3.1]# find / -type f -name "php-fpm.conf.default"

将php-fpm.conf.default文件移动为/usr/local/php831/etc/php-fpm.conf

3. www.conf

查找www.conf.default文件

[root@bj-web131 php-8.3.1]# find / -name "www.conf.default"

将/www.conf.default文件移动为/usr/local/php831/etc/php-fpm.d/www.conf

以下是具体操作

cp -av /root/php-8.2.12/php.ini-development /usr/local/php8/lib/php.ini

cp -av /usr/local/php8/etc/php-fpm.conf.default  /usr/local/php8/etc/php-fpm.conf

cp -av  /usr/local/php8/etc/php-fpm.d/www.conf.default  /usr/local/php8/etc/php-fpm.d/www.conf

添加用户

useradd -s /sbin/nologin apache -M

useradd -g apache -s /sbin/nologin apache

查看配置文件的用户信息

grep -ni '^user' /usr/local/php8/etc/php-fpm.d/www.conf

将user改为apache因为httpd的用户是apache

sed -i 's@user = nobody@user = apache@' /usr/local/php8/etc/php-fpm.d/www.conf

添加systenctl 配置文件

[root@localhost php-fpm.d]# cat  /usr/lib/systemd/system/php-fpm.service

[Unit]

Description=php-fpm

After=syslog.target network.target

[Service]

Type=forking

ExecStart=/usr/local/php8/sbin/php-fpm

#标红为自己php路径的php-fp配置文件

ExecReload=/bin/kill -USR2 $MAINPID

PrivateTmp=true

[Install]

WantedBy=multi-user.target

给该脚本增加权限

chmod 700 /usr/lib/systemd/system/php-fpm.service

刷新

systemctl daemon-reload

启动                               开机自启                 查看状态

systemctl start php-fpm && systemctl enable php-fpm && systemctl status php-fpm

修改apache的配置文件

1

vim /usr/local/apache/conf/httpd.conf

将153行的注释删掉

2

find / -type f -name "libphp.so" 查找该文件的路径

将155行的

LoadModule php_module   /usr/local/apache/modules/libphp.so

标红为php模块的路径 ,可以根据实际情况进行修改。

3

修改 AllowOverride none 为 All 此版本的 apache 在最后一个 如下

Centos9部署LAMP_第2张图片

4

修改 apache 的进程守护者

找到 User 将用户和组的名称改为 创建的 apache 用户

5

添加默认访问 index.php 作为首页访问 (改为如下内容)

5

修改以下高亮内容

Centos9部署LAMP_第3张图片

AddType application/x-httpd-php .php

AddType application/x-httpd-php .php .phtml .php3

AddType application/x-httpd-php-source .phps

6

检查配置语法

[root@localhost ~]# /usr/local/apache/bin/apachectl -t

Syntax OK

关闭

[root@localhost ~]# /usr/local/apache/bin/apachectl stop

启动

[root@localhost ~]# /usr/local/apache/bin/apachectl start

重启

/usr/local/apache/bin/apachectl restart

测试php能否被apche识别

cd /usr/local/apache/htdocs/

cat >index.php<

phpinfo();

?>

EOF

/usr/local/apache/bin/apachectl restart

可以被识别

Centos9部署LAMP_第4张图片

你可能感兴趣的:(linux,运维,服务器)