lamp搭建
作者:互联网
##### 安装httpd ~~~~ [root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo --2021-01-04 23:15:41-- https://mirrors.aliyun.com/repo/Centos-8.repo Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 116.153.35.242, 116.153.35.249, 116.153.35.244, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|116.153.35.242|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2595 (2.5K) [application/octet-stream] Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’ /etc/yum.repos.d/CentOS-B 100%[====================================>] 2.53K --.-KB/s in 0s 2021-01-04 23:15:42 (79.3 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2595/2595] [root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2595 100 2595 0 0 14828 0 --:--:-- --:--:-- --:--:-- 14913 [root@localhost ~]# ls /etc/yum.repos.d/CentOS-Base.repo ^C [root@localhost ~]# [root@localhost ~]# yum makecache CentOS-8 - Base - mirrors.aliyun.com 3.4 MB/s | 2.3 MB 00:00 CentOS-8 - Extras - mirrors.aliyun.com 4.6 kB/s | 8.6 kB 00:01 CentOS-8 - AppStream - mirrors.aliyun.com 5.6 MB/s | 6.3 MB 00:01 Metadata cache created. [root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo [root@localhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo [root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm CentOS-8 - Base - mirrors.aliyun.com 23 kB/s | 3.9 kB 00:00 CentOS-8 - Extras - mirrors.aliyun.com 14 kB/s | 1.5 kB 00:00 CentOS-8 - AppStream - mirrors.aliyun.com 31 kB/s | 4.3 kB 00:00 epel-release-latest-8.noarch.rpm 145 kB/s | 22 kB 00:00 Dependencies resolved. ======================================================================================================= Package Architecture Version Repository Size ======================================================================================================= Installing: epel-release noarch 8-10.el8 @commandline 22 k Transaction Summary ======================================================================================================= Install 1 Package Total size: 22 k Installed size: 32 k Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : epel-release-8-10.el8.noarch 1/1 Running scriptlet: epel-release-8-10.el8.noarch 1/1 Verifying : epel-release-8-10.el8.noarch 1/1 Installed: epel-release-8-10.el8.noarch Complete! [root@localhost ~]# ls /etc/yum.repos.d/ CentOS-Base.repo epel-playground.repo epel-testing-modular.repo epel-modular.repo epel.repo epel-testing.repo [root@localhost ~]# ls /etc/yum.repos.d/ CentOS-Base.repo epel-playground.repo epel-testing-modular.repo epel-modular.repo epel.repo epel-testing.repo [root@localhost ~]# ls /etc/yum.repos.d/ [root@localhost~]# sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel* [root@test ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel* [root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel* [root@test ~]# [root@localhost ~]# vim /etc/yum.repos.d/epel.repo [root@localhost ~]# yum clean all 27 files removed [root@localhost ~]# yum makecache CentOS-8 - Base - mirrors.aliyun.com 4.4 MB/s | 2.3 MB 00:00 CentOS-8 - Extras - mirrors.aliyun.com 30 kB/s | 8.6 kB 00:00 CentOS-8 - AppStream - mirrors.a100% [===============================] 854 kB/s | 4.7 MB 00:00 ETA CentOS-8 - AppStream - mirrors.a100% [===============================] 854 kB/s | 4.7 MB 00:00 ETA CentOS-8 - AppStream - mirrors.aliyun.com 660 kB/s | 6.3 MB 00:09 Extra Packages for Enterprise Linux Modular 8 - x86_64 1.2 MB/s | 527 kB 00:00 Extra Packages for Enterprise Linux 8 - x86_64 1.3 MB/s | 8.7 MB 00:06 Metadata cache created. //安装开发工具包 [root@localhost ~]# yum -y groups mark install 'Development Tools' //创建apache服务的用户和组 [root@localhost ~]# useradd -r -M -s /sbin/nologin apache //安装依赖包 [root@localhost ~]# yum -y install bzip2 make openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ libxml2-devel //下载源码包 [root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.46.tar.bz2 [root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz [root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz [root@localhost ~]# ls anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.46.tar.bz2 //安装apr [root@localhost ~]# tar xf apr-1.7.0.tar.gz [root@localhost ~]# cd apr-1.7.0 [root@localhost apr-1.7.0]# vim configure cfgfile=${ofile}T trap "$RM \"$cfgfile\"; exit 1" 1 2 15 # $RM "$cfgfile" //将此行加上注释,或者删除此行 [root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr [root@localhost apr-1.7.0]# make [root@localhost apr-1.7.0]# make install //安装apr-util [root@localhost apr-1.7.0]# cd .. [root@localhost ~]# tar xf apr-util-1.6.1.tar.gz [root@localhost ~]# cd apr-util-1.6.1 [root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@localhost apr-util-1.6.1]# make [root@localhost apr-util-1.6.1]# make install //安装httpd [root@localhost apr-util-1.6.1]# cd .. [root@localhost ~]# tar xf httpd-2.4.46.tar.bz2 [root@localhost ~]# cd httpd-2.4.46 [root@localhost ~]# ./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 ~]# make [root@localhost ~]# make install //安装后配置 [root@localhost httpd-2.4.46]# cd [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 apachectl /usr/local/apache/bin/apachectl [root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd [root@localhost ~]# vim /etc/man_db.conf MANDATORY_MANPATH /usr/local/apache/man //取消ServerName前面的注释 [root@localhost ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf //启动apache [root@localhost ~]# apachectl start [root@localhost ~]# ss -antl [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port 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 ncurses-devel openssl-devel openssl cmake mariadb-devel //创建mysql的用户和组 [root@localhost ~]# useradd -r -M -s /sbin/nologin mysql 解压到/usr/local下 [root@localhost src]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@localhost src]# cd /usr/local/ [root@localhost local]# ll total 0 drwxr-xr-x. 13 root root 152 Jan 4 23:58 apache drwxr-xr-x. 6 root root 58 Jan 4 23:51 apr drwxr-xr-x. 5 root root 43 Jan 4 23:54 apr-util drwxr-xr-x. 2 root root 6 May 11 2019 bin drwxr-xr-x. 2 root root 6 May 11 2019 etc drwxr-xr-x. 2 root root 6 May 11 2019 games drwxr-xr-x. 2 root root 6 May 11 2019 include drwxr-xr-x. 2 root root 6 May 11 2019 lib drwxr-xr-x. 2 root root 6 May 11 2019 lib64 drwxr-xr-x. 2 root root 6 May 11 2019 libexec drwxr-xr-x. 9 7161 31415 129 Jun 2 2020 mysql-5.7.31-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 May 11 2019 sbin drwxr-xr-x. 5 root root 49 Dec 14 23:39 share drwxr-xr-x. 2 root root 6 May 11 2019 src //设置软链接并修改属主和属组 [root@localhost local]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64/ mysql [root@localhost local]# ll total 0 drwxr-xr-x. 13 root root 152 Jan 4 23:58 apache drwxr-xr-x. 6 root root 58 Jan 4 23:51 apr drwxr-xr-x. 5 root root 43 Jan 4 23:54 apr-util drwxr-xr-x. 2 root root 6 May 11 2019 bin drwxr-xr-x. 2 root root 6 May 11 2019 etc drwxr-xr-x. 2 root root 6 May 11 2019 games drwxr-xr-x. 2 root root 6 May 11 2019 include drwxr-xr-x. 2 root root 6 May 11 2019 lib drwxr-xr-x. 2 root root 6 May 11 2019 lib64 drwxr-xr-x. 2 root root 6 May 11 2019 libexec lrwxrwxrwx. 1 root root 36 Jan 5 00:16 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64/ drwxr-xr-x. 9 7161 31415 129 Jun 2 2020 mysql-5.7.31-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 May 11 2019 sbin drwxr-xr-x. 5 root root 49 Dec 14 23:39 share drwxr-xr-x. 2 root root 6 May 11 2019 src [root@localhost local]# chown -R mysql.mysql mysql* [root@localhost local]# ll total 0 drwxr-xr-x. 13 root root 152 Jan 4 23:58 apache drwxr-xr-x. 6 root root 58 Jan 4 23:51 apr drwxr-xr-x. 5 root root 43 Jan 4 23:54 apr-util drwxr-xr-x. 2 root root 6 May 11 2019 bin drwxr-xr-x. 2 root root 6 May 11 2019 etc drwxr-xr-x. 2 root root 6 May 11 2019 games drwxr-xr-x. 2 root root 6 May 11 2019 include drwxr-xr-x. 2 root root 6 May 11 2019 lib drwxr-xr-x. 2 root root 6 May 11 2019 lib64 drwxr-xr-x. 2 root root 6 May 11 2019 libexec lrwxrwxrwx. 1 mysql mysql 36 Jan 5 00:16 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64/ drwxr-xr-x. 9 mysql mysql 129 Jun 2 2020 mysql-5.7.31-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 May 11 2019 sbin drwxr-xr-x. 5 root root 49 Dec 14 23:39 share drwxr-xr-x. 2 root root 6 May 11 2019 src [root@localhost local]# chown -R mysql.mysql /usr/local/mysql [root@localhost local]# ll total 0 drwxr-xr-x. 13 root root 152 Jan 4 23:58 apache drwxr-xr-x. 6 root root 58 Jan 4 23:51 apr drwxr-xr-x. 5 root root 43 Jan 4 23:54 apr-util drwxr-xr-x. 2 root root 6 May 11 2019 bin drwxr-xr-x. 2 root root 6 May 11 2019 etc drwxr-xr-x. 2 root root 6 May 11 2019 games drwxr-xr-x. 2 root root 6 May 11 2019 include drwxr-xr-x. 2 root root 6 May 11 2019 lib drwxr-xr-x. 2 root root 6 May 11 2019 lib64 drwxr-xr-x. 2 root root 6 May 11 2019 libexec lrwxrwxrwx. 1 mysql mysql 36 Jan 5 00:16 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64/ drwxr-xr-x. 9 mysql mysql 129 Jun 2 2020 mysql-5.7.31-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 May 11 2019 sbin drwxr-xr-x. 5 root root 49 Dec 14 23:39 share drwxr-xr-x. 2 root root 6 May 11 2019 src 创建存放数据目录,配置环境变量 [root@localhost local]# cd [root@localhost ~]# mkdir /opt/data [root@localhost ~]# chown -R mysql.mysql /opt/data/ [root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@localhost ~]# source /etc/profile.d/mysql.sh [root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/ 2021-01-04T16:20:25.878257Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-01-04T16:20:26.115870Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-01-04T16:20:26.181090Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-01-04T16:20:26.264392Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c0e51860-4ea8-11eb-94f1-000c2989b3b5. 2021-01-04T16:20:26.265120Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-01-04T16:20:26.683900Z 0 [Warning] CA certificate ca.pem is self signed. 2021-01-04T16:20:26.843990Z 1 [Note] A temporary password is generated for root@localhost: ozkaev=wl1tI [root@localhost ~]# echo 'ozkaev=wl1tI' > pass [root@localhost ~]# cat /etc/my.cnf # # This group is read both both by the client and the server # use it for options that affect everything # [client-server] # # include all files from the config directory # !includedir /etc/my.cnf.d //配置mysql [root@localhost ~]# vim /etc/my.cnf [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 ........ 配置服务启动脚本 [root@localhost ~]# cd /usr/local/mysql [root@localhost mysql]# cd support-files/ [root@localhost support-files]# cp mysql.server /etc/init.d/mysqld [root@localhost support-files]# vim /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/opt/data ....... 启动mysql [root@localhost ~]# service mysqld start Starting MySQL.Logging to '/opt/data/localhost.err'. SUCCESS! [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 80 *:3306 *:* [root@localhost ~]# cat pass ozkaev=wl1tI 安装依赖包 [root@localhost ~]# mysql -uroot -p'ozkaev=wl1tI' mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory [root@localhost ~]# yum whatprovides libncurses.so.5 Last metadata expiration check: 0:13:07 ago on Tue 05 Jan 2021 12:15:05 AM CST. ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries Repo : base Matched from: Provide : libncurses.so.5 [root@localhost ~]# yum -y install ncurses-compat-libs Last metadata expiration check: 0:13:20 ago on Tue 05 Jan 2021 12:15:05 AM CST. Dependencies resolved. ======================================================================================================= Package Architecture Version Repository Size ======================================================================================================= Installing: ncurses-compat-libs x86_64 6.1-7.20180224.el8 base 331 k Transaction Summary ======================================================================================================= Install 1 Package Total download size: 331 k Installed size: 1.2 M Downloading Packages: ncurses-compat-libs-6.1-7.20180224.el8.x86_64.rpm 1.1 MB/s | 331 kB 00:00 ------------------------------------------------------------------------------------------------------- Total 1.1 MB/s | 331 kB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : ncurses-compat-libs-6.1-7.20180224.el8.x86_64 1/1 Running scriptlet: ncurses-compat-libs-6.1-7.20180224.el8.x86_64 1/1 Verifying : ncurses-compat-libs-6.1-7.20180224.el8.x86_64 1/1 Installed: ncurses-compat-libs-6.1-7.20180224.el8.x86_64 Complete! 更改密码 [root@localhost ~]# mysql -uroot -p'ozkaev=wl1tI' mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.31 Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> set password = password ('123'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> quit Bye [root@localhost ~]# mysql -uroot -p123 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.31 MySQL Community Server (GPL) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> quit Bye 安装后配置 [root@localhost ~]# vim /etc/man_db.conf MANDATORY_MANPATH /usr/local/mysql/man [root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib [root@localhost ~]# ldconfig ~~~~~~~~ ##### 安装php ~~~~~~~~~ 安装依赖包 [root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel [root@localhost ~]# yum install -y php-mysqlnd //安装php [root@localhost ~]# yum -y install php-* [root@localhost ~]# which php /usr/bin/php [root@localhost ~]# php -v PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies //启动php [root@localhost ~]# systemctl start php-fpm ~~~~~~~~ ##### 配置apache ~~~~~~ //启用代理模块 [root@localhost ~]# vim /etc/httpd24/httpd.conf #取消注释 LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so [root@localhost httpd24]# vim /etc/php-fpm.d/www.conf ;listen = /run/php-fpm/www.sock //加上注释 listen = 127.0.0.1:9000 加上本机ip和端口号 重启服务 [root@localhost httpd24]# systemctl restart php-fpm.service [root@localhost httpd24]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 127.0.0.1:9000 0.0.0.0:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 80 *:3306 *:* //创建虚拟主机目录并生成php测试页面 [root@localhost ~]# mkdir /usr/local/apache/htdocs/test [root@localhost ~]# vim /usr/local/apache/htdocs/test/index.php <?php phpinfo(); ?> [root@localhost ~]# chown -R apache.apache /usr/local/apache/htdocs/ [root@localhost ~]# ll /usr/local/apache/htdocs/ total 4 -rw-r--r--. 1 apache apache 45 Jun 12 2007 index.html drwxr-xr-x. 2 apache apache 23 Jan 1 20:28 test //配置虚拟主机 [root@localhost ~]# vim /etc/httpd24/httpd.conf <VirtualHost *:80> DocumentRoot "/usr/local/apache/htdocs/test" ServerName www.meijianbiao.com ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test/$1 <Directory "/usr/local/apache/htdocs/test"> 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 #添加此行 //搜索index.html,修改成以下内容 <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> //重启apache服务 [root@localhost ~]# apachectl restart [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 127.0.0.1:9000 0.0.0.0:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 80 *:3306 *:* //关闭防火墙 [root@localhost ~]# systemctl stop firewalld [root@localhost ~]# setenforce 0
标签:apr,drwxr,lamp,mysql,xr,root,localhost,搭建 来源: https://www.cnblogs.com/meijianbiao/p/14233363.html