使用fastestmirror插件给yum加速
安装一些必要的软件:
yum -y install gcc gcc-c++ screen autoconf automake libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel pcre pcre-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libtiff libtiff-devel gettext gettext-devel pam pam-devel fontconfig-devel libXpm-devel libtool
关闭SELINUX
./configure \
--with-ssl \
建立配置文件
初始化数据库,并修改相关目录所有权
/usr/local/mysql/bin/mysql_install_db --user=mysql
调整lib库路径
echo "/usr/local/mysql/lib/mysql/" >>/etc/ld.so.conf
使用mysqld_safe脚本安全启动服务(后台)
/usr/local/mysql/bin/mysqld_safe --user=mysql &
查看一下mysqld是否启动
将mysql添加为系统服务
cp support-files/mysql.server /etc/init.d/mysqld
把MySQL加入环境变量(设置mysql的执行路径)
echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
设置"root"用户密码,登陆且验证数据库正确安装
mysql>use mysql;
mysql>select Host,User,Password,Select_priv,Grant_priv from user;
mysql>delete from user where user=''; (删除user为空的用户)
mysql>delete from user where password=''; (删除密码为空的用户)
mysql>delete from user where host=''; (删除主机名为空的用户)
mysql>drop database test; (删除默认的test数据库)
mysql>flush privileges; (刷新mysql的缓存,让以上设置立即生效)
mysql>quit;
为了使以上优化和安全设置生效,请重启Mysql服务或Linux。
find / -name libpcre.so.0
安装Nginx
--group=www \
注意:--with-pcre=/usr/local/src/pcre-8.10指向的是源码包解压的路径,而不是安装的路径,否则会报错
echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local
编辑 /etc/rc.d/init.d/nginx 文件,覆盖为以下代码:(脚本里也有apache的启动,若没有安装apache会报错,可以先注释掉)
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
kill -QUIT `cat $PIDFILE` || echo -n "nginx not running"
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
echo -n "Reloading $DESC configuration..."
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
添加到开机自启动
Nginx启动后有两个进程,master为主进程,worker为工作进程,如下图
//编译安装zlib
>tar zxvf zlib-1.2.5.tar.gz
>cd zlib-1.2.5
>./configure --prefix=/usr/local/zlib
>make
>make install
//编译安装libpng
>tar zxvf libpng-1.5.1.tar.gz
>cd libpng-1.5.1
./configure –prefix=/usr/local/png
>make
>make install
ln -s /usr/local/png/lib/* /usr/lib/
//编译安装freetype
>tar zxvf freetype-2.4.4.tar.gz
>cd freetype-2.4.4
>./configure --prefix=/usr/local/freetype
>make
>make install
//编译安装jpeg
>tar zxvf jpegsrc.v8c.tar.gz
>cd jpeg-8c/
>./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
>make
>make install
ln -s /usr/local/jpeg/lib/* /usr/lib/
//编译安装fontconfig
>tar zxvf fontconfig-2.8.0.tar.gz
>cd fontconfig-2.8.0
#./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config
>make
>make install
//编译安装libxml
>tar zxvf libxml2-2.7.4.tar.gz
>cd libxml2-2.7.4
>./configure
>make
>make install
编译安装GD
>tar zxvf gd-2.0.35.tar.gz
>cd gd-2.0.35
> ./configure --prefix=/usr/local/gd
>make && make install
** Configuration summary for gd 2.0.34:
Support for PNG library: yes
Support for JPEG library: yes
Support for Freetype 2.x library: yes
Support for Fontconfig library: yes
Support for Xpm library: no
Support for pthreads: yes
tar xf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/
make && make install
tar xf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
make && make install
cd libltdl/
./configure --enable-ltdl-install
make && make install
tar xf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make && make install
ehco "/usr/local/lib" >>/etc/ld.so.conf
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
ldconfig
tar xf mcrypt-2.6.8.tar.gz
make && make install
默认情况下Nginx和PHP他俩之间是一点感觉没有的。在之前,很多朋友都搭建过Apache+PHP,Apache+PHP编译后生成的是模块文件,而Nginx+PHP需要PHP生成可执行文件才可以,所以要利用fastcgi技术来实现N ginx与PHP的整合,这个只要我们安装是启用FastCGI即可。此次我们安装PHP不仅使用了FastCGI,而且还使用了PHP-FPM这么一个东东,PHP-FPM说白了是一个管理FastCGI的一个管理器,它作为PHP的插件纯在,在安装PHP要想使用PHP-FPM时就需要把PHP-FPM以补丁的形式安装到PHP中,而且PHP要与PHP-FPM版本一致,这是必须的,切记!
tar xf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17
--with-mysqli=/usr/local/mysql/bin/mysql_config \
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /usr/local/php/etc/php.ini
ln -s /usr/local/php/bin/php /usr/bin/php
ln -s /usr/local/php/bin/phpize /usr/bin/phpize
ln -s /usr/local/php/sbin/php-fpm /usr/bin/php-fpm
/usr/local/php/sbin/php-fpm start
vi /usr/local/php/etc/php-fpm.conf
/usr/local/php/sbin/php-fpm start
cp sapi/cgi/fpm/php-fpm /etc/init.d/php-fpm
chmod a+x /etc/init.d/php-fpm
echo "/usr/local/php/sbin/php-fpm start" >>/etc/rc.local
vi /usr/local/nginx/conf/nginx.conf //标的部分是我们后面要修改的
注:上面的/usr/local/nginx/html 是我们PHP网站放置的路径
vi /usr/local/php/etc/php-fpm.conf
echo phpinfo();
重启PHP与nginx后(可以用杀死进程的方式关闭,然后在启动)我们在浏览器中输入http://localhost/test.php,出现如下界面算成功
5.安装Apache2:
tar zxvf httpd-2.4.2.tar.gz
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
make && make install
vi /usr/local/apache2/conf/httpd.conf
将端口改为8080
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
chmod a+x /etc/init.d/httpd
echo "/usr/local/apache2/bin/apachectl start" >>/etc/rc.local
/etc/init.d/httpd start
tar zxvf php-5.2.17.tar.gz
cd php-5.2.17/
./configure \
--prefix=/usr/local/php2 \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php2/etc \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-curl \
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-mhash \
--with-libxml-dir \
--with-gd \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-shared
如果编译的时候忘记编译一些参数,可以追加编译,如追加编译mysqli curl
追加编译安装mysqli
cd ext/mysqli/ # php5.2.17版本 安装目录下
/usr/local/php/bin/phpize #生成configure
./configure --prefix=/usr/local/php2 \
--with-php-config=/usr/local/php2/bin/php-config \
--enable-embedded-mysqli=shared \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-shared
make
make install
成功后会提示安装到哪个目录(如: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/)
cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/mysqli.so /usr/local/php/lib/
vim /usr/local/php/lib/php.ini
指定目录用绝对路径
extension_dir = "/usr/local/php2/lib"
extension=mysqli.so
OK 重启相应服务就可以了
追加编译安装curl
cd ext/curl
/usr/local/php/bin/phpize
./configure ==prefix=/usr/local/curl
./configure --with-php-config=/usrl/local/php/bin/php-config
make
make install
编译php
make ZEND_EXTRA_LIBS='-liconv'
make install
copy生成PHP配置文件
cp php.ini-dist /usr/local/php2/etc/php.ini
vi /usr/local/php2/etc/php.ini
register_globals=On //修改处
vi /usr/local/apache2/conf/httpd.conf
查找:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在其下添加:
AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddType p_w_picpath/x-icon .ico
AddType application/x-httpd-php-source .phps
修改DirectoryIndex 行,添加index.php
DirectoryIndex index.php index.html index.html.var
查找是否有这行,没有的话要添加。
LoadModule php5_module modules/libphp5.so
测试php脚本,写入如下代码
vi /usr/local/apache/htdocs/test.php
添加以下行:
<?php
phpinfo();
?>
wq保存退出。
/usr/local/apache2/bin/apachectl restart
在浏览器中输入:http://IP:8080/test.php进行测试。
测试PHP与数据库的连接
vi /usr/local/apache/htdocs/sql.php
<?php
$LINK=mysql_connect('127.0.0.1','root','1234');
if ($LINK)
echo "success...";
else
echo "Failure...";
mysql_close();
?>
/usr/local/apache2/bin/apachectl restart
在浏览器中输入:http://IP:8080/sql.php进行测试。
干嘛儿网-电影频道、最新电影、高清影视:http://v.ganmaer.com/
转载于:https://blog.51cto.com/wushuaishuai/963390