Apache + MySQL + PHP + FastCGI 配置(上)

时间:2022-10-29 12:59:54

安装 MySQL

/usr/sbin/groupadd -g 27 mysql
/usr/sbin/useradd -c "MySQL Server" -u 27 -d /usr/local/mysql -g mysql -s /bin/bash -M mysql

tar zxvf mysql-5.1.25-rc.tar.gz
cd mysql-5.1.25-rc

CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --prefix=/usr/local/mysql --sysconfdir=/etc --localstatedir=/var/lib/mysql --without-debug --with-unix-socket-path=/var/lib/mysql/mysql.sock --with-extra-charset=all --with-pthread --enable-thread-safe-client

make
make install

cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 700 /etc/rc.d/init.d/mysqld

cd ..
rm -rf mysql-5.1.25-rc

/usr/local/mysql/bin/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysql.pid --skip-locking --port=3306 --socket=/var/lib/mysql/mysql.sock

cd /usr/local/mysql

chown -R root .
chown -R mysql.mysql /var/lib/mysql
chmod 755 /var/lib/mysql

mkdir /var/run/mysqld
chown mysql.mysql /var/run/mysqld

/etc/rc.d/init.d/mysqld start

检查 mysqld 进程是否启动:

ps aux|grep mysqld       (若看到如下几个进程,就已经启动OK,若无则要检查配置)
      
root      3749  0.0  0.0   4112   612 pts/0    S+   11:32   0:00 grep mysqld
root      8568  0.0  0.1   4720  1204 ?        S    10:58   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/run/mysqld/mysqld.pid
mysql     8743  0.0  0.5  35412  4272 ?        Sl   10:58   0:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock --port=3306

安装 pcre 7.7

      
其实之前我们已经安装好了 pcre-6.6-2 版本,但其官方网站已经升级到 7.7 版本了,再者这次安装所涉及的软件都是使用目前最新的稳定版本,因此 pcre 我们也安装最新版本。

tar zxvf pcre-7.7.tar.gz
cd pcre-7.7

./configure
make
make install

cd ..
rm -rf pcre-7.7

rm -rf /usr/bin/pcre-config
cp -a /usr/local/bin/pcre-config /usr/bin/

rm -rf /usr/lib/libpcre.a
cp -a /usr/local/lib/libpcre.a /usr/lib/

安装 apache

cd tar.gz

/usr/sbin/groupadd -g 48 apache
/usr/sbin/useradd -g 48 -u 48 -M -d /usr/local/httpd/htdocs -s /sbin/nologin apache

tar zxvf httpd-2.2.9.tar.gz
cd httpd-2.2.9

CHOST="i686-pc-linux-gnu" CXX=gcc CXXFLAGS="-o3 -msse2 -mmmx -mfpmath=sse -funroll-loops -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/httpd --enable-modules=all --enable-mods-shared=all --enable-so --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-support --enable-static-htpasswd --enable-static-htdigest --enable-static-rotatelogs --enable-static-logresolve --enable-static-htdbm --enable-static-ab --enable-static-checkgid --disable-cgid --disable-cgi --disable-userdir --with-mpm=worker --enable-ssl --enable-suexec --with-suexec-uidmin=500 --with-suexec-gidmin=100 --with-pcre=/usr/local/bin/pcre-config

make
make install

cd ..
rm -rf httpd-2.2.9

cp /usr/local/httpd/bin/apachectl /etc/rc.d/init.d/httpd
chmod 700 /etc/rc.d/init.d/httpd

/etc/rc.d/init.d/httpd start

检查 httpd 进程是否启动:

ps aux|grep httpd       (若看到如下几个进程,就已经启动OK,若无则要检查配置)

root      3373  0.0  0.4  10648  3540 ?        Ss   11:25   0:00 /usr/local/httpd/bin/httpd
apache    3375  0.0  0.2  10420  1904 ?        S    11:25   0:00 /usr/local/httpd/bin/httpd
apache    3376  0.0  0.4 287416  3240 ?        Sl   11:25   0:00 /usr/local/httpd/bin/httpd
apache    3378  0.0  0.4 287416  3176 ?        Sl   11:25   0:00 /usr/local/httpd/bin/httpd
apache    3380  0.0  0.3 287284  2568 ?        Sl   11:25   0:00 /usr/local/httpd/bin/httpd
apache    3461  0.0  0.3 287284  2568 ?        Sl   11:25   0:00 /usr/local/httpd/bin/httpd
root      4119  0.0  0.0   4116   596 pts/0    R+   11:49   0:00 grep httpd

安装 PHP5

cd tar.gz

tar zxvf php-5.2.6.tar.gz
gzip -cd php-5.2.6-fpm-0.5.8.diff.gz | patch -d php-5.2.6 -p1

       php-fpm
是为 PHP 打的一个 FastCGI 管理补丁,可以平滑变更 php.ini 配置而无需重启 php-cgi
这一部分留到后续再讲了。。。

cd php-5.2.6

./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --with-config-file-path=/etc --enable-inline-optimization --with-zlib --with-gd --with-ttf --with-gmp --with-pcre-dir=/usr/local/bin/pcre-config --with-mysql=/usr/local/mysql --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mysqli=/usr/local/mysql/bin/mysql_config --disable-debug --enable-posix --disable-rpath --enable-safe-mode --enable-magic-quotes --disable-dmalloc --enable-bcmath --enable-gd-native-ttf --enable-sysvsem --enable-sysvshm --enable-exif --enable-ftp --enable-sockets --enable-wddx --with-jpeg-dir --with-freetype-dir --enable-gd-native-ttf --with-mime-magic=/usr/share/file/magic.mime

make
make install

cp php.ini-dist /etc/php.ini

cd ..
rm -rf php-5.2.6

安装 PHP5 扩展模块

tar zxvf memcache-2.2.3.tgz
cd memcache-2.2.3

/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

cd ..
rm -rf memcache-2.2.3

tar zxvf xcache-1.2.2.tar.gz
cd xcache-1.2.2

/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-xcache
make
make install

cd ..
rm -rf xcache-1.2.2