CentOS 7.0 安装Apache + MySQL + PHP + php-mcrypt + ZendOpcache 设置启动菜单等待时间: vi /boot/grub2/grub.cfg set timeout=0 设置自动启动网络服务: vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 ONBOOT=yes service network restart 查看IP地址: ip addr 安装编译工具: yum update yum install gcc gcc-c++ make 安装Apache: yum install httpd httpd-devel systemctl start httpd.service systemctl status httpd.service #设置apache开机启动 systemctl enable httpd.service 添加Firewall规则: vi /etc/firewalld/zones/public.xml <zone> ... <port protocol="tcp" port="80"/> <port protocol="udp" port="80"/> ... </zone> yum 源里的 MySQL 被替换为了 MariaDB: 安装 MariaDB: yum install mariadb mariadb-server #拷贝配置文件 cp /usr/share/mysql/my-huge.cnf /etc/my.cnf systemctl start mariadb.service #设置开机启动 systemctl enable mariadb.service 安装原版 MySQL: rpm -ivh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm #上面的地址来自 http://dev.mysql.com/downloads/repo/yum/ ,可能会有变动,请自行修改 yum install mysql mysql-server systemctl start mysqld.service #设置开机启动 systemctl enable mysqld.service mysql_secure_installation 安装PHP: yum install php php-devel yum install php-bcmath php-gd libjpeg* php-intl php-ldap php-mbstring php-mhash php-mysqlnd php-odbc php-pdo php-pear php-pecl-memcache php-soap php-xml php-xmlrpc 安装ZendOpcache 或 APC(推荐ZendOpcache): ZendOpcache: pecl install channel://pecl.php.net/zendopcache-7.0.3 vi /etc/php.ini 添加: [ZendOpcache] zend_extension=/usr/lib64/php/modules/opcache.so APC: pecl install apc vi /etc/php.ini 添加:extension=apc.so 安装libmcrypt: wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz tar -xvzf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make && make install 安装mhash: wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz tar -xvzf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9 ./configure make && make install 安装mcrypt: wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz tar -xvzf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8 LD_LIBRARY_PATH=/usr/local/lib ./configure make && make install 安装php-mcrypt: wget http://museum.php.net/php5/php-5.4.16.tar.gz tar -xvzf php-5.4.16.tar.gz cd php-5.4.16/ext/mcrypt phpize php-config ./configure make && make install vi /etc/php.ini 添加:extension=mcrypt.so 配置Apache: vi /etc/httpd/conf/httpd.conf 去除 Indexes 修改: AllowOverride All DirectoryIndex index.php index.html #禁止显示版本,修改或添加: ServerTokens Prod 设置gzip压缩传输和客户端缓存时间: vi /etc/httpd/conf.d/xxx.conf 添加: <VirtualHost *:80> ... <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/plain text/css application/xml application/rss+xml application/atom_xml application/javascript application/x-javascript text/x-component application/x-httpd-php text/html AddOutputFilter DEFLATE js css </IfModule> <IfModule mod_expires.c> <FilesMatch "\.(jpg|jpeg|png|gif|js|css)$"> ExpiresActive On ExpiresDefault "accesss plus 60 seconds" FileETag None Header unset ETag </FilesMatch> </IfModule> </VirtualHost> vi /etc/php.ini date.timezone = PRC #禁止显示php版本的信息 expose_php = Off yum install memcached systemctl start memcached.service systemctl enable memcached.service 设置VirtualHost: vi /etc/httpd/conf.d/xxx.conf <VirtualHost *:80> ServerName xxx.com DocumentRoot /var/www/html/xxx.com ErrorLog /var/log/xxx.com-error_log CustomLog /var/log/xxx.com-access_log common </VirtualHost> 禁止IP直接访问,防止恶意解析: vi /etc/httpd/conf.d/default.conf <VirtualHost *:80> <Location /> Order Allow,Deny Deny from all </Location> </VirtualHost> 如果出现访问虚拟目录时报告403错误,可能是SELinux导致,须执行: chcon -R -t httpd_sys_content_t /var/www/html/xxx 执行后可通过 ls -Z 查看目录属性(责任编辑:IT) |