一、编译部署Apache2.4.25
1、环境准备
#设置或停止防火墙: [root@localhost ~]# systemctl stop firewalld.service [root@localhost ~]# systemctl disable firewalld.service
#关闭selinux: 临时关闭: [root@localhost ~]# setenforce 0永久关闭(修改配置文件): [root@localhost ~]# vi /etc/selinux/config 改成SELINUX=disabled
#卸载系统默认安装的Apache软件包: [root@localhost ~]# rpm -qa httpd* [root@localhost ~]# rpm -e --nodeps 包名 有多个httpd*,用脚本删除for name in `rpm -qa httpd*`;do rpm -e --nodeps $name;done#安装依赖包: [root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm [root@localhost ~]# yum install gcc gcc-c++ zlib-devel expat-devel libxml2-devel libtools openssl openssl-devel wget lrzsz vim lynx -y 如果libxml2-devel没安装会报错https://blog.51cto.com/castiel/2051440#新建安装包存放目录: [root@localhost ~]# mkdir -p /root/soft
2、源码安装apr、apr-util、pcre包
#安装apr包: [root@localhost ~]# cd /root/soft [root@localhost soft]# wget http://mirrors.hust.edu.cn/apache/apr/apr-1.6.5.tar.gz [root@localhost soft]# tar -zxvf apr-1.6.5.tar.gz [root@localhost soft]# cd apr-1.6.5 [root@localhost apr-1.6.5]# vi configure 编辑configure配置文件,将这行代码注释掉: # $RM "$cfgfile" 编译 [root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr [root@localhost apr-1.6.5]# make [root@localhost apr-1.6.5]# make install#安装apr-util包: [root@localhost ~]# cd /root/soft [root@localhost soft]# wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.gz [root@localhost soft]# tar -zxvf apr-util-1.6.1.tar.gz [root@localhost soft]# 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#安装pcre包: [root@localhost ~]# cd /root/soft [root@localhost soft]# wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz [root@localhost soft]# tar -zxvf pcre-8.42.tar.gz [root@localhost soft]# cd pcre-8.42 [root@localhost pcre-8.42]# ./configure --prefix=/usr/local/pcre/ [root@localhost pcre-8.42]# make [root@localhost pcre-8.42]# make install
3、编译安装apache包
#安装apache包: [root@localhost ~]# cd /root/soft [root@localhost soft]# wget http://archive.apache.org/dist/httpd/httpd-2.4.25.tar.gz [root@localhost soft]# tar -zxvf httpd-2.4.25.tar.gz [root@localhost soft]# cd httpd-2.4.25 [root@localhost httpd-2.4.25]# ./configure --help(可以查看编译的参数说明) [root@localhost httpd-2.4.25]# ./configure \ --prefix=/usr/local/apache2.4.25 \ --sysconfdir=/etc/httpd \ --with-pcre=/usr/local/pcre \ --with-apr-util=/usr/local/apr-util \ --with-apr=/usr/local/apr \ --enable-so \ --enable-deflate \ --enable-expires \ --enable-headers \ --enable-ssl \ --enable-cgi \ --enable-proxy \ --enable-proxy-fcgi \ --enable-rewrite \ --enable-mpms-shared=all \ --with-mpm=prefork \ --enable-mods-shared=most \ --enable-dav \ --enable-dav-fs \ --enable-dav-lock [root@localhost httpd-2.4.25]# make [root@localhost httpd-2.4.25]# make install#做软链接(意义非常大) [root@localhost httpd-2.4.25]# cd /usr/local [root@localhost local]# ln -s apache2.4.25 apache [root@localhost local]# cd ~#检查编译安装情况 [root@localhost ~]# /usr/local/apache/bin/apachectl -l Compiled in modules:core.cmod_so.chttp_core.c [root@localhost ~]# /usr/local/apache/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_prefork_module (shared) authn_file_module (shared) authn_core_module (shared) authz_host_module (shared) authz_groupfile_module (shared) authz_user_module (shared) authz_core_module (shared) access_compat_module (shared) auth_basic_module (shared) reqtimeout_module (shared) filter_module (shared) mime_module (shared) log_config_module (shared) env_module (shared) headers_module (shared) setenvif_module (shared) version_module (shared) unixd_module (shared) status_module (shared) autoindex_module (shared) dir_module (shared) alias_module (shared)
4、启动apache并测试
[root@localhost ~]# /usr/local/apache/bin/apachectl start httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName [root@localhost ~]# vi /etc/httpd/httpd.conf 将这行注释取消掉,并再启动。 # ServerName www.example.com:80 [root@localhost ~]# /usr/local/apache/bin/apachectl start#开机启动方法: [root@localhost ~]# cp /usr/local/apache2.4.25/bin/apachectl /etc/rc.d/init.d/httpd [root@localhost ~]# vi /etc/rc.d/init.d/httpd 编辑httpd文件,在#!/bin/sh下面添加以下两句后保存 #chkconfig: 345 70 70 #description: apache 把Apache添加到系统服务并自启: [root@localhost ~]# chmod +x /etc/init.d/httpd [root@localhost ~]# chkconfig --add httpd #加入系统服务 [root@localhost ~]# chkconfig httpd on #开机自启 这样就可以使用systemctl start|stop|restart httpd 启动|关|重启Apache服务了#查看80端口验证: [root@localhost ~]# lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 55401 root 4u IPv6 61399 0t0 TCP *:http (LISTEN) httpd 55402 daemon 4u IPv6 61399 0t0 TCP *:http (LISTEN) httpd 55403 daemon 4u IPv6 61399 0t0 TCP *:http (LISTEN) httpd 55404 daemon 4u IPv6 61399 0t0 TCP *:http (LISTEN)#查看httpd进程验证: [root@localhost ~]# ps -ef | grep http root 55401 1 0 16:57 ? 00:00:00 /application/apache2.4.7/bin/httpd -k start daemon 55402 55401 0 16:57 ? 00:00:00 /application/apache2.4.7/bin/httpd -k start daemon 55403 55401 0 16:57 ? 00:00:00 /application/apache2.4.7/bin/httpd -k start daemon 55404 55401 0 16:57 ? 00:00:00 /application/apache2.4.7/bin/httpd -k start root 55500 17403 0 16:59 pts/0 00:00:00 grep --color=auto http#web方式访问: http://192.168.146.128
二、安装PHP 7.2.10
yum安装方式:
#安装php [root@localhost ~]# yum -y remove httpd-tools.x86_64 [root@localhost ~]# whereis php [root@localhost ~]# rm -rf /usr/lib64/php /etc/php /etc/php.d/ /etc/php.ini /usr/local/php /usr/share/php /usr/local/php [root@localhost ~]# yum -y remove php* [root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm [root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm [root@localhost ~]# yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml#配置文件 [root@localhost ~]# cp /usr/lib64/httpd/modules/libphp7-zts.so /usr/local/apache2.4.25/modules/ [root@localhost ~]# cp /usr/lib64/httpd/modules/libphp7.so /usr/local/apache2.4.25/modules/#相关启动命令 [root@localhost ~]# systemctl enable php-fpm [root@localhost ~]# systemctl start php-fpm [root@localhost ~]# systemctl status php-fpm
编译安装方式:
#新增帐号: [root@localhost ~]# groupadd www [root@localhost ~]# useradd -s /sbin/nologin -g www -M www#安装依赖: [root@localhost ~]# yum install gcc autoconf gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel systemd-devel openjpeg-devel [root@localhost ~]# yum install autoconf patch m4 bison bzip2-devel pam-devel gmp-devel libicu-devel curl-devel pcre-devel libtool-libs libtool-ltdl-devel libwebp-devel libXpm-devel libvpx-devel libjpeg-devel libpng-devel freetype-devel oniguruma-devel aspell-devel enchant-devel readline-devel unixODBC-devel libtidy-devel openldap-devel libxslt-devel net-snmp net-snmp-devel libtoo会生产libphp7.so#安装php7.2.10: [root@localhost ~]# wget http://cn2.php.net/distributions/php-7.2.10.tar.gz [root@localhost ~]# tar zxvf php-7.2.10.tar.gz [root@localhost ~]# cd php-7.2.10 [root@localhost php-7.2.10]# ./configure \ --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-zlib-dir \ --with-freetype-dir \ --enable-mbstring \ --with-libxml-dir=/usr \ --enable-xmlreader \ --enable-xmlwriter \ --enable-soap \ --enable-calendar \ --with-curl \ --with-zlib \ --with-gd \ --with-pdo-sqlite \ --with-pdo-mysql \ --with-mysqli \ --with-mysql-sock \ --enable-mysqlnd \ --disable-rpath \ --enable-inline-optimization \ --with-bz2 \ --with-zlib \ --enable-sockets \ --enable-sysvsem \ --enable-sysvshm \ --enable-pcntl \ --enable-mbregex \ --enable-exif \ --enable-bcmath \ --with-mhash \ --enable-zip \ --with-pcre-regex \ --with-jpeg-dir=/usr \ --with-png-dir=/usr \ --with-openssl \ --enable-ftp \ --with-kerberos \ --with-gettext \ --with-xmlrpc \ --with-xsl \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --with-fpm-systemd \ --disable-fileinfo \ --disable-phpdbg \ --disable-dtrace \ --enable-opcache [root@localhost php-7.2.10]# make [root@localhost php-7.2.10]# make test [root@localhost php-7.2.10]# make install#配置文件: [root@localhost php-7.2.10]# cp php.ini-production /usr/local/php/etc/php.ini [root@localhost php-7.2.10]# cd /usr/local/php/etc [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf [root@localhost etc]# vim php-fpm.conf error_log = /usr/local/php/var/php-fpm.log pid = /usr/local/php/var/run/php-fpm.pid [root@localhost etc]]# cd /usr/local/php/etc/php-fpm.d [root@localhost php-fpm.d]]# cp www.conf.defaultwww.conf#管理php-fpm服务: [root@localhost php-fpm.d]]# cd /root/php-7.2.10 [root@localhost php-7.2.10]# cp ./sapi/fpm/php-fpm.service /usr/lib/systemd/system/ [root@localhost ~]# systemctl enable php-fpm [root@localhost ~]# systemctl start php-fpm [root@localhost ~]# systemctl status php-fpm#添加环境变量: [root@localhost ~]# vim /etc/profile 在末尾追加: export PATH=$PATH:'/usr/local/php/bin/' [root@localhost ~]# source /etc/profile#验证版本: [root@localhost ~]# php -v PHP 7.2.10 (cli) (built: Jan 21 2019 23:25:27) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
三、配置apaache2.4.25支持php7.2.10
1、配置用户、网站目录、上传网站代码和设置权限
新建用户和用户组: [root@localhost ~]# useradd -M -s /sbin/nologin gxm [root@localhost ~]# mkdir -p /opt/www/ [root@localhost ~]# cd /opt/www/ [root@localhost www]# mkdir drupal [root@localhost www]# chown -R gxm.gxm drupal
2、编辑apache的httpd.conf配置文件
#更改httpd.conf配置文件: [root@localhost ~]# vi /etc/httpd/httpd.conf ServerRoot "/usr/local/apache2.4.25" ServerTokens Prod Listen 7777 LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule ssl_module modules/mod_ssl.so#MPM方式改成EVENT LoadModule mpm_event_module modules/mod_mpm_event.so #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so#设置php-fpm方式: <IfModule mpm_event_module>ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/opt/www/drupal/$1 </IfModule>User gxm Group gxm<FilesMatch \.php$>SetHandler "proxy:fcgi://127.0.0.1:9000"SetHandler application/x-httpd-php </FilesMatch>ServerName 127.0.0.1:7777DocumentRoot "/opt/www/drupal" <Directory "/opt/www/drupal">Options Indexes FollowSymLinksAllowOverride AllRequire all granted </Directory><IfModule dir_module>DirectoryIndex index.php index.html </IfModule>AddType application/x-compress .Z AddType application/x-gzip .gz .tgz #在上面两行下加下面这三行 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps ExtendedStatus OnInclude /etc/httpd/extra/httpd-mpm.conf TraceEnable off
3、编辑http-mpm.conf配置文件
[root@localhost ~]# vi /etc/httpd/extra/httpd-mpm.conf 相关选项更改成如下: # prefork MPM <IfModule mpm_prefork_module>StartServers 50MinSpareServers 80MaxSpareServers 256MaxRequestWorkers 256MaxConnectionsPerChild 0 </IfModule># worker MPM <IfModule mpm_worker_module>StartServers 5MinSpareThreads 50MaxSpareThreads 100ThreadsPerChild 100MaxRequestWorkers 10000MaxConnectionsPerChild 0ServerLimit 150 </IfModule># event MPM <IfModule mpm_event_module>ServerLimit 10000StartServers 6MinSpareThreads 75MaxSpareThreads 250ThreadsPerChild 25MaxRequestWorkers 4000MaxConnectionsPerChild 2000 </IfModule># WinNT MPM <IfModule mpm_winnt_module>ThreadsPerChild 2000MaxConnectionsPerChild 20000 </IfModule>
4、验证是否是event模式
一般默认是worker和perfork模式,但是event针对高并发表现好,不过对SSL支持的不是非常好。 [root@localhost ~]# /usr/local/apache/bin/httpd -V | grep "Server MPM" Server MPM: event
5、测试apche与PHP结合是否成功
在网站目录下建立一个文index.php的文件,验证php是否正常(下图表示成功): [root@localhost ~]# vi /opt/www/drupal/index.php <?php phpinfo(); ?> [root@localhost ~]# chown gxm.gxm /opt/www/drupal/index.php
四、部署MySQL 5.6.16
1、编译安装MySQL前的准备工作
#安装编译源码所需的工具和库 [root@localhost ~]# yum install gcc gcc-c++ ncurses-devel perl autoconf libtool -y#安装cmake,从http://www.cmake.org下载源码并编译安装 [root@localhost ~]# cd /root/soft [root@localhost soft]# wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz 如果提示SSL下载不了,就接--no-check-certificate参数 [root@localhost soft]# tar -xzvf cmake-2.8.10.2.tar.gz [root@localhost soft]# cd cmake-2.8.10.2 [root@localhost cmake-2.8.10.2]# ./bootstrap [root@localhost cmake-2.8.10.2]# make [root@localhost cmake-2.8.10.2]# make install [root@localhost cmake-2.8.10.2]# cd ~
2、设置MySQL用户和组
[root@localhost ~]# groupadd mysql [root@localhost ~]# useradd -r -g mysql mysql
3、新建MySQL所需要的目录
新建mysql安装目录 [root@localhost ~]# mkdir -p /usr/local/mysql 新建mysql数据库数据文件目录 [root@localhost ~]# mkdir -p /data/mysqldb
4、下载MySQL源码包并解压
[root@localhost ~]# cd /root/soft [root@localhost soft]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz [root@localhost soft]# tar -zxv -f mysql-5.6.16.tar.gz [root@localhost soft]# cd mysql-5.6.16 从mysql5.5起,mysql源码安装开始使用cmake了,设置源码编译配置脚本。 [root@localhost mysql-5.6.16]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1 [root@localhost mysql-5.6.16]# rm CMakeCache.txt [root@localhost mysql-5.6.16]# make [root@localhost mysql-5.6.16]# make install [root@localhost mysql-5.6.16]# cd ~
5、修改mysql相关目录所有者和组
#修改mysql安装目录权限: [root@localhost ~]# cd /usr/local/mysql [root@localhost mysql]# chown -R mysql:mysql . [root@localhost mysql]# cd ~#修改mysql数据库文件目录权限: [root@localhost ~]# cd /data/mysqldb [root@localhost mysqldb]# chown -R mysql:mysql . [root@localhost mysqldb]# cd ~
6、初始化mysql数据库
[root@localhost ~]# cd /usr/local/mysql [root@localhost ~]# scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb
7、生成my.cnf配置文件
[root@localhost ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf 注:如果/etc/my.cnf文件存在,则覆盖。
8、复制mysql服务启动脚本及加入PATH路径
[root@localhost ~]# cp support-files/mysql.server /etc/init.d/mysqld [root@localhost ~]# vi /etc/profile PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH export PATH [root@localhost ~]# source /etc/profile [root@localhost ~]# echo $PATH
9、启动mysql服务并加入开机自启动(可选这个步骤,以后可以自己启动的)
[root@localhost ~]# vi /etc/my.cnf #填入下面这行 datadir = /data/mysqldb [root@localhost ~]# service mysqld start [root@localhost ~]# chkconfig mysqld on
10、检查mysql服务是否启动
[root@localhost ~]# netstat -tulnp | grep 3306 [root@localhost ~]# mysql -u root -p 密码为空,如果能登陆上,则安装成功。
11、修改MySQL用户root的密码
[root@localhost ~]# /usr/local/mysql/bin/mysql_secure_installation 备注:密码为123456
12.测试php连接数据库
将网站目录下index.php内容替换成如下,验证数据库是否正常(如下图表示正常): [root@localhost ~]# vi /opt/www/drupal/index.php <?php$mysqli = new mysqli("localhost", "root", "123456");if(!$mysqli) {echo"database error";}else{echo"php env successful";}$mysqli->close(); ?>
可能会出现的错误
问题: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 解决: 新建一个链接或在mysql中加入-S参数,直接指出mysql.sock位置。 [root@localhost ~]# ln -s /usr/local/mysql/data/mysql.sock /tmp/mysql.sock [root@localhost ~]# /usr/local/mysql/bin/mysql -u root -S /usr/local/mysql/data/mysql.sock
五、部署测试网站
部署一个网站(CMS)作为测试,国内比较有名的CMS有织梦、phpcms等,国外有worepress、drupal等。这里以drupal 8为例。
详细可参考:https://www.drupal.org/docs/user_guide/en/index.html
1、建立数据库、数据库用户和密码、授权用户权限
[root@localhost ~]# mysql -u root -p Enter password: mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec) mysql> CREATE DATABASE drupal CHARACTER SET utf8 COLLATE utf8_general_ci mysql> CREATE USER drupal@localhost IDENTIFIED BY '123456'; mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY '123456'; mysql> flush privileges; mysql> exit
2、下载设置网站
[root@localhost ~]# cd /opt/www/ [root@localhost www]# wget https://ftp.drupal.org/files/projects/drupal-8.6.1.tar.gz [root@localhost www]# tar -zxvf drupal-8.6.1.tar.gz [root@localhost www]# rm -f drupal-8.6.1.tar.gz [root@localhost www]# mv drupal-8.6.1 drupal [root@localhost www]# chown -R gxm.gxm drupal
3、输入如下地址启动安装程序
http://192.168.146.128:7777/
转载于:https://blog.51cto.com/net881004/2346779