文章目录
1, cent6: lamp (yum安装)
a, 软件包安装: httpd2.2, mysql5.1, php5.3
##### 使用更高版本的php( 比如zabbix要求最低php5.4) :
##### rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
##### yum -y install $(yum list |grep php55w |awk '{print $1}') --skip-broken #56w,70w,71w
### 1, 准备环境
yum -y install httpd mysql-server mysql php php-mysql
yum -y install mod_ssl mod_auth_mysql php-ldap php-mbstring
# [vagrant@c6 ~]$ mysql_secure_installation
# ....
# Reload privilege tables now? [Y/n] y
# ... Success!
# Cleaning up...
# All done! If you've completed all of the above steps, your MySQL
# installation should now be secure.
# Thanks for using MySQL!
service mysqld start
service httpd start
### 2, 测试使用
[vagrant@c6 html]$ pwd
/var/www/html
[vagrant@c6 html]$ ls
index.html index.php mysql.php
[vagrant@c6 html]$ cat index.html
123
[vagrant@c6 html]$ curl localhost/index.html
123
[vagrant@c6 html]$ cat index.php
<?php phpinfo(); ?>
[vagrant@c6 html]$ curl localhost/index.php |head -5
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 52083 0 52083 0 0 5015k 0 --:--:-- --:--:-- --:--:-- 5651k
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html><head>
<style type="text/css">
body {background-color: #ffffff; color: #000000;}
body, td, th, h1, h2 {font-family: sans-serif;}
[vagrant@c6 html]$ cat mysql.php
<?php
$res=mysql_connect("localhost","root","123");
if (!$res) echo "faild,mysql";
else echo "ok,mysql";
?>
[vagrant@c6 html]$ curl localhost/mysql.php
ok,mysql
b, 查看php编译参数
[vagrant@c6 ~]$ php -i |grep -i configure
Configure Command => ./configure --build=x86_64-redhat-linux-gnu \
--host=x86_64-redhat-linux-gnu --target=x86_64-redhat-linux-gnu \
--program-prefix= --prefix=/usr --exec-prefix=/usr \
--bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc \
--datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 \
--libexecdir=/usr/libexec --localstatedir=/var \
--sharedstatedir=/var/lib --mandir=/usr/share/man \
--infodir=/usr/share/info --cache-file=../config.cache \
--with-libdir=lib64 --with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d --disable-debug \
--with-pic --disable-rpath --without-pear --with-bz2 \
--with-exec-dir=/usr/bin --with-freetype-dir=/usr \
--with-png-dir=/usr --with-xpm-dir=/usr --enable-gd-native-ttf \
--with-zlib --with-layout=GNU --without-gdbm --with-gettext --with-gmp \
--with-iconv --with-jpeg-dir=/usr --with-openssl --with-pcre-regex=/usr \
--enable-exif --enable-ftp --enable-magic-quotes --enable-sockets \
--enable-sysvmsg --with-kerberos --enable-ucd-snmp-hack --enable-shmop \
---enable-sysvsem --enable-sysvshm -enable-calendar --without-sqlite \
--with-libxml-dir=/usr --enable-xml --with-system-tzdata \
--enable-force-cgi-redirect --enable-pcntl \
--with-imap=shared --with-imap-ssl --enable-mbstring=shared --enable-mbregex \
--with-gd=shared --enable-bcmath=shared \
--enable-dba=shared --with-db4=/usr --with-xmlrpc=shared --with-ldap=shared \
--with-ldap-sasl --with-mysql=shared,/usr \
--with-mysqli=shared,/usr/lib64/mysql/mysql_config --enable-dom=shared \
--with-pgsql=shared --enable-wddx=shared \
--with-snmp=shared,/usr --enable-soap=shared --with-xsl=shared,/usr \
--enable-xmlreader=shared --enable-xmlwriter=shared \
--with-curl=shared,/usr --enable-fastcgi --enable-pdo=shared \
--with-pdo-odbc=shared,unixODBC,/usr \
--with-pdo-mysql=shared,/usr/lib64/mysql/mysql_config \
--with-pdo-pgsql=shared,/usr --with-pdo-sqlite=shared,/usr \
--with-sqlite3=shared,/usr --enable-json=shared --enable-zip=shared \
--without-readline --with-libedit --with-pspell=shared \
--enable-phar=shared --with-tidy=shared,/usr --enable-sysvmsg=shared \
--enable-sysvshm=shared --enable-sysvsem=shared \
--enable-posix=shared --with-unixODBC=shared,/usr --enable-fileinfo=shared \
--enable-intl=shared --with-icu-dir=/usr \
--with-enchant=shared,/usr --with-recode=shared,/usr
c, 查看php模块化配置文件
[vagrant@c6 ~]$ cat /etc/httpd/conf.d/php.conf |grep -Ev "^#|^$"
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
AddHandler php5-script .php
AddType text/html .php
DirectoryIndex index.php
1, cent6: lamp (src编译安装)
参考博文:https://www.linuxidc.com/Linux/2015-08/121078.htm
a, httpd2.4
httpd2.4源码编译: https://blog.csdn.net/eyeofeagle/article/details/103754637
b, mysql5.7
mysql5.7二进制安装: https://blog.csdn.net/eyeofeagle/article/details/103363966
c, php5.5
##1, 编译安装php5.5
yum install libxml2-devel
yum -y install bzip2-devel
yum -y install libcurl-devel
yum -y install libpng-devel
yum install -y libmcrypt-devel
ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/local/mysql/lib/libmysqlclient_r.so
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd2.4/bin/apxs \
--with-config-file-path=/usr/local/httpd2.4/conf --with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd \
--enable-gd-native-ttf --with-zlib --with-mcrypt \
--with-pdo-mysql=/usr/local/mysql --enable-shmop --enable-soap \
--enable-sockets --enable-zip --enable-fpm --enable-mbstring \
--with-zlib-dir --with-bz2 --with-curl
##2, 配置httpd支持php5.5
[root@c6 httpd2.4]# ls modules/ |grep php
libphp5.so
[root@c6 httpd2.4]# cat >> /usr/local/httpd2.4/conf/httpd.conf <<EOF
LoadModule php5_module modules/libphp5.so
<Directory "/usr/local/httpd2.4/htdocs">
Options Indexes FollowSymLinks
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
<IfModule mime_module>
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
</IfModule>
EOF
##3, 测试apache-php使用
[root@c6 httpd2.4]# ls htdocs/
index.html index.php mysql.php
[root@c6 httpd2.4]# cat htdocs/index.php
<?php phpinfo(); ?>
[root@c6 httpd2.4]# cat htdocs/mysql.php
<?php
$link = mysqli_connect('localhost', 'root', '123');
if (!$link) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>
[root@c6 conf]# ps -ef |grep httpd
root 1026 1 0 Feb26 ? 00:00:05 /usr/local/httpd2.4/bin/httpd -k start
daemon 22326 1026 0 03:12 ? 00:00:00 /usr/local/httpd2.4/bin/httpd -k start
daemon 22327 1026 0 03:12 ? 00:00:00 /usr/local/httpd2.4/bin/httpd -k start
daemon 22328 1026 0 03:12 ? 00:00:00 /usr/local/httpd2.4/bin/httpd -k start
root 22415 21590 0 03:14 pts/3 00:00:00 grep httpd
service httpd restart
chown -R daemon. /usr/local/httpd2.4/htdocs/
chmod -R 770 /usr/local/httpd2.4/htdocs/
[root@c6 httpd2.4]# curl localhost/mysql.php
Connected successfully