标签归档:text

把apache加入系统service,开机自启动

sudo cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

sudo

vi /etc/init.d/httpd

在文件开头加入下面几行:

#!/bin/sh

# chkconfig: 2345 85 15

# description: Apache is a World Wide Web server.

sudo chmod +x /etc/init.d/httpd

sudo /sbin/chkconfig –add httpd

sudo /sbin/chkconfig –list httpd

sudo ln -s /sbin/chkconfig /usr/bin/chkconfig

sudo ln -s /sbin/service /usr/bin/service

PHP编译安装时常见错误解决办法

http://www.poluoluo.com/jzxy/201505/364819.html

This article is post on https://coderwall.com/p/ggmpfa

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

代码如下:

yum -y install libxslt-devel

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.

代码如下:

yum -y install net-snmp-devel

configure: error: Please reinstall readline – I cannot find readline.h

代码如下:

yum -y install readline-devel

configure: error: Cannot find pspell

代码如下:

yum -y install aspell-devel

checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!

代码如下:

yum -y install unixODBC-devel

configure: error: Unable to detect ICU prefix or /usr/bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works.

代码如下:

yum -y install libicu-devel

configure: error: utf8mime2text() has new signature, but U8TCANONICAL is missing. This should not happen. Check config.log for additional information.

代码如下:

yum -y install libc-client-devel

configure: error: freetype.h not found.

代码如下:

yum -y install freetype-devel

configure: error: xpm.h not found.

代码如下:

yum -y install libXpm-devel

configure: error: png.h not found.

代码如下:

yum -y install libpng-devel

configure: error: vpx_codec.h not found.

代码如下:

yum -y install libvpx-devel

configure: error: Cannot find enchant

代码如下:

yum -y install enchant-devel

configure: error: Please reinstall the libcurl distribution – easy.h should be in /include/curl/

代码如下:

yum -y install libcurl-devel

LAOGAO added 20140907

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

代码如下:

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

tar zxf libmcrypt-2.5.7.tar.gz

cd libmcrypt-2.5.7

./configure

make && make install

added 20141003

Cannot find imap

代码如下:

ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so

configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing.

代码如下:

yum -y install libc-client-devel

Cannot find ldap.h

代码如下:

yum -y install openldap

yum -y install openldap-devel

configure: error: Cannot find ldap libraries in /usr/lib

代码如下:

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

configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

代码如下:

yum -y install postgresql-devel

configure: error: Please reinstall the lib curl distribution

代码如下:

yum -y install curl-devel

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.

代码如下:

yum -y install net-snmp-devel

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

代码如下:

yum -y install libxslt-devel

checking for BZip2 support yes checking for BZip2 in default path not found configure: error: Please reinstall the BZip2 distribution

Fix:

代码如下:

yum -y install bzip2-devel

checking for cURL support yes checking if we should use cURL for url streams no checking for cURL in default path not found configure: error: Please reinstall the libcurl distribution C easy.h should be in/include/curl/

Fix:

代码如下:

yum -y install curl-devel

checking for curl_multi_strerror in -lcurl yes checking for QDBM support no checking for GDBM support no checking for NDBM support no configure: error: DBA: Could not find necessary header file(s).

Fix:

代码如下:

yum -y install db4-devel

checking for fabsf yes checking for floorf yes configure: error: jpeglib.h not found.

Fix:

代码如下:

yum -y install libjpeg-devel

checking for fabsf yes checking for floorf yes checking for jpeg_read_header in -ljpeg yes configure: error: png.h not found.

Fix:

代码如下:

yum -y install libpng-devel

checking for png_write_image in -lpng yes If configure fails try Cwith-xpm-dir=

configure: error: freetype.h not found.

Fix:

代码如下:

Reconfigure your PHP with the following option. –with-xpm-dir=/usr

checking for png_write_image in -lpng yes configure: error: libXpm.(a|so) not found.

Fix:

代码如下:

yum -y install libXpm-devel

checking for bind_textdomain_codeset in -lc yes checking for GNU MP support yes configure: error: Unable to locate gmp.h

Fix:

代码如下:

yum -y install gmp-devel

checking for utf8_mime2text signature new checking for U8T_DECOMPOSE configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.

Fix:

代码如下:

yum -y install libc-client-devel

checking for LDAP support yes, shared checking for LDAP Cyrus SASL support yes configure: error: Cannot find ldap.h

Fix:

代码如下:

yum -y install openldap-devel

checking for mysql_set_character_set in -lmysqlclient yes checking for mysql_stmt_next_result in -lmysqlclient no checking for Oracle Database OCI8 support no checking for unixODBC support configure: error: ODBC header file /usr/include/sqlext.h’ not found!

Fix:

代码如下:

yum -y install unixODBC-devel

checking for PostgreSQL support for PDO yes, shared checking for pg_config not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

Fix:

代码如下:

yum -y install postgresql-devel

checking for sqlite 3 support for PDO yes, shared checking for PDO includes (cached) /usr/local/src/php-5.3.7/ext checking for sqlite3 files in default path not found configure: error: Please reinstall the sqlite3 distribution

Fix:

代码如下:

yum -y install sqlite-devel

checking for utsname.domainname yes checking for PSPELL support yes configure: error: Cannot find pspell

Fix:

代码如下:

yum -y install aspell-devel

checking whether to enable UCD SNMP hack yes checking for default_store.h no

checking for kstat_read in -lkstat no checking for snmp_parse_oid in -lsnmp no checking for init_snmp in -lsnmp no configure: error: SNMP sanity check failed. Please check config.log for more information.

Fix:

代码如下:

yum -y install net-snmp-devel

checking whether to enable XMLWriter support yes, shared checking for xml2-config path (cached) /usr/bin/xml2-config checking whether libxml build works (cached) yes checking for XSL support yes, shared configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

Fix:

代码如下:

yum -y install libxslt-devel

configure: error: xml2-config not found. Please check your libxml2 installation.

Fix:

代码如下:

yum -y install libxml2-devel

checking for PCRE headers location configure: error: Could not find pcre.h in /usrFix:

代码如下:

yum -y install pcre-devel

configure: error: Cannot find MySQL header files under yes. Note that the MySQL client library is not bundled anymore!

Fix:

代码如下:

yum -y install mysql-devel

checking for unixODBC support configure: error: ODBC header file /usr/include/sqlext.h’ not found!

Fix:

代码如下:

yum -y install unixODBC-devel

checking for pg_config not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

Fix:

代码如下:

yum -y install postgresql-devel

configure: error: Cannot find pspell

Fix:

代码如下:

yum -y install pspell-devel

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.

Fix:

代码如下:

yum -y install net-snmp-devel

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

Fix:

代码如下:

yum -y install libxslt-devel

一键安装LAMP和LNMP

2017-06-02 我更新了

重新整理编写的一件安装,通过数字选择进行选项选择安装,一次性安装完成,把环境部署工作更简单的操作,而且是可选项操作。目前是centos6.8,大部分环境测试没有问题,有遇到的问题的可以留言或微信沟通

如此,完整包下载点这里

只需要脚本的点这里

只是要看看看代码的,看下面吧

 

代码实在太长了,去下载吧,自己慢慢看

文末的下载链接任然有效,但是代码有错,不想花时间改了,各位下载最新的吧

 
———-我是美丽的分割线,我代表着有更美的更新————-

可以一键安装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

就是这样

新西兰登山家希拉里,在登上珠穆朗玛峰后,经常被记者问一个问题:你为什么要爬?

他总不回答,于是记者总问,终于有一次,他答出了一个让所有人都无法再问的答案:

因为它(指珠峰),就在那里!

因为它就在那里。

其实这个世上很多事,本不需要理由,之所以需要理由,是因为很多人喜欢找抽,抽久了,就需要理由了。

#反鸡汤#

img_0076

修改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,若能成功显示,则表示安装成功。
至此,安装完毕。