配置apache
//安装开发工具包
[root@server ~]# yum groups mark install 'Development Tools'
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Marked install: Development Tools
//创建用户和组
[root@server ~]# groupadd -r apache
[root@server ~]# useradd -r -M -s /sbin/nologin -g apache apache
//安装依赖包
[root@server ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
//下载apr和apr-util
wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.5.tar.bz2 http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
//安装apr和apr-util
//在apr-1.6.5中将configure脚本内的$RM这一行删除
[root@server ~]# ./configure --prefix=/usr/local/apr
[root@server ~]# make && make install
[root@server ~]# cd apr-util-1.6.1
[root@server apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@server apr-util-1.6.1]# make && make install
//下载httpd
[root@server ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.37.tar.bz2
//安装httpd
[root@server ~]# tar xf httpd-2.4.37.tar.bz2
[root@server ~]# cd httpd-2.4.37
[root@server httpd-2.4.37]# ./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@server httpd-2.4.37]# make && make install
//安装后配置
[root@server httpd-2.4.37]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@server httpd-2.4.37]# source /etc/profile.d/httpd.sh
[root@server httpd-2.4.37]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@server httpd-2.4.37]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
[root@server httpd-2.4.37]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
[root@server httpd-2.4.37]# apachectl start
[root@server ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:57330 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::49181 :::*
配置mysql
//安装依赖包和下载二进制mysql包
[root@server ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
[root@server ~]# groupadd -r -g 306 mysql
[root@server ~]# useradd -r -M -s /sbin/nologin -g 306 -u 306 mysql
[root@server ~]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
//解压配置mysql
[root@server ~]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@server ~]# cd /usr/local/
[root@server local]# ls
apache apr-util etc include lib64 mysql-5.7.22-linux-glibc2.12-x86_64 share
apr bin games lib libexec sbin src
[root@server local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.22-linux-glibc2.12-x86_64/"
[root@server local]# ls
apache apr-util etc include lib64 mysql sbin src
apr bin games lib libexec mysql-5.7.22-linux-glibc2.12-x86_64 share
[root@server local]# chown -R mysql.mysql /usr/local/mysql
[root@server local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 12月 19 10:59 /usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
[root@server local]# ls /usr/local/mysql
bin COPYING docs include lib man README share support-files
[root@server local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@server local]# . /etc/profile.d/mysql.sh
[root@server local]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@server local]# mkdir /opt/data
[root@server local]# chown -R mysql.mysql /opt/data/
[root@server local]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 12月 19 11:00 data
//初始化数据库
[root@server ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/2019-12-19T03:01:35.862161Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-12-19T03:01:36.673480Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-12-19T03:01:36.882420Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-12-19T03:01:37.307046Z 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: df361822-220b-11ea-ba15-000c296e029d.
2019-12-19T03:01:37.308394Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-12-19T03:01:37.309741Z 1 [Note] A temporary password is generated for root@localhost: qK(iyJrAB4SP
[root@server ~]# echo 'qK(iyJrAB4SP' > pass
[root@server ~]# cat pass
qK(iyJrAB4SP
//配置mysql
[root@server ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[root@server ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@server ~]# ldconfig
[root@server ~]# 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
//启动mysql
[root@server ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@server ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@server ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
[root@server ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/server.err'.
SUCCESS!
[root@server ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:57330 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::49181 :::*
LISTEN 0 80 :::3306 :::*
//修改mysql密码
[root@server ~]# cat pass
qK(iyJrAB4SP
[root@server ~]# mysql -uroot -p'qK(iyJrAB4SP'
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 2
Server version: 5.7.22
Copyright (c) 2000, 2018, 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('wangqing123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
配置php
//配置php源
[root@server ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@server ~]# rpm -Uvh remi-release-7.rpm
[root@server ~]# yum makecache --enablerepo=remi
//安装依赖包
[root@server ~]# 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 php72-php-mysqlnd
//下载php
[root@server ~]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
//编译安装php
[root@server ~]# tar xf php-7.2.8.tar.xz
[root@server ~]# cd php-7.2.8
[root@server php-7.2.8]# ./configure --prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--enable-ftp \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--enable-json \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix
[root@server php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
[root@server php-7.2.8]# make install
//安装后配置
[root@server ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@server ~]# source /etc/profile.d/php7.sh
[root@server php-7.2.8]# which php
/usr/local/php7/bin/php
[root@server 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
[root@server php-7.2.8]# cp php.ini-production /etc/php.ini
[root@server php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@server php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[root@server php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@server php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
//编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf):
//配置fpm的相关选项为你所需要的值:
[root@server ~]# 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@server ~]# 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-fpm
[root@server ~]# service php-fpm start
Starting php-fpm done
//默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验证其是否已经监听在相应的套接字
[root@server ~]# 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 :::*
[root@server ~]# ps -ef|grep php
root 81070 1 0 14:13 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 81071 81070 0 14:13 ? 00:00:00 php-fpm: pool www
nobody 81072 81070 0 14:13 ? 00:00:00 php-fpm: pool www
nobody 81073 81070 0 14:13 ? 00:00:00 php-fpm: pool www
nobody 81074 81070 0 14:13 ? 00:00:00 php-fpm: pool www
nobody 81075 81070 0 14:13 ? 00:00:00 php-fpm: pool www
root 81079 83354 0 14:15 pts/1 00:00:00 grep --color=auto php
root@server php]# /bin/systemctl start php-fpm.service
[root@server php]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:57330 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::49181 :::*
LISTEN 0 80 :::3306 :::*
生成测试界面
[root@server php]# sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf
[root@server php]# sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd24/httpd.conf
[root@server php]# mkdir /usr/local/apache/htdocs/wangqing.com
[root@server php]# vim /usr/local/apache/htdocs/wangqing.com/index.php
[root@server php]# cat /usr/local/apache/htdocs/wangqing.com/index.php
<?php
phpinfo()
?>
[root@server php]# chown -R apache.apache /usr/local/apache/htdocs/
[root@server php]# ll /usr/local/apache/htdocs/ -d
drwxr-xr-x. 3 apache apache 44 12月 19 11:21 /usr/local/apache/htdocs/
[root@server php]# vim /etc/httpd24/httpd.conf
[root@server php]# tail -10 /etc/httpd24/httpd.conf
DocumentRoot "/usr/local/apache/htdocs/wangqing.com"
ServerName www.wangqing.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/wangqing.com/$1
<Directory "/usr/local/apache/htdocs/wangqing.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
[root@server php]# vim /etc/httpd24/httpd.conf
//添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
修改DirectoryIndex index.html --> DirectoryIndex index.php index.html
[root@server ~]# apachectl restart
[root@server ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:57330 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::49181 :::*
LISTEN 0 80 :::3306 :::*
//关闭防火墙
[root@server ~]# systemctl stop firewalld
[root@server ~]# setenforce
来源:CSDN
作者:mylovewxl
链接:https://blog.csdn.net/hhsd123/article/details/103702490