在centos8源码部署LAMP
在centos8源码部署LAMP
#关防火墙、selinux
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config
.....
SELINUX=disabled
一、安装httpd
#下载apr、apr-util、httpd最新版
http://archive.apache.org/
#解压
[root@localhost ~]# tar xf apr-1.7.4.tar.gz
[root@localhost ~]# tar xf apr-util-1.6.3.tar.gz
#下载依赖包
[root@localhost ~]# yum -y install gcc gcc-c++ zlib zlib-devel expat-devel pcre-devel make wget tar net-tools
#复制
[root@localhost ~]# cp -r apr-1.7.4 httpd-2.4.9/srclib/apr
[root@localhost ~]# cp -r apr-util-1.6.3 httpd-2.4.9/srclib/apr-util
#编译
[root@localhost ~]# cd httpd-2.4.9
[root@localhost httpd-2.4.9]# ./configure --prefix=/usr/local/apache/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite-shared
[root@localhost httpd-2.4.9]# make && make install
#创建用户,改权限
[root@localhost ~]# groupadd apache
[root@localhost ~]# useradd apache -g apache -M -s /bin/false
[root@localhost ~]# id apache
uid=1000(apache) gid=1000(apache) groups=1000(apache)
[root@localhost ~]# chown -R apache.apache /usr/local/apache/
#配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# which httpd
/usr/local/apache/bin/httpd
#链接头文件
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf
#启动服务
[root@localhost ~]# apachectl start
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
二、安装mysql
[root@localhost ~]# yum -y install mariadb*
[root@localhost ~]# systemctl enable --now mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> set password = password("000000");
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
三、安装php
#下载包
https://www.php.net/
#下载依赖包
[root@localhost ~]# yum -y install libxml2-devel openssl-devel bzip2-devel libjpeg-devel libpng-devel libwebp-devel libXpm-devel freetype-devel oniguruma libzip-devel sqlite-devel.x86_64 libcurl libcurl-devel
#编译
[root@localhost php-8.2.6]# ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --enable-inline-optimization --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-zlib --with-curl --with-gd --with-jpeg --with-png --with-webp --with-xpm --with-freetype --with-bz2 --with-libzip --with-onig
[root@localhost php-8.2.6]# make
[root@localhost php-8.2.6]# make install
#配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/php/bin:$PATH' > /etc/profile.d/php.sh
[root@localhost ~]# source /etc/profile.d/php.sh
[root@localhost ~]# which php
/usr/local/php/bin/php
[root@localhost ~]# php -v
PHP 8.2.6 (cli) (built: May 23 2023 21:14:29) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.6, Copyright (c) Zend Technologies
[root@localhost php-8.2.6]# cp php.ini-production /etc/php.ini
[root@localhost php-8.2.6]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-8.2.6]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-8.2.6]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-8.2.6]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
#启动服务
[root@localhost php-8.2.6]# service php-fpm start
Starting php-fpm done
[root@localhost php-8.2.6]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 80 0.0.0.0:3306 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
四、配置apache
[root@localhost]# vim /usr/local/apache/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so #注释
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so #注释
五、配置虚拟化
#创建php测试页面
[root@localhost]# cd /usr/local/apache/htdocs
[root@localhost htdocs]# mkdir zc
[root@localhost htdocs]# cd zc
[root@localhost zc]# vim index.php
<?php
phpinfo();
?>
[root@localhost htdocs]# chown -R apache.apache /usr/local/apache
#改配置文件
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
<IfModule dir_module>
DirectoryIndex index.php index.html #在前面添加index.php
</IfModule>
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php #添加
AddType application/x-httpd-php-source .phps #添加
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zc" #网站位置
ServerName www.zhaocong.com #域名
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zc/$1
<Directory "/usr/local/apache/htdocs/zc">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
#重启服务
[root@localhost ~]# service php-fpm stop
[root@localhost ~]# service php-fpm start
[root@localhost ~]# apachectl stop
[root@localhost ~]# apachectl start
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:* #php
LISTEN 0 80 0.0.0.0:3306 0.0.0.0:* #mariadb
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:* #httpd
LISTEN 0 128 [::]:22 [::]:*
查看: