编译安装LAMP
实验环境:
两台主机 A B
软件版本:
apr-1.7.0.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.39.tar.bz2 php-7.3.7.tar.xz
A:安装httpd和PHP
B: 安装mysql
A:
先编译httpd:
安装httpd所依赖到的包
[root@node4 source]#yum install gcc prce-devel openssl-devel expat-devel -y
创建Apache用户
[root@node4 source]#useradd -r -s /sbin/nologin apache
解压软件压缩包
[root@node4 source]#for i in *.bz2;do tar xf $i;done [root@node4 source]#ls apr-1.7.0.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.39 httpd-2.4.39.tar.bz2
将解压的apr-1.7.0和apr-util-1.6.1移动到解压好的httpd中并改名
[root@node4 source]#mv apr-1.7.0 httpd-2.4.39/srclib/apr [root@node4 source]#mv apr-util-1.6.1 httpd-2.4.39/srclib/apr-util [root@node4 srclib]#ls apr apr-util Makefile Makefile.in
编译
[root@node4 srclib]#./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
安装
[root@node4 httpd-2.4.39]#make -j 4 && make install
修改环境变量
[root@node4 httpd-2.4.39]#echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh
[root@node4 httpd-2.4.39]#. /etc/profile.d/httpd24.sh
修改配置文件
[root@node4 source]#vim /app/httpd24/conf/httpd.conf DirectoryIndex index.php index.html #:添加支持PHP页面 LoadModule proxy_module modules/mod_proxy.so #:启动代理模块 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so #:启动fcgi模块 User apache Group apache #:修改为apache用户
Include conf/extra/httpd-vhosts.conf #:取消注释,使其包含进虚拟主机的配置文件 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps #:添加两行使Apache支持PHP ProxyRequests Off #:关闭正向代理
配置虚拟主机
[root@node4 httpd-2.4.39]#vim /app/httpd24/conf/extra/httpd-vhosts.conf <VirtualHost *:80> ServerName blog.magedu.com DocumentRoot "/data/wordpress" <Directory "/data/wordpress/"> require all granted </Directory> ProxyPassMatch "^/(.*\.php)$" "fcgi://127.0.0.1:9000/data/wordpress/$1" </virtualhost>
<VirtualHost *:80>
ServerName frum.magedu.com
DocumentRoot "/data/discuze"
<Directory "/data/discuze/">
require all granted
</Directory>
ProxyPassMatch "^/(.*\.php)$" "fcgi://127.0.0.1:9000/data/discuze/$1"
</virtualhost>
将wordpress解压到/data目录
[root@node4 httpd-2.4.39]#tar xf wordpress-5.2.2.tar.gz
[root@node4 data]#unzip Discuz_X3.3_SC_UTF8.zip
[root@node4 data]#ln -sv upload/ discuze
设置权限
[root@node4 wordpress]#setfacl -Rm u:apache:rwx /data/wordpress
[root@node4 data]#setfacl -Rm u:apache:rwx /data/discuze/
启动
[root@node4 httpd-2.4.39]#apachectl start
编译php:
安装PHP依赖的包
[root@node4 php-7.3.7]# yum install libxml2-devel bzip2-devel libmcrypt-devel -y
解压PHP
[root@node4 php-7.3.7]#tar xf php-7.3.7.tar.xz
[root@node4 source]#ls
apr-1.7.0.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.39 httpd-2.4.39.tar.bz2 php-7.3.7 php-7.3.7.tar.xz
进到解压目录内,开始编译安装
[root@node4 php-7.3.7]#cd php-7.3.7/ [root@node4 php-7.3.7]#./configure --prefix=/app/php --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo [root@node4 php-7.3.7]#make -j 4 && make install
为php提供配置文件
[root@node4 php-7.3.7]#cd /data/source/php-7.3.7/ [root@node4 php-7.3.7]#cp php.ini-production /etc/php.ini
为php-fpm提供启动脚本
[root@node4 php-7.3.7]#cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@node4 php-7.3.7]#chmod +x /etc/init.d/php-fpm [root@node4 php-7.3.7]#chkconfig --add /etc/init.d/php-fpm [root@node4 php-7.3.7]#chkconfig php-fpm on
将编译的php-fpm的默认配置文件名改一下
[root@node4 etc]#cd /app/php/etc [root@node4 etc]#ls pear.conf php-fpm.conf.default php-fpm.d [root@node4 etc]#mv php-fpm.conf.default php-fpm.conf [root@node4 etc]#ls pear.conf php-fpm.conf php-fpm.d [root@node4 etc]#cd php-fpm.d/ [root@node4 php-fpm.d]#ls www.conf.default [root@node4 php-fpm.d]#mv www.conf.default www.conf
启动
[root@node4 data]#service php-fpm start
编译mariadb
将压缩包解压到/usr/local中
[root@node2 ~]#tar xf mariadb-10.2.25-linux-x86_64.tar.gz -C /usr/local/
创建软连接
[root@node2 local]#ln -sv mariadb-10.2.25-linux-x86_64/ mysql
修改目录权限,并创建用户
[root@node2 local]#chown -R root.root mysql/ [root@node2 local]#useradd -r -s /sbin/nologin mysql
修改环境变量
[root@node2 mysql]#echo 'PATH=/usr/local/bin/:$PATH' > /etc/profile.d/mysql.sh [root@node2 mysql]#. /etc/profile.d/mysql.sh
初始化
[root@node3 mysql]#scripts/mysql_install_db --datadir=/data/mysql --user=mysql
将配置文件移动到/etc目录
[root@node2 support-files]#cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf
配置启动文件
[root@node2 support-files]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@node2 support-files]#chkconfig --add mysqld
编辑配置文件,添加数据目录
[root@node2 support-files]#vim /etc/my.cnf
[mysqld]
data=/data/mysql
启动
[root@node2 mysql]#service mysqld start
测试数据库连接
<?php $mysqli=new mysqli("localhost","root","123456"); if(mysqli_connect_errno()){ echo "连接数据库失败!"; $mysqli=null; exit; } echo "连接数据库成功!"; $mysqli->close(); ?> ---------------------
测试