搭建lamp服务

版权声明:勇哥出品必属精品违者必究,相信勇哥幸福一生,不信勇哥抱憾终身,盗版一时爽全家火葬场! https://blog.csdn.net/weixin_42837637/article/details/82857887

一、安装http

[root@localhost ~]# yum groups mark install 'Development Tools'
[root@localhost ~]# groupadd -r apache
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g apache apache
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
[root@localhost ~]#cd /usr/src/
[root@localhost src]# tar xf apr-1.6.3.tar.bz2
[root@localhost src]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost src]# tar xf httpd-2.4.34.tar.bz2
[root@localhost src]# ls
apr-1.6.3          apr-util-1.6.1          debug                 kernels
apr-1.6.3.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.34.tar.bz2  mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# cd apr-1.6.3
[root@localhost apr-1.6.3]# vi configure

cfgfile="${ofile}T"
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile"   //删除此行
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.3]# make && make install
[root@localhost apr-1.6.3]# cd /usr/src/apr-util-1.6.3
[root@localhost apr-util-1.6.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.3]# make && make install
[root@localhost src]# cd httpd-2.4.34
[root@localhost 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
[root@localhost httpd-2.4.34]# make && make install
安装后进行配置
[root@localhost httpd-2.4.34]# echo 'PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
取消Server Name前面的注释并启动Apachectl
[root@localhost ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
[root@localhost ~]# apachectl start
[root@localhost ~]# 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                                                :::* 

二、安装mysql

[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
[root@localhost src]# groupadd -r -g 306 mysql
[root@localhost src]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
[root@localhost ~]# ls
anaconda-ks.cfg  mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost local]# ln -sv mysql-5.7.23-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.23-linux-glibc2.12-x86_64/"

修改目录/usr/local/mysql属组属主

[root@localhost local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 9月  26 18:38 /usr/local/mysql -> mysql-5.7.23-linux-glibc2.12-x86_64/

添加环境变量

[root@localhost local]# . /etc/profile.d/mysql.sh
[root@localhost local]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

建立数据库存放目录

[root@localhost local]# mkdir /opt/data
[root@localhost local]# chown -R mysql.mysql /opt/data/
[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/

配置mysql

[root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]#ldconfig -v
[root@localhost ~]# 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

配置服务启动脚本

[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld

启动mysql

[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost ~]# ps -ef|grep mysql
root      46466      1  0 19:00 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql     46644  46466  2 19:00 pts/1    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root      46674  13269  0 19:00 pts/1    00:00:00 grep --color=auto mysql
[root@localhost ~]# ss -ant
State       Recv-Q Send-Q                     Local Address:Port                                    Peer Address:Port              
LISTEN      0      128                                    *:22                                                 *:*                  
LISTEN      0      100                            127.0.0.1:25                                                 *:*                  
ESTAB       0      0                        192.168.100.148:22                                     192.168.100.1:4744               
ESTAB       0      0                        192.168.100.148:22                                     192.168.100.1:5617               
LISTEN      0      80                                    :::3306                                              ::: *                  
LISTEN      0      128                                   :::80                                                ::: *                  
LISTEN      0      128                                   :::22                                                ::: *                  
LISTEN      0      100                                  ::1:25                                                ::: *      

修改临时密码进行登录

[root@localhost ~]# mysql -uroot -p
Enter password:
mysql> set password = password('qinyong123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit;

三、安装php

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# yum -y install epel-release

安装依赖包

扫描二维码关注公众号,回复: 5384194 查看本文章
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
[root@localhost src]# tar xf php-7.2.8.tar.xz
[root@localhost src]# cd php-7.2.8
[root@localhost 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
[root@localhost php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
[root@localhost php-7.2.8]# make install

安装后配置

[root@localhost php-7.2.8]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost php-7.2.8]# source /etc/profile.d/php7.sh
[root@localhost php-7.2.8]# which php
/usr/local/php7/bin/php
[root@localhost php-7.2.8]# php -v
PHP 7.2.8 (cli) (built: Sep 26 2018 19:39:04) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

配置php-fpm

[root@localhost php-7.2.8]# cp php.ini-production /etc/php.ini
[root@localhost php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@localhost ~]# 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                   //最大空闲进程数
[root@localhost php-7.2.8]# tail /usr/local/php7/etc/php-fpm.conf
; files from a glob(3) pattern. This directive can be used everywhere in the
; 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-fpm

[root@localhost php-7.2.8]# service php-fpm start
Starting php-fpm  done
[root@localhost php-7.2.8]# 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                                                ::: *  
[root@localhost php-7.2.8]# ps -ef|grep php
root      85945      1  0 19:56 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody    85946  85945  0 19:56 ?        00:00:00 php-fpm: pool www
nobody    85947  85945  0 19:56 ?        00:00:00 php-fpm: pool www
nobody    85948  85945  0 19:56 ?        00:00:00 php-fpm: pool www
nobody    85949  85945  0 19:56 ?        00:00:00 php-fpm: pool www
nobody    85950  85945  0 19:56 ?        00:00:00 php-fpm: pool www
root      85978  13269  0 19:57 pts/1    00:00:00 grep --color=auto php

配置apache

[root@localhost php-7.2.8]# sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf
[root@localhost php-7.2.8]# sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd24/httpd.conf

配置虚拟主机

[root@localhost php-7.2.8]# vim /etc/httpd24/httpd.conf

在行尾添加

ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
[root@localhost ~]# mkdir /usr/local/apache/htdocs/qinyong.com
[root@localhost ~]# cat > /usr/local/apache/htdocs/qinyong.com/index.php <<EOF
> <?php
> phpinfo();
> ?>
> EOF
[root@localhost ~]# chown -R apache.apache /usr/local/apache/htdocs/
[root@localhost ~]# ll /usr/local/apache/htdocs/ -d
drwxr-xr-x. 4 apache apache 63 9月  26 20:12 /usr/local/apache/htdocs/
[root@localhost ~]# vim /etc/httpd24/httpd.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/qinyong.com"
ServerName www.qinyong.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdo
cs/qinyong.com/$1
<Directory "/usr/local/apache/htdocs/qinyong.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
//搜索AddType添加两行
# 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               //添加这行
[root@localhost ~]# sed -i '/ DirectoryIndex/s/index.html/index.php index.html/g' /etc/httpd24/httpd.conf

重启Apache服务

[root@localhost ~]# apachectl stop
[root@localhost ~]# apachectl start
[root@localhost ~]# 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                                                                                      :::*  

添加IP和域名映射

在我的电脑
修改C:\Windows\System32\drivers\etc\hosts
# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost
192.168.100.148 www.qinyong.com          \\添加此行域名ip

进行验证
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42837637/article/details/82857887