LAMP----->2.4 模块实现
yum groupinstall "Development Tools" "Server Platform Development"------>安装包组1、编译安装Apache httpd-2.4.9需要较新版本的apr和apr-util,因此需要事先对其进行升级 (1)、编译安装apr tar xf apr-1.5.0.tar.bz2cd apr-1.5.0./configure --prefix=/usr/local/apr make && make install (2)、编译安装apr-util tar xf apr-util-1.5.3.tar.bz2cd apr-util-1.5.3./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install (3)、编译安装httpd groupadd -r apache useradd -r -g apache apahce yum -y install pcre-devel ---->安装pcre-devel支持 tar xf httpd-2.4.9.tar.bz2cd httpd-2.4.9./configure --prefix=/usr/local/apache --sysconf=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --withzlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpmsshared= all --with-mpm=event make && make install3、修改httpd的主配置文件,设置其Pid文件的路径 编辑vim /etc/httpd24/httpd.conf,添加如下行即可: PidFile "/var/run/httpd/httpd24.pid"提供httpd 运行脚本cd /etc/rc.d/init.d/ cp httpd httpd24 vim httpd24 apachectl=/usr/local/apache/bin/apachectl ---------------->改的 httpd=${HTTPD-/usr/local/apache/bin/httpd} ---->查看pid路径--->/usr/local/apache/logs/httpd.pid pidfile=${PIDFILE-/var/run/httpd/httpd24.pid}lockfile=${LOCKFILE-/var/lock/subsys/httpd24}chkconfig --add httpd24 chkconfig --list httpd24 httpd24 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭 httpd -t ------------>检查语法hash -r --------------->清除缓存 vim /etc/profile.d/httpd.shexport PATH=/usr/local/apache/bin$PATH-------------->定义PATH读取 . /etc/profile.d/httpd.sh ------------->重读配置文件 编辑/etc/man.config,添加如下行即可 MANPATH /usr/local/apache/man 库文件和头文件的导出 输出apche的头文件至系统头文件路径/usr/include: 这可以通过简单的创建链接实现: ln -sv /usr/local/apache/include /usr/include/apache 输出mysql的库文件给系统库查找路径:echo ‘/usr/sbin/httpd‘ > /etc/ld.so.conf.d/httpd24.conf 而后让系统重新载入系统库: ldconfig service httpd24 start ss -tnl ---------------->查看80端口是否被监听到 ps aux | grep httpd----->查看工作模式 vim /etc/httpd24/httpd.conf ----------->配置文件 LoadModule deflate_module modules/mod_deflate.so----------->启用2、编译安装mariadb tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local准备数据目录 mkdir -pv /mydata/data------>创建数据存放目录 配置mariadb-----> groupadd -r -g 306 mysql useradd -r -g 306 -u 306 mysqlcd /usr/local/ ln -sv mariadb-5.5.36-linux-x86_64 mysqlcd /usr/local/mysql chown -R root:mysql ./* scripts/mysql_install_db --datadir=/mydata/data --user=mysql cp supper-files/mysql.server /etc/rc.d/init.d/mysqld chkconfig --add mysqld --->添加 chkconfig --list mysqld --->查看 mkdir /etc/mysql cp support-files/my-large.cnf /etc/mysql/my.cnf vim /etc/mysql/my.cnf 添加三个选项: datadir = /mydata/data innodb_file_per_table = on skip_name_resolve = on service mysqld start /usr/local/mysql/bin/mysql_secure_installation------------>安全初始化 mysql优化 编辑/etc/man.config,添加如下行即可: MANPATH /usr/local/mysql/man7、输出mysql的头文件至系统头文件路径/usr/include: 这可以通过简单的创建链接实现: ln -sv /usr/local/mysql/include /usr/include/mysql8、输出mysql的库文件给系统库查找路径:echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf 而后让系统重新载入系统库: ldconfig9、修改PATH环境变量,让系统可以直接使用mysql的相关命令。 vim /etc/profile.d/mysql.shexport PATH=/usr/local/mysql/bin:$PATH. /etc/profile.d/mysql.sh 安装php 解决依赖关系 yum -y groupinstall "Desktop Platform Development"yum -y install bzip2-devel libmcrypt-devel libxml2-devel2、编译安装php-php-5.4.26php-5.4.26.tar.bz2cd php-5.4.26./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --withmysqli=/ usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib -- with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-configfile- path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts make make testmake intall 为php提供配置文件: cp php.ini-production /etc/php.ini3、 编辑apache配置文件httpd.conf,以apache支持php# vim /etc/httpd24/httpd.conf1、添加如下二行 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps2、定位至DirectoryIndex index.html 修改为: DirectoryIndex index.php index.html 启动httpd服务 测试页面index.php示例如下: <?php$link = mysql_connect(‘127.0.0.1‘,‘root‘,‘mageedu‘);if ($link)echo "Success...";elseecho "Failure..."; phpinfo(); mysql_close(); ?> 用 wordpress测试 unzip wordpress-4.5.3-zh_CN.zip cp -rf wordpress /usr/local/apache/htdocs/cd /usr/local/apache/htdocs/wordpress cp wp-config-sample.php wp-config.php vim wp-config.php defile (‘DB_NAME‘, ‘wpdb‘); defile (‘DB_USER‘, ‘wpuser‘); defile (‘DB_PASSWORD‘, ‘wppword‘); 连上MySQL数据库 mysql -uroot -p GRANT ALL ON wpdb.* TO ‘wpuser‘@‘localhost‘ IDENTIFIED BY ‘wppword‘; CREATE DATABASE wpdb; FLUSH PRIVILEGES; mysql -uwpuser -pwppword SHOW DATABASES; http://192.168.159.128/wordpress 访问---->安装 ---------------------->虚拟主机 vim /etc/httpd24/httpd.conf#DocumentRoot "/usr/local/apache/htdocs"vim /etc/httpd24/extra/httpd-vhosts.conf <VirtualHost 192.168.159.128 *:80> DocumentRoot "/web/vhost/www1/"ServerName www1.stuX.com ErrorLog "/var/log/httpd/www1.err"CustomLog "/var/log/httpd/www1.access" common <Directory "/web/vhost/www1"> AllowOverride None Options None Require all granted </Directory> </VirtualHost> <VirtualHost 192.168.159.128 *:80> DocumentRoot "/web/vhosts/www2"ServerName www2.stuX.com ErrorLog "/var/log/httpd/www2.err"CustomLog "/var/log/httpd/www2.access" common <Directory "/web/vhost/www2"> AllowOverride None Options None Require all granted Require local</Directory> </VirtualHost> mkdir -pv /web/vhost/{www1,www2}echo "www1.site" > /web/vhost/www1/index.html && echo "www2.site" > /web/vhost/www2/index.html vim /etc/httpd24/httpd.conf Include /etc/httpd24/extra/httpd-vhosts.conf------>启动这一项 [[email protected] ~]# curl www1.stuX.comwww1.site [[email protected] ~]# curl www2.stuX.comwww2.site vim /etc/httpd24/extra/httpd-vhosts.conf vim /etc/httpd24/extra/httpd-vhosts.conf <VirtualHost 192.168.159.128 *:80> DocumentRoot "/web/vhost/www1/"ServerName www1.stuX.com ErrorLog "/var/log/httpd/www1.err"CustomLog "/var/log/httpd/www1.access" common <Directory "/web/vhost/www1"> AllowOverride None Options None Require all granted </Directory> <Location /server-status> AuthType Basic AuthName "Only for Admin"AuthUserFile "/usr/local/apache/.htpasswd"Require valid-user SetHandler server-status AllowOverride None Options None </Location </VirtualHost> ./htpasswd -m -c /usr/local/apache/.htpasswd admin
LAMP---->2.4 fpm实现
yum groupinstall "Development Tools" "Server Platform Development"------>安装包组1、编译安装Apachehttpd-2.4.9需要较新版本的apr和apr-util,因此需要事先对其进行升级 (1)、编译安装apr tar xf apr-1.5.0.tar.bz2 cd apr-1.5.0./configure --prefix=/usr/local/apr make && make install (2)、编译安装apr-util tar xf apr-util-1.5.3.tar.bz2 cd apr-util-1.5.3 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmake && make install (3)、编译安装httpd groupadd -r apache useradd -r -g apache apahce yum -y install pcre-devel ---->安装pcre-devel支持 tar xf httpd-2.4.9.tar.bz2 cd httpd-2.4.9./configure --prefix=/usr/local/apache --sysconf=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --withzlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpmsshared= all --with-mpm=event make && make install3、修改httpd的主配置文件,设置其Pid文件的路径 编辑vim /etc/httpd24/httpd.conf,添加如下行即可:PidFile "/var/run/httpd/httpd24.pid"提供httpd 运行脚本 cd /etc/rc.d/init.d/ cp httpd httpd24 vim httpd24 apachectl=/usr/local/apache/bin/apachectl ---------------->改的 httpd=${HTTPD-/usr/local/apache/bin/httpd} ---->查看pid路径--->/usr/local/apache/logs/httpd.pid pidfile=${PIDFILE-/var/run/httpd/httpd24.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd24} chkconfig --add httpd24 chkconfig --list httpd24 httpd24 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭 httpd -t ------------>检查语法 hash -r --------------->清除缓存 vim /etc/profile.d/httpd.sh export PATH=/usr/local/apache/bin$PATH-------------->定义PATH读取 . /etc/profile.d/httpd.sh ------------->重读配置文件 编辑/etc/man.config,添加如下行即可MANPATH /usr/local/apache/man 库文件和头文件的导出 输出apche的头文件至系统头文件路径/usr/include: 这可以通过简单的创建链接实现: ln -sv /usr/local/apache/include /usr/include/apache 输出mysql的库文件给系统库查找路径: echo ‘/usr/sbin/httpd‘ > /etc/ld.so.conf.d/httpd24.conf 而后让系统重新载入系统库: ldconfig service httpd24 start ss -tnl ---------------->查看80端口是否被监听到 ps aux | grep httpd----->查看工作模式 vim /etc/httpd24/httpd.conf ----------->配置文件LoadModule deflate_module modules/mod_deflate.so----------->启用2、编译安装mariadb tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local 准备数据目录 mkdir -pv /mydata/data------>创建数据存放目录 配置mariadb-----> groupadd -r -g 306 mysql useradd -r -g 306 -u 306 mysql cd /usr/local/ ln -sv mariadb-5.5.36-linux-x86_64 mysql cd /usr/local/mysql chown -R root:mysql ./* scripts/mysql_install_db --datadir=/mydata/data --user=mysql cp supper-files/mysql.server /etc/rc.d/init.d/mysqld chkconfig --add mysqld --->添加 chkconfig --list mysqld --->查看 mkdir /etc/mysql cp support-files/my-large.cnf /etc/mysql/my.cnf vim /etc/mysql/my.cnf 添加三个选项: datadir = /mydata/datainnodb_file_per_table = on skip_name_resolve = on service mysqld start /usr/local/mysql/bin/mysql_secure_installation------------>安全初始化 mysql优化 编辑/etc/man.config,添加如下行即可:MANPATH /usr/local/mysql/man7、输出mysql的头文件至系统头文件路径/usr/include: 这可以通过简单的创建链接实现: ln -sv /usr/local/mysql/include /usr/include/mysql8、输出mysql的库文件给系统库查找路径: echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf 而后让系统重新载入系统库: ldconfig9、修改PATH环境变量,让系统可以直接使用mysql的相关命令。 vim /etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin:$PATH. /etc/profile.d/mysql.sh 编译安装php 请配置好yum源(系统安装源及epel源)后执行如下命令:# yum -y groupinstall "Desktop Platform Development"# yum -y install bzip2-devel libmcrypt-devel libxml2-devel编译安装php-5.4.26# tar xf php-5.4.26.tar.bz2# cd php-5.4.26# ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-openssl --withmysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-configfile- scan-dir=/etc/php.d --with-bz2#make#make test#make install为php提供配置文件:# cp php.ini-production /etc/php.ini3、配置php-fpm 为php-fpm提供SysV init脚本,并将其添加至服务列表:# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm# chmod +x /etc/rc.d/init.d/php-fpm# chkconfig --add php-fpm# chkconfig php-fpm on为php-fpm提供配置文件:# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf编辑php-fpm的配置文件:# vim /usr/local/php5/etc/php-fpm.conf配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行): pm.max_children = 50pm.start_servers = 5pm.min_spare_servers = 2pm.max_spare_servers = 8pid = /usr/local/php5/var/run/php-fpm.pid 接下来就可以启动php-fpm了:# service php-fpm start使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):# ps aux | grep php-fpm默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验正其是否已经监听在相应的套接字。# netstat -tnlp | grep php-fpmtcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 689/php-fpm 三、配置httpd-2.4.91、启用httpd的相关模块 在Apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩 充,因此,这两个模块都要加载LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so3、编辑apache配置文件httpd.conf,让apache能识别php格式的页面,并支持php格式的主页# vim /etc/httpd24/httpd.conf1、添加如下二行AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps2、定位至DirectoryIndex index.html 修改为:DirectoryIndex index.php index.html 在相应的虚拟主机中添加类似如下两行。ProxyRequests OffProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1测试页面index.php示例如下: <?php$link = mysql_connect(‘127.0.0.1‘,‘root‘,‘mageedu‘);if ($link) echo "Success...";elseecho "Failure..."; phpinfo(); mysql_close(); ?>
时间: 2024-10-11 12:55:06