标签归档:Apache

一键安装LAMP和LNMP

可以一键安装LAMP或者LNMP,自由选择

同时扩展了ssh、oci、ssl

目标项目中使用了phalcon框架和jdk,不需要的可以不安装。

不多说,上代码


#!bin/sh

function init()
{
#import RPM-GPG-KEY and install initscripts,wget,git
yum clean all
# cp -rf ./repo/aliyun.repo /etc/yum.repos.d/
# cp -rf ./repo/epel.repo /etc/yum.repos.d/
rpm --import /etc/pki/rpm-gpg/RPM* && rpm --import http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
yum -y install gcc gcc-c++ bison autoconf automake initscripts wget git
}

function install_httpd()
{
yum -y install httpd httpd-devel
sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/g' /etc/httpd/conf/httpd.conf
}

function install_nginx()
{
echo -e "[nginx]\nname=nginx repo\nbaseurl=http://nginx.org/packages/centos/6/x86_64\ngpgcheck=0\nenabled=1" >> /etc/yum.repos.d/nginx.repo
yum -y install nginx

}

function download_php()
{
wget -c http://cn2.php.net/distributions/php-5.6.29.tar.bz2
}

function install_php()
{
#install support libs
yum -y install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel mhash mcrypt libtool-ltdl libtool-ltdl-devel bzip2 bzip2-devel freetype freetype-devel openldap openldap-devel openssl openssl-devel

cp -frp /usr/lib64/libldap* /usr/lib/

#install php
tar -jxvf php-5.6.29.tar.bz2 && cd php-5.6.29 && ./configure --with-apxs2=/usr/sbin/apxs --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql-sock --with-pdo-mysql=mysqlnd --with-openssl --with-gd --with-iconv --with-jpeg-dir=/usr/local/lib --with-png-dir --with-freetype-dir --with-zlib --with-bz2 --with-libxml-dir --with-gettext --with-curl --with-mhash --with-mcrypt --enable-mbstring --enable-mbregex --with-ldap --with-ldap-sasl --with-xmlrpc --enable-gd-native-ttf --enable-pdo --enable-pcntl --enable-sockets --enable-bcmath --enable-xml --enable-zip --enable-soap --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-maintainer-zts --enable-opcache --enable-cgi --without-pear --disable-phar >> ../install_php_log && make >> ../install_php_log && make install >> ../install_php_log && cd ../

#config PHP
cp ./php-5.6.29/php.ini-development $(php-config --prefix)/lib/php.ini && sed -i 's/\;date\.timezone \=/date\.timezone \=PRC/g' $(php-config --prefix)/lib/php.ini && sed -i "s/\;include_path \= \"\.\:\/php\/includes\"/include_path \= \"\$\(php-config --prefix\)\/lib\/php\"/g" $(php-config --prefix)/lib/php.ini && ln -s $(php-config --prefix)/bin/php /usr/bin/php
echo "AddHandler application/x-httpd-php .php" >> /etc/httpd/conf/httpd.conf
echo "" > /var/www/html/i.php
}

function install_phpfpm()
{
#install support libs
yum -y install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel mhash mcrypt libtool-ltdl libtool-ltdl-devel bzip2 bzip2-devel freetype freetype-devel openldap openldap-devel openssl openssl-devel

cp -frp /usr/lib64/libldap* /usr/lib/

#install php
tar -jxvf php-5.6.29.tar.bz2 && cd php-5.6.29 && ./configure --enable-fpm --enable-cgi --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql-sock --with-pdo-mysql=mysqlnd --with-openssl --with-gd --with-iconv --with-jpeg-dir=/usr/local/lib --with-png-dir --with-freetype-dir --with-zlib --with-bz2 --with-libxml-dir --with-gettext --with-curl --with-mhash --with-mcrypt --enable-mbstring --enable-mbregex --with-ldap --with-ldap-sasl --with-xmlrpc --enable-gd-native-ttf --enable-pdo --enable-pcntl --enable-sockets --enable-bcmath --enable-xml --enable-zip --enable-soap --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-maintainer-zts --enable-opcache --enable-cgi --without-pear --disable-phar >> ../install_php_log && make >> ../install_php_log && make install >> ../install_php_log && cd ../

#config PHP
cp ./php-5.6.29/php.ini-development $(php-config --prefix)/lib/php.ini && sed -i 's/\;date\.timezone \=/date\.timezone \=PRC/g' $(php-config --prefix)/lib/php.ini && sed -i "s/\;include_path \= \"\.\:\/php\/includes\"/include_path \= \"\$\(php-config --prefix\)\/lib\/php\"/g" $(php-config --prefix)/lib/php.ini && ln -s $(php-config --prefix)/bin/php /usr/bin/php

#config php-fpm. use -t test fpm’s configs
cp ./php-5.6.29/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && chmod a+x /etc/init.d/php-fpm && chkconfig --add php-fpm && chkconfig php-fpm on && cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf && /usr/local/sbin/php-fpm -c $(php-config --prefix)/lib/php.ini -y /usr/local/etc/php-fpm.conf -t && /usr/local/sbin/php-fpm -c $(php-config --prefix)/lib/php.ini -y /usr/local/etc/php-fpm.conf

#write something into readme.txt
echo -e "start php-fpm:\n/usr/local/sbin/php-fpm -c $(php-config --prefix)/lib/php.ini -y /usr/local/etc/php-fpm.conf\nstop php-fpm:\nkill -INT 'cat /usr/local/php/var/run/php-fpm.pid'\nOR\nservice php-fpm stop\nreboot php-fpm:\nkill -USR2 'cat /usr/local/php/var/run/php-fpm.pid'\nOR\nservice php-fpm reboot" >> ../readme.txt

#config nginx
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
echo -e "server\n{\n listen 80;\n server_name localhost;\n root /var/www/zhenzhidaole;\n access_log /var/log/nginx/access_zhenzhidaole_com.log;\n error_log /var/log/nginx/error_zhenzhidaole_com.log;\n index index.html index.php;\n location ~ \.php$ {\n fastcgi_pass 127.0.0.1:9000;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;\n include fastcgi_params; \n }\n}" >> /etc/nginx/conf.d/vhost.conf

mkdir -p /var/www/html && echo "" > /var/www/html/i.php

service nginx restart
}

function install_php_by_yum()
{
yum install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel mhash mcrypt libtool-ltdl libtool-ltdl-devel bzip2 bzip2-devel freetype freetype-devel openldap openldap-devel openssl openssl-devel
yum -y install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml
yum -y install perl
yum -y install mod_python
}

function download_mysql()
{
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.16-1.el6.x86_64.rpm
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.16-1.el6.x86_64.rpm
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-devel-5.7.16-1.el6.x86_64.rpm
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.16-1.el6.x86_64.rpm
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.16-1.el6.x86_64.rpm
}

function install_mysql()
{
#install mysql
yum -y install libaio net-tools numactl
yum -y remove mysql*

echo -e "HOSTNAME=internal.hostname.DOMAIN.com" >> /etc/sysconfig/network

rpm -ivh mysql-community-common-5.7.16-1.el6.x86_64.rpm && rpm -ivh mysql-community-libs-5.7.16-1.el6.x86_64.rpm && rpm -ivh mysql-community-devel-5.7.16-1.el6.x86_64.rpm && rpm -ivh mysql-community-client-5.7.16-1.el6.x86_64.rpm && rpm -ivh mysql-community-server-5.7.16-1.el6.x86_64.rpm && echo "max_allowed_packet=200M" >> /etc/my.cnf && service mysqld start

#find the default password and save it into readme.txt
echo -e "\nmysql install information:" >> ../readme.txt
sed -n '/A temporary password is generated for root@localhost:/p' /var/log/mysqld.log >> ../readme.txt
echo -e "After login mysql,you need to do:\nstep 1: SET PASSWORD = PASSWORD(\"your new password\");\nstep 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;\nstep 3: flush privileges;" >> ../readme.txt
# echo -e "export MYSQL_HOME=/usr/local/mysql\nexport PATH=\$MYSQL_HOME/bin:\$PATH" >>/etc/profile && source /etc/profile
}

function download_ssh2()
{
wget -c https://www.libssh2.org/download/libssh2-1.8.0.tar.gz
wget -c http://pecl.php.net/get/ssh2-0.13.tgz
}

function install_ssh2()
{
tar -zxvf libssh2-1.8.0.tar.gz && cd libssh2-1.8.0 && ./configure --prefix=/usr/local/libssh2 && make && make install && cd ../
tar -zxvf ssh2-0.13.tgz && cd ssh2-0.13 && phpize && ./configure --prefix=/usr/local/ssh2 --with-ssh2=/usr/local/libssh2 && make && make install && echo "extension=ssh2.so" >> $(php-config --prefix)/lib/php.ini && cd ../
}

function download_oci()
{
# wget -c http://download.oracle.com/otn/linux/instantclient/11204/oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
# wget -c http://download.oracle.com/otn/linux/instantclient/11204/oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
wget -c http://pecl.php.net/get/PDO_OCI-1.0.tgz
wget -c http://pecl.php.net/get/oci8-2.0.12.tgz
}

Function install_oci()
{
#install oci8 support oracle11grc2
rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm && rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm && echo '/usr/lib/oracle/11.2/client64/lib/' > /etc/ld.so.conf.d/oracle-x86_64.conf && ln -s /usr/lib/oracle/11.2/client64 /usr/lib/oracle/11.2/client && ln -s /usr/include/oracle/11.2/client64 /usr/include/oracle/11.2/client && echo -e "export ORACLE_HOME=/usr/lib/oracle/11.2/client64/\nexport LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64:\$LD_LIBRARY_PATH\nexport NLS_LANG=\"AMERICAN_AMERICA.AL32UTF8\"" >> /etc/profile && source /etc/profile

tar -zxvf oci8-2.0.12.tgz && cd oci8-2.0.12 && phpize && ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib && make && make install && echo "extension=oci8.so" >> $(php-config --prefix)/lib/php.ini && cd ../

tar -zxvf PDO_OCI-1.0.tgz && cd PDO_OCI-1.0 && ln -s /usr/include/oracle/11.2 /usr/include/oracle/10.2.0.1 && ln -s /usr/lib/oracle/11.2 /usr/lib/oracle/10.2.0.1 && sed -i '101i 11.2)\n PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)\n \;\;' config.m4 && sed -i '10i elif test -f \$PDO_OCI_DIR/lib/libclntsh\.\$SHLIB_SUFFIX_NAME.11.2\; then\n PDO_OCI_VERSION=11\.2' config.m4 && sed -i 's/function_entry/zend_function_entry/g' pdo_oci.c && phpize && ./configure --with-pdo-oci=instantclient,/usr,11.2 && make && make install && echo "extension=pdo_oci.so" >> $(php-config --prefix)/lib/php.ini && cd ../

}

function download_phalcon()
{
git clone --depth=1 git://github.com/phalcon/cphalcon.git
}

function install_phalcon()
{
#install phalcon frameworks
cd cphalcon/build && ./install && echo "extension=phalcon.so" >> $(php-config --prefix)/lib/php.ini && cd ../../
}

function download_jdk()
{
# http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
}

function install_jdk()
{
install_path=$(pwd) && mkdir -p /usr/java && cp -rf jdk-8u111-linux-x64.tar.gz /usr/java/ && cd /usr/java && tar -zxvf jdk-8u111-linux-x64.tar.gz && echo -e "JAVA_HOME=/usr/java/jdk1.8.0_111\nCLASSPATH=\$JAVA_HOME/lib/\nPATH=\$PATH:\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin\nexport PATH JAVA_HOME CLASSPATH" >> /etc/profile && source /etc/profile && java -version && cd $install_path
}

function install_openssl()
{
yum -y install openssl mod_ssl
cd /etc/pki/tls/private/ && openssl genrsa 1024 >localhost.key && openssl req -new -key localhost.key > localhost.csr && openssl req -x509 -days 3650 -key localhost.key -in localhost.csr > localhost.crt && cp localhost.crt /etc/pki/tls/certs/localhost.crt
}

function test_http()
{
echo -e "Alias /webalias \"/var/www/alias\”\n\n Options Indexes MultiViews FollowSymLinks\n AllowOverride None\n Order allow,deny\n Allow from all\n" >> /etc/httpd/conf/httpd.conf
echo -e "\n ServerAdmin admin@zhenzhidaole.com\n DocumentRoot /var/www/html\n ServerName www.zhenzhidaole.com\n ErrorLog /var/www/logs/error_log\n CustomLog /var/www/logs/access_log common\n" >> /etc/httpd/conf/httpd.conf
mkdir -p /var/www/web && mkdir -p /var/www/alias
echo "" > /var/www/alias/s.php
echo -e "127.0.0.1 www.zhenzhidaole.com" >> /etc/hosts
service httpd restart
}

function test_phpinfo()
{
php -v
php -i |grep mcrypt
php -i |grep ssh
php -i |grep oci
php -i |grep phalcon
curl https://localhost/ -k
curl http://www.zhenzhidaole.com/c.php |grep oci

#
}

init()
install_httpd()
#install_nginx()
#download_php()
install_php()
#install_phpfpm()
#download_mysql()
install_mysql()
#download_ssh2()
install_ssh2()
#download_oci()
install_oci()
#download_phalcon()
install_phalcon()
#download_jdk()
install_jdk()
install_openssl()

#test_http()
#test_phpinfo()

附件下载install-php.sh
另外附repo文件repo

修改CentOS的yum源及安装配置PHP+MySQL环境

1. 换源,在这里我们使用搜狐的镜像源。 

 

1.1 备份CentOS-Base.repo
cd /etc/yum.repos.d/
cp CentOS-Base.repo CentOS-Base.repo.bak
1.2 替换源
用vi打开CentOS-Base.repo,并将内容清空,然后将下面的内容复制进去,并保存。
# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever – Base
baseurl=http://mirrors.sohu.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
#released updates
[updates]
name=CentOS-$releasever – Updates
baseurl=http://mirrors.sohu.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever – Addons
baseurl=http://mirrors.sohu.com/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
baseurl=http://mirrors.sohu.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
baseurl=http://mirrors.sohu.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
1.3 更新一下
yum -y update
2. 用yum升级安装Apache, Mysql, PHP.
Centos默认已安装相应的环境,但是版本可能达不到相关的要求。
A. 安装部分
2.1 安装Apache
yum -y install httpd httpd-devel
安装完成后,用/etc/init.d/httpd start 启动apache
设为开机启动:chkconfig httpd on
2.2 安装mysql
2.2.1 yum install mysql mysql-server mysql-devel
同样,完成后,用/etc/init.d/mysqld start 启动mysql
2.2.2设置mysql密码
mysql -u root -p (提示输入密码时,直接回车即可。)
mysql>; USE mysql;
mysql>; UPDATE user SET Password=PASSWORD(‘newpassword’) WHERE user=’root’;
mysql>; FLUSH PRIVILEGES;
授权远程访问
mysql>; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
2.2.3设为开机启动
chkconfig mysqld on
3. 安装php 
yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml
/etc/init.d/httpd start
4. 测试一下 
4.1 在/var/www/html/新建个test.php文件,将以下内容写入,然后保存。
<?
phpinfo();
?>
安装其他
yum -y install perl
yum -y install mod_python
4.2 防火墙配置
a.添加.允许访问端口{21: ftp, 22:ssh, 80: http}.  vi /etc/sysconfig/iptables
iptables -I RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 21 -j ACCEPT
iptables -I RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
iptables -I RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
b.关闭防火墙{不推荐}.
service iptables stop
c.重启iptables
service iptables restart
4.3 然后在客户端浏览器里打开http://serverip/test.php,若能成功显示,则表示安装成功。
至此,安装完毕。

ubuntu apache rewrite

解决方法一

需要通过命令,或者自己重新创建个软连接才可以。
命令是:sudo a2enmod rewrite
软连接是:sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

因为Ubuntu下,Apache的配置文件及目录结构不大一样,所以mods-avalilable下的是可用的模块,而真正启用了的模块是在mods-enable目录底下的。所以自己创建软连接也可以实现启用rewrite模块。

除了启用rewrite外,还有地方需要修改的,如果你的站点只有一个,那修改/etc/apache2/sites-available/default这个文件就可以

<Directory />
Options FollowSymLinks
AllowOverride None(修改为AllowOverride All)
</Directory>
<Directory “/var/orioner”>
Options Indexes FollowSymLinks MultiViews
AllowOverride None(修改为AllowOverride All)
Order allow,deny
allow from all
</Directory>
其实网上其它地方贴出来的解决办法是吧Options FollowSymlinks的给改了就行了。其实不行,还要把Options Indexes FollowSymLinks MultiViews的也给改了才可以。

 

==============================================================================

解决方法二

在终端中执行

sudo a2enmod rewrite

指令后,即启用了 Mod_rewrite 模块。

另外,也可以通过将 /etc/apache2/mods-available/rewrite.load 连接到 /etc/apache2/mods-enabled/rewrite.load 来打开 Mod_rewrite 模块。用指令操作就是:

sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

一点小提示

事实上,当我在 Ubuntu 中采用上述做法并重启了 Apache 服务后,仍然无法正常 rewrite 网址。这里,还有一点需要注意的地方:

sudo vim /etc/apache2/sites-enabled/000-default

将其中的:

AllowOverride None

修改为:

AllowOverride All

上面的 /etc/apache2/sites-enabled/000-default 实则为 /etc/apache2/sites-available/default 的连接。而 AllowwOverride None 则会完全忽略 .htaccess 文件,自然其中所定义的 rewrite 规则也就不能生效了。

最后,别忘了使用下列指令来重启 Apache:

sudo /etc/init.d/apache2 restart.

apache note 日志 及详细设置

引:http://blog.csdn.net/btbtd/archive/2005/02/15/288027.aspx
# apache note | Apache 学习笔记(心得) by Emerald 绿色学院 – Green Institute

# 分类:
# 01.常规设置
# 02.虚拟主机
# 03. + Alias
# 04..htaccess
# 05.Log
# 06.URL Rewrite
# 07.其他

########01.常规设置

# Listen
# 监听端口, 例: Listen 80

# ServerRoot
# Apache 所在目录, 例: ServerRoot “C:/Program Files/Apache Group/Apache2” (WINDOWS)

# ServerAdmin
# 错误报告邮箱, 例: ServerAdmin btbtd@yahoo.com.cn

# DocumentRoot
# 站点根目录, 例: DocumentRoot “I:/gi-2288”

# DirectoryIndex
# 配置目录索引文件,
# 例: DirectoryIndex index.php index.php3 index.html index.htm

# ServerName
# 服务器域名/IP地址, 例 继续阅读apache note 日志 及详细设置

linux apachectl命令详解

功能说明:可用来控制Apache HTTP服务器的程序。
语  法:apachectl [configtest][fullstatus][graceful][help][restart][start][status][stop]
补充说明:apachectl是slackware内附Apache HTTP服务器的script文件,可供管理员控制服务器,但在其他Linux的Apache HTTP服务器不一定有这个文件。
参  数:
configtest 检查设置文件中的语法是否正确。
fullstatus 显示服务器完整的状态信息。
graceful 重新启动Apache服务器,但不会中断原有的连接。
help 显示帮助信息。
restart 重新启动Apache服务器。
start 启动Apache服务器。
status 显示服务器摘要的状态信息。
stop 停止Apache服务器。

本文所处位置:Linux爱好者 » 《linux apachectl命令详解》