安装Apache
解压apache安装包(httpd-2.4.17.tar.gz)到 /usr/src/目录下面
tar -zxvf /root/httpd-2.4.17.tar.gz -C /usr/src/
安装httpd所需要的依赖包
yum -y install zlib* openssl* apr* pcre-devel openssl*
进入httpd目录,安装httpd所需要的模块
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi --enable-mpms-shared=all --with-mpm=worker --enable-cgid --enable-deflate --enable-ssl --enable-modules=most --enable-modes-shared=most
编译安装,并嵌入系统内核
make && make install
制作路径优化(注意:*号前面没有空格)
ln -s /usr/local/httpd/bin/* /usr/local/bin/
将文本复制到/etc/init.d目录下起名为httpd
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
在httpd添加配置服务识别参数
vim /etc/init.d/httpd
在第二行#号后面添加:chkconfig:35 33 33
将httpd添加为系统服务
chkconfig --add httpd
chkconfig httpd on
重启httpd
systemctl restart httpd
安装PHP
安装lib开发库
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp gmp-devel expat-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libcurl libcurl-devel curl curl-devel libmcrypt libmcrypt-devel libxslt libxslt-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmemcached-devel libzip readline readline-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
上传并解压php安装包(php-5.5.9.tar.bz2)
cd /root
tar -xjf php-5.5.9.tar.bz2
生成configure文件
#分别进入以下文件夹
cd /root/php-5.5.9/ext/curl
cd /root/php-5.5.9/ext/fileinfo
cd /root/php-5.5.9/ext/gd
cd /root/php-5.5.9/ext/ldap
cd /root/php-5.5.9/ext/mbstring
cd /root/php-5.5.9/ext/mysql
cd /root/php-5.5.9/ext/mysqli
cd /root/php-5.5.9/ext/openssl(额外执行mv config0.m4 config.m4)
cd /root/php-5.5.9/ext/pdo_mysql
cd /root/php-5.5.9/ext/pdo_sqlite
cd /root/php-5.5.9/ext/soap
cd /root/php-5.5.9/ext/sockets
#执行
/root/php-5.5.9/bin/phpize
编译
cd /root/php-5.5.9
./configure --prefix=/root/php-5.5.9 --with-config-file-path=/root/php-5.5.9/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/root --with-png-dir=/root --with-freetype-dir=/root --enable-gd-native-ttf --with-iconv-dir=/root --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/root --with-zlib --with-pdo-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --with-mysql=mysqlnd --with-apxs2=/usr/local/httpd/bin/apxs --enable-dom --enable-xml --enable-fpm --with-php-config=/root/php-5.5.9/bin/php-config
安装
make && make install
报错就用make clean清除
初始化配置文件php.ini
cp /root/php-5.5.9/php.ini-production /root/php-5.5.9/etc/php.ini
初始化配置文件php-fpm.conf
cp /root/php-5.5.9/etc/php-fpm.conf.default /root/php-5.5.9/etc/php-fpm.conf
启动php
/root/php-5.5.9/sbin/php-fpm
Apache配置
配置httpd.conf,使其能解析php文件
找到AddType application/x-gzip .gz .tgz,在后面添加AddType application/x-httpd-php .php
修改DirectoryIndex index.html为DirectoryIndex index.html index.htm index.php
修改ServerName www.example.com:80为ServerName localhost:80
PHP配置
配置php.ini
开启扩展包,去掉以下语句前面的【;】
extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_soap.dll
extension=php_sockets.dll
附录
将php添加到系统服务
cp /root/php-5.5.9/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
php命令
service php-fpm start #开启
service php-fpm stop #停止
service php-fpm restart #重启
service php-fpm status #状态
查看apache根目录
在httpd.conf中搜索DocumentRoot