#lamp平台搭建:
*环境说明:
系统平台 | ip地址 | 需要安装的服务 |
---|---|---|
centos7 | 192.168.110.128 | httpd-2.4 mysql-5.7 php php-mysql |
一.安装httpd:
#安装开发工具:
[[email protected] ~]# yum groups mark install ‘Development Tools‘
安装过程已省略
#创建apache用户和组:
[[email protected] ~]# groupadd -r apache
[[email protected] ~]# useradd -r -M -s /sbin/nologin -g apache apache
#安装依赖包:
[[email protected] ~]# yum -y install openssl-devel pcre-devel expat-devel lib tool
安装过程已省略。
#下载和安装arp和arp-util:
[[email protected] ~]# cd /usr/src/
[[email protected] src]wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.
tar.bz2
下载过程已省略
[[email protected] src]#wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1
.6.1.tar.bz2
下载过程已省略
#解压apr和apr-util:
[[email protected] src]# ls
apr-1.6.3.tar.bz2 apr-util-1.6.1.tar.bz2 debug kernels
[[email protected] src]# tar xf apr-1.6.3.tar.bz2
[[email protected] src]# tar xf apr-util-1.6.1.tar.bz2
[[email protected] src]# ls
apr-1.6.3 apr-1.6.3.tar.bz2 apr-util-1.6.1 apr-util-1.6.1.tar.bz2 debug
kernels
[[email protected] src]# cd apr-1.6.3
[[email protected] apr-1.6.3]# vim configure
cfgfile="${ofile}T"
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
#$RM "$cfgfile" #将此行加上注释或者删除此行
#配置编译apr和apr-util:
[[email protected] apr-1.6.3]# ./configure --prefix=/usr/local/apr
配置过程省略
[[email protected] apr-1.6.3]# make && make install
编译过程省略
[[email protected] apr-1.6.3]# cd /usr/src/apr-util-1.6.1
[[email protected] apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util -
-with-apr=/usr/local/apr
配置过程略
[[email protected] apr-util-1.6.1]# make && make install
编译过程略
#下载编译安装httpd:
[[email protected] ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.3
4.tar.bz2
下载过程略
[[email protected] ~]# ls
httpd-2.4.34.tar.bz2
[[email protected] ~]# tar xf httpd-2.4.34.tar.bz2
[[email protected] ~]# cd httpd-2.4.34
[[email protected] httpd-2.4.34]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[[email protected] httpd-2.4.34]# make && make install
编译过程略
#安装后配置:
[[email protected] ~]# echo ‘PATH=/usr/local/apache/bin:$PATH‘ > /etc/profile.
d/httpd.sh
[[email protected] ~]# source /etc/profile.d/httpd.sh
[[email protected] ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[[email protected] ~]# echo ‘MANPATH /usr/local/apache/man‘ >> /etc/man.config
#在主配置文件取消ServerName的注释?:
[[email protected] ~]#sed -i ‘/#ServerName/s/#//g‘ /etc/httpd24/httpd.conf
#关闭防火墙,启动apache:
[[email protected] ~]#systemctl stop firewalld
[[email protected] ~]#setenforce 0
[[email protected] ~]# apachectl start
二.安装mysq:
#安装依赖包:
[[email protected] ~]# yum -y install ncurses-devel openssl-devel openssl cmak
e mariadb-devel
#创建用户和组:
[[email protected] src]# groupadd -r -g 306 mysql
[[email protected] src]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
#下载二进制格式的mysql软件包:
[[email protected] ~]# cd /usr/src/
[[email protected] src]# wget https://downloads.mysql.com/archives/get/file/my
sql-5.7.22-linux-glibc2.12-x86_64.tar.gz 下载过程略
#解压至/usr/local/
[[email protected] src]# ls
debug kernels mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[[email protected] src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C
/usr/local/
[[email protected] ~]# ls /usr/local/
bin games lib libexec sbin src
#做一个软连接:
[[email protected] local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
‘mysql’ -> ‘mysql-5.7.22-linux-glibc2.12-x86_64/’
#修改/usr/local/my属主属组:
[[email protected] ~]# chown -R mysql.mysql /usr/local/mysql
[[email protected] ~]# ll /usr/local/mysql -d
lrwxrwxrwx 1 mysql mysql 36 Aug 14 16:00 /usr/local/mysql -> mysql-5.7.22-l
inux-glibc2.12-x86_64/
#添加环境变量:
[[email protected] ~]# ls /usr/local/mysql
bin COPYING docs include lib man README share support-files
[[email protected] ~]# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/pr
ofile.d/mysql.sh
[[email protected] ~]# . /etc/profile.d/mysql.sh
[[email protected] ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/roo
t/bin
#建立数据库存放目录:
[[email protected] mysql]# mkdir /opt/data
[[email protected] mysql]# chown -R mysql.mysql /[[email protected] mysql]# ll /opt/
total 0
drwxr-xr-x 2 mysql mysql 6 Aug 14 16:54 data
#初始化数据库:
[[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
[[email protected] src]# echo ‘ri9woXLadi,G‘ >/root/a
#配置mysql并生成配置文件:
[[email protected] ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[[email protected] ~]# echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf
[[email protected] ~]# ldconfig -v
#生成配置文件:
[[email protected] ~]# cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF
#配置服务启动脚本:
[[email protected] ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~]# sed -ri ‘s#^(basedir=).*#\1/usr/local/mysql#g‘ /etc/init.d/mysqld
[[email protected] ~]# sed -ri ‘s#^(datadir=).*#\1/opt/data#g‘ /etc/init.d/mysqld
#启动mysql服务:
[[email protected] ~]# service mysqld start
Starting MySQL.. SUCCESS!
[[email protected] ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
#登入mysql修改密码:
[[email protected] local]# mysql -uroot -p‘ri9woXLadi,G‘
mysql> set password=password(‘123.com‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)
三.安装php:
#安装依赖包:
[[email protected] ~]# yum -y install libxml2 libxml2-devel openssl openssl-de
vel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng li
bpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel
readline readline-devel libxslt libxslt-devel mhash mhash-devel
安装过程略
#下载php:
[[email protected] ~]# cd /usr/src/
[[email protected] src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
#编译安装php:
[[email protected] src]# tar xf php-7.2.8.tar.xz
[[email protected] src]# cd php-7.2.8
[[email protected] php-7.2.8]# ./configure --prefix=/usr/local/php7 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir=/usr --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-jpeg-dir --with-png-dir --with-xmlrpc --with-xsl --with-zlib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
[[email protected] php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc
-l)
编译过程略
[[email protected] php-7.2.8]# make install
安装过程略
#安装后配置:
[[email protected] ~]# echo ‘export PATH=/usr/local/php7/bin:$PATH‘ > /etc/profile.d/php7.sh
[[email protected] ~]# source /etc/profile.d/php7.sh
[[email protected] php-7.2.8]# which php
/usr/local/php7/bin/php
[[email protected] php-7.2.8]# php -v
PHP 7.2.8 (cli) (built: Aug 16 2018 13:27:30) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
#配置php-fpm:
[[email protected] php-7.2.8]# cp php.ini-production /etc/php.ini
[[email protected] php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[[email protected] php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /us
r/local/php7/etc/php-fpm.conf
[[email protected] php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.defau
lt /usr/local/php7/etc/php-fpm.d/www.conf
#编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf)
配置fpm的相关选项为你所需要的值:
[[email protected] ~]# vim /usr/local/php7/etc/php-fpm.conf
pm.max_children = 50 /最多同时提供50个进程提供50个并发服务
pm.start_servers = 5 //启动时启动5个进程
pm.min_spare_servers =2 //最小空闲进程数
pm.max_spare_servers = 8 //最大空闲进程数
[[email protected] ~]# tail /usr/local/php7/etc/php-fpm.conf
; file.
; Relative path can also be used. They will be prefixed by:
; - the global prefix if it‘s been set (-p argument)
; - /usr/local/php7 otherwise
include=/usr/local/php7/etc/php-fpm.d/*.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
#启动php服务:
[[email protected] ~]# service php-fpm start
Starting php-fpm done
[email protected] src]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 80 :::3306 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[[email protected] ~]# ps -ef | grep php
root 67777 1 0 09:32 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 67778 67777 0 09:32 ? 00:00:00 php-fpm: pool www
nobody 67779 67777 0 09:32 ? 00:00:00 php-fpm: pool www
nobody 67780 67777 0 09:32 ? 00:00:00 php-fpm: pool www
nobody 67781 67777 0 09:32 ? 00:00:00 php-fpm: pool www
nobody 67782 67777 0 09:32 ? 00:00:00 php-fpm: pool www
root 67785 2020 0 09:32 pts/2 00:00:00 grep --color=auto php
四.配置虚拟主机:
#启动ttpd相关的模块:
[[email protected] ~]# sed -i ‘/proxy_module/s/#//g‘ /etc/httpd24/httpd.conf
[[email protected] ~]# sed -i ‘/proxy_fcgi_module/s/#//g‘ /etc/httpd24/httpd.conf
#在需要使用的cfgi的虚拟主机中添加如下两行:
ProxyRequests Off //关闭正向代理
ProxyPassMatch ^/(.*\.php)$fcgi://127.0.0.1:9000/var/www/html/idfsoft.com/
$1
#创建虚拟主机目录并生成php测试页面:
[[email protected] ~]# mkdir /usr/local/apache/htdocs/wuzhiyong.com
localhost ~]# cat > /usr/local/apache/htdocs/wangqing.com/index.php <<EOF
<?php
phpinfo();
?>
EOF
[[email protected] ~]# chown -R apache.apache /usr/local/apache/htdocs/
[[email protected] ~]# ll /usr/local/apache/htdocs/ -d
drwxr-xr-x 3 apache apache 44 Aug 16 14:50 /usr/local/apache/htdocs/
#在配置文件最后加入以下内容:
[[email protected] ~]# vim /etc/httpd24/httpd.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/wuzhiyong.com"
ServerName www.wuzhiyong.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/wuzhiyong.com/$1
<Directory "/usr/local/apache/htdocs/wuzhiyong.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
#搜索AddType,添加以下内容:
[[email protected] ~]# vim /etc/httpd24/httpd.conf
#If the AddEncoding directives above are commented-out, then you
#probably should define those extensions to indicate media types:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php //添加此行内容
AddType application/x-httpd-php-source .phps //添加此行内容
[[email protected] ~]# sed -i ‘/ DirectoryIndex/s/index.html/index.php inde
x.html/g‘ /etc/httpd24/httpd.conf
#重启apache服务:
[[email protected] ~]# apachectl stop
[[email protected] ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
#修改 host 文件,添加域名与IP的映射
#在windows客户机上增加环境变量,让虚拟域名和虚拟主机ip对照
#在浏览器上使用域名访问,若看到以下界面则表示lamp架构搭建成功
![]
原文地址:http://blog.51cto.com/13945839/2287372
时间: 2024-11-08 09:39:57