Linux下搭建php运行环境【转】

Linux下搭建php运行环境【转】

需要安装的软件:
1.	安装mysql
1.1安装编译器gcc
最小化安装,没有安装编译器
yum install gcc
yum install gcc-c++
如果不安装,在编译mysql的时候会出现【exec: g++: not found】错误

1.2安装ncurses-5.6.tar.gz,
tar zxvf ncurses-5.6.tar.gz
cd ncurses-5.6 
./configure --prefix=/usr --with-shared --without-debug
make
make install 

1.3安装mysql 
tar -zxvf mysql-5.0.51a.tar.gz 
cd mysql-5.0.51a
./configure --with-mysqld-user=mysql --prefix=/usr/local/mysql5 --with-charset=gbk --with-extra-charsets=all --without-isam --exec-prefix=/usr/local/mysql5
echo $?
Make clean
make && make install

1.4 初始化数据库:
groupadd mysql
useradd -g mysql mysql
scripts/mysql_install_db
cp /usr/local/mysql5/share/mysql/my-medium.cnf /usr/local/mysql5/var/my.cnf 
cp /usr/local/mysql5/share/mysql/mysql.server /etc/init.d/mysqld 
编辑my.cnf 把skip -federated注释掉
chkconfig --add mysqld 
chkconfig --level 2345 mysqld on
chown mysql:mysql -R /usr/local/mysql5/
chmod +w /usr/local/mysql5/
service mysqld start
ln -s /usr/local/mysql5/bin/mysql /sbin/mysql 
ln -s /usr/local/mysql5/bin/mysqladmin /sbin/mysqladmin

1.5 设定mysql密码
mysqladmin -uroot password "1111111"

1.6让系统找到mysql(如果必要的话): 
PATH=$PATH:/usr/local/mysql5/bin 
export PATH 
echo "/usr/local/mysql5/lib/mysql" >> /etc/ld.so.conf 
ldconfig

1.7测试 
netstat -nplt | grep mysql
ps aux|grep mysql

1.8 授权用户权限
切记:@%代表在远程的权限,@localhost实际上只有在本机的权限
进入mysql
grant all on *.* to root@”%” identified by “111111” with grant option;
其他用户也可以这样设置权限

2.	安装apache
2.1编译安装
tar zxvf httpd-2.2.8.tar.gz 
cd httpd-2.2.8
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
echo $?
make && make install
/usr/local/apache2/bin/apachectl configtest
/usr/local/apache2/bin/apachectl start
/usr/local/apache/bin/apachectl stop

2.2修改默认启动页
vi /usr/local/apache2/conf/httpd.conf
DirectoryIndex index.html 改为
DirectoryIndex index.html index.htm default.htm default.html index.php index.php3 index.jsp
#ServerName http://www.7966.org/ 改为
ServerName http://www.7966.org/

2.3 apache 开机启动的办法
#echo "/usr/local/apache/bin/apachectl start" >>/etc/rc.local(系统启动时服务自动启动)
测试:
在浏览器上输入127.0.0.1进入Apache test页面

编辑/etc/init.d/httpd
修改:
apachectl=/usr/local/apache2/bin/apachectl
httpd=/usr/local/apache2/bin/httpd
prog=httpd
pidfile=/usr/local/apache2/logs/httpd.pid
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0

5.安装PHP
5.1安装zlib
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
make install

5.2安装png
tar zxvf libpng-1.2.14.tar.gz
cd libpng-1.2.14
cp scripts/makefile.linux ./makefile
./configure –prefix=/usr/local/libpng
make
make install

5.3安装freetype
tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure
make
make install

5.4安装jpeg
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
mkdir -pv /usr/local/jpeg/{,bin,lib,include,man/man1,man1}
./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
make
make install

5.5 安装GD
tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --with-png --with-freetype --with-jpeg=/usr/local/jpeg/
make
make install

5.6安装LIBXML2
tar zxvf libxml2-2.6.31.tar.gz
cd libxml2-2.6.31
./configure --prefix=/usr/local/libxml2
make
make install
cp xml2-config /usr/bin

5.7安装PHP5.2.5
tar zxvf php-5.2.5.tar.gz 
cd php-5.2.5
./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql5 --with-apxs2=/usr/local/apache2/bin/apxs --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/include/freetype2 --with-zlib --with-png-dir=/usr/local/libpng12 --with-libxml-dir=/usr/local/libxml2 --with-gd --enable-ftp --enable-sockets
make
make test
make install

5.8配置
cp php.ini-dict /usr/local/php5/lib/php.ini
编辑/usr/local/apache2/conf/httpd.conf
加载php模块,去掉注释,有的版本是缺省就启用的。
LoadModule php5_module        modules/libphp5.so
加上下面两行
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
编辑/usr/local/php5/lib/php.ini
设置php的session直接读取方式
register_globals=off 改成 on
设置php支持cookie
output_buffering = Off 改成 on

7.3 在apache网站的根目录下(/usr/local/apache2/htdocs/)新建index.php
<? php
  $ip=$HTTP_HOST;
  echo $ip;
?>
测试通过,OK

文章来源于网络或者作者投稿,若有侵权请联系删除,作者:老钟,如若转载,请注明出处:https://www.laoz.net/87.html

(0)
上一篇 2011 年 08 月 16 日
下一篇 2011 年 08 月 17 日

相关推荐

  • CentOS7修改SSH端口

    一、修改ssh配置文件sshd_config [root@bogon ~]# vi /etc/ssh/sshd_config 二、防火墙放行 [root@bogon ~]# firewall-cmd --zone=public --add-port=22345/tcp --permanent [root@bogon ~]# firewall-cmd --relo...

    2020 年 05 月 16 日
  • CentOS7 网站开启ssl证书后,网站无法访问,提示ERR_CONNECTION_REFUSED

    CentOS7服务器,安装lnmp, 原本网站正常运行,添加SSL证书后,发现网站拒绝访问,提示: 无法显示此网页 网站暂时无法连接,错误代码 ERR_CONNECTION_REFUSED 解决方法如下: 1, 检查系统防火墙firewall是否添加...

    vps教程 2021 年 02 月 26 日
  • 解决VMware安装Centos在安装VMware Tools就停止的情况

    在Vmware上面安装Centos 6.5来测试,发现总是在安装VMware Tools停止安装了,当然,也在网上找了很多解决办法,下面可以提供给大家参考 我的解决:在刚开始创建虚拟机的时候,不需要添加iso文件进行安装,这样就...

    2017 年 06 月 20 日
  • 2016-9-22 搬瓦工最新优惠信息,最新优惠码

    Bandwagonhost又称为搬瓦工,现在已经被屏蔽了,尽量翻{哈哈}墙访问 老钟用了一段时间,搬瓦工的主机比较稳定,访问速度还算可以 如果搭配国内的CDN使用,访问速度能减少到300毫秒以下,这个速度算是不错了 现在...

    2016 年 09 月 22 日
  • couldn't flush system prefs

    运行程序时,发现报此错误:警告: Couldn't flush system prefs: java.util.prefs.BackingStoreException: java.io.FileNotFoundException: /etc/.java/.systemPrefs/pre...

    vps教程 2012 年 08 月 13 日
  • VPS安全设置 增强VPS安全性防止被攻破

    安全是一个VPS最基本的必备条件,若您的VPS三天两头被人攻破,那么对于网站来说也没什么意义了,所以,在创建了Web服务器之后,您首先要做的事情就是将您的VPS加固,至少让普通黑客没有办法能够攻破您的网站。 用...

    vps教程 2018 年 01 月 17 日
  • Linux中 常用命令 和 进程管理

    Vim: 文本编辑器 vim   文件名 vim  + n(行号)  如  vim  + 3  /etc/passwd 光标在第三行; + /word       光标在有word的行首; Vim主要有三种模式: 命令,输入,末行这三种模式 命令模式 —>  输入模式 1...

    vps教程 2011 年 08 月 11 日
  • 在Linux中配置网络

    与网络有关的常用命令: --------------------------------------------------------------------------------------------------------- 1、ifconfig # ifconfig [接口名称] 查看某个设备的配置: # ifconfig et...

    vps教程 2011 年 10 月 30 日
  • linux下统计文件夹文件数量

    linux下统计文件夹数量 egrep "7966.org"  file|wc -l 最近bluehost主机上,发现文件限制为50,000个文件。于是想看一下,主机文件夹里的文件数量,由于主机是linux的,所以找了一下。大致有两种: 一种是: ls  ...

    vps教程 2011 年 11 月 23 日
  • Linux初级使用,切换字符界面、配置网络

    在linux中是叫文本界面而不是字符界面。方法如下: vi /etc/inittab id:3:initdefault: (大约在18行左右,其中3代表启动级别) 5代表的是图形界面 以后在你重启系统的时候都会进入字符界面。 --------------------...

    vps教程 2011 年 10 月 16 日