Linux下PHP开发环境搭建-php,mysql,apache
原文url: http://blog.sina.com.cn/s/blog_4b029ef301007xky.html
软件安装列表
zlib.
mysql
php
http
libpng
freetype
jpegsrc
libxml
我都采用源代码安装,因为这样比较灵活,能自己指定安装目录并配置参数,或者进行特性的选取与优化。
说明:所有的包都安装在/data目录下。
(1):
安装zlib
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/data/zlib
make
make install
然后在/etc/ld.so.conf中添加
/data/zlib/lib
保存,执行ldconfig -v
(2)mysql installing.
#groupadd mysql
#useradd -g mysql mysql
# vi /home/mysql/.bash_profile
添加
export PATH=$PATH:/data/mysql/bin
保存后,进入安装包所在目录,先安装Mysql
解压缩:
tar -zxvf mysql-5.0.45.tar.gz
cd mysql-5.0.45
接着要进行configure配置,在以前我只是制定了prefix没有设置字体编码,结果PHP后来不支持汉字编码,只好重新安装
才发现这个问题要注意,而且我们已经安装了zlib,就可以给mysql来指明zlib的位置
[root@cme_box mysql-5.0.45]# ./configure --prefix=/data/mysql --with-zlib-dir=/data/zlib/ --with-charset=utf8 --with-extra-charsets=gbk,gb2312,utf8
make
make install
同样,在/etc/ld.so.conf中添加一行
/data/mysql/lib/mysql
保存,执行ldconfig -v
#./scripts/mysql_install_db
#chown -R root /data/mysql
#chown -R mysql /data/mysql/var
#chgrp -R mysql /data/mysql
# cp support-files/my-medium.cnf /etc/my.cnf
#/data/mysql/bin/mysqld_safe &
下来再init.d中设置mysql的自启动。
# cp support-files/mysql.server /etc/init.d/mysql
cd /etc/rc3.d
ln -s ../init.d/mysql S85mysql
ln -s ../init.d/mysql K85mysql
cd ../rc5.d/
ln -s ../init.d/mysql S85mysql
ln -s ../init.d/mysql K85mysql
cd ../init.d
chmod 755 mysql
然后reboot查看mysql是否启动。
(3)安装apache
tar -zxvf httpd-2.2.6.tar.gz
cd httpd-2.2.6
./configure --prefix=/data/httpd/ --enable-so --enable-cgi --with-z=/data/zlib
make
make install
cp /data/httpd/bin/apachectl /etc/init.d/httpd
cp: overwrite `/etc/init.d/httpd'? y
cd /etc/rc3.d
rm -fr K15httpd
cd /etc/rc5.d
rm -fr K15httpd
cd /etc/rc3.d
ln -s ../init.d/httpd K85httpd
ln -s ../init.d/httpd S85httpd
cd /etc/rc5.d
ln -s ../init.d/httpd K85httpd
ln -s ../init.d/httpd S85httpd
chmod 755 /etc/init.d/httpd
(4)安装GD库
首先,我们要安装各个图形库的支持,包括libpng, libjpeg,ttf等。
1)libpng
tar -zxvf libpng-1.2.23.tar.gz
./configure --prefix=/data/libpng
make
make install
然后将libpng的路径(/data/libpng/lib)加到/etc/ld.so.conf下,执行ldconfig -v
能看到
/data/libpng/lib:
libpng.so.3 -> libpng.so.3.23.0
libpng12.so.0 -> libpng12.so.0.23.0
这一项。说明安装成功。
2)freetype
tar -zxvf freetype-2.1.10.tar.gz
cd freetype-2.1.10
./configure --prefix=/data/freetype
make
make install
then add the path of freetype(/data/freetype/lib) to /etc/ld.so.conf and run command "ldconfig -v",we can get
the output
/data/freetype/lib:
libfreetype.so.6 -> libfreetype.so.6.3.8
3)jpeg
tar -zxvf jpegsrc.v6b.tar.gz
./configure --prefix=/data/jpeg --enable-shared
make
make install
提示:/usr/bin/install: cannot create regular file `/data/jpeg/include/jconfig.h': No such file or directory
nnd,在CU上查到了,原来是安装程序没有权限在/data下自己创建目录,需要手动创建
当我创建include目录后,提示lib目录不存在,创建lib目录后,又提示man/man1目录不存在,那就挨个创建吧。
cd /data/jpeg
mkdir include lib man bin
mkdir man/man1
然后make install就OK了。
然后在/etc/ld.so.conf中添加一行 /data/jpeg/lib,执行命令 ldconfig -v,可以看到
/data/jpeg/lib:
libjpeg.so.62 -> libjpeg.so.62.0.0
4)安装fontconfig
tar -zxvf fontconfig-2.5.0.tar.gz
cd fontconfig-2.5.0
./configure --prefix=/data/fontconfig --with-freetype-config=/data/freetype/bin/freetype-config
make
make install
cd /data/fontconfig/lib
pwd >> /etc/ld.so.conf
ldconfig -v | grep fontconfig
安装GD
tar -zxvf gd-2.0.33.tar.gz
./configure --prefix=/data/gd --with-png=/data/libpng --with-freetype=/data/freetype --with-jpeg=/data/jpeg --with-fontconfig=/data/fontconfig
(在以前没有加fontconfig的时候,会报这个错,但是2008-12-15日加了fontconfig后,却没有报错,一路make,make install很顺利,不过还是要写上,以防再遇到:make时系统提示找不到png.h,手动修改makefile
在CPPFLAGS = 行末加上 -I/data/libpng/include
在CFLAGS = -g -O2 行末加上
-DHAVE_JPEG -DHAVE_LIBTTF -DHAVE_PNG
修改为
CFLAGS = -g -O2 -DHAVE_JPEG -DHAVE_LIBTTF -DHAVE_PNG
)
然后
make
make install
(4)安装libxml
tar -zxvf libxml2-2.6.11.tar.gz
./configure --prefix=/data/xml --with-zlib=/data/zlib
make
make install
然后把xml的库路径【 /data/xml/lib/】添加到/etc/ld.so.conf文件中保存后执行ldconfig -v
看到
/data/xml/lib:
libxml2.so.2 -> libxml2.so.2.6.11
添加gd的库路径[/data/gd/lib]到etc/ld.so.conf文件,执行ldconfig -v
(5)安装php
tar -zxvf php-5.2.4.tar.gz
./configure --prefix=/data/php --with-zlib-dir=/data/zlib --with-mysql=/data/mysql --with-apxs2=/data/httpd/bin/apxs --with-config-file-path=/data/php --with-gd --enable-sysvmsg --enable-sockets --enable-sysvshm --enable-sysvsem --enable-gd-native-ttf --with-ttf=/usr/lib --with-jpeg-dir=/data/jpeg --with-png-dir=/data/libpng --with-iconv --with-libxml-dir=/data/xml
make
make install
cp php.ini-dist /data/php/php.ini
(6)在http.conf中设置php支持。
vi /data/httpd/conf/http.conf
在
# Example:
# LoadModule foo_module modules/mod_foo.so
LoadModule php5_module modules/libphp5.so
下添加一行
AddType application/x-httpd-php .php
并将
DirectoryIndex index.html
修改为
DirectoryIndex index.php index.html
设置默认主页为index.php
然后在/data/php/php.ini中添加一行
default_charset = "gb2312"
保存
service httpd restart
进行测试
在 /data/httpd/htdocs/下建立index.php
写入内容为 保存
打开页面输入url地址
http://192.168.x.x/
就能看到phpinfo的输出了。
如果想修改http的默认根目录,或者说你不想把自己的文件放在/data/httpd/htdoc目录下
可以修改httpd.conf中的
DocumentRoot "/data/httpd/htdoc"为
DocumentRoot "/cme/web"
和
然后还要给新的目录加上能执行的权限
chmod +x /cme
chmod +x /cme/web
重启服务 service httpd restart
就OK了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To set up a CGI directory in Apache, you need to perform the following steps: Create a CGI directory such as "cgi-bin", and grant Apache write permissions. Add the "ScriptAlias" directive block in the Apache configuration file to map the CGI directory to the "/cgi-bin" URL. Restart Apache.

There are 3 ways to view the version on the Apache server: via the command line (apachectl -v or apache2ctl -v), check the server status page (http://<server IP or domain name>/server-status), or view the Apache configuration file (ServerVersion: Apache/<version number>).

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

To get Nginx to run Apache, you need to: 1. Install Nginx and Apache; 2. Configure the Nginx agent; 3. Start Nginx and Apache; 4. Test the configuration to ensure that you can see Apache content after accessing the domain name. In addition, you need to pay attention to other matters such as port number matching, virtual host configuration, and SSL/TLS settings.

There are many ways to solve CentOS system failures. Here are some common steps and techniques: 1. Check the log file /var/log/messages: system log, which contains various system events. /var/log/secure: Security-related logs, such as SSH login attempts. /var/log/httpd/error_log: If you use the Apache server, there will be an error message here. 2. Use the diagnostic tool dmesg: display the contents of the kernel ring buffer, which helps understand hardware and driver questions

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Apache cannot start because the following reasons may be: Configuration file syntax error. Conflict with other application ports. Permissions issue. Out of memory. Process deadlock. Daemon failure. SELinux permissions issues. Firewall problem. Software conflict.
