1. httpd 安装 rpm包
yum install httpd
systemctl start httpd
httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Apr 2 2020 13:13:23
2. mysql 安装rpm包
yum -y install mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
此中含有依赖( mysql-community-libsmysql-community-devel),有此两个libs和devel,php configure时mysql目录编译可不指定
mysql --version
mysql Ver 14.14 Distrib 5.6.48, for Linux (x86_64) using EditLine wrapper
此中,/usr/bin/apxs安装包
yum install -y httpd-devel
3. PHP安装
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz ( 下载速度过慢,建议本地浏览器下载上传 )
php依赖
yum -y install libxml2 libxml2-devel curl curl-devel openssl openssl-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel gmp-devel mysql-devel ncurses ncurses-devel unixODBC-devel net-snmp-devel libmcrypt libmcrypt-devel net-snmp mhash-devel
yum -y install openldap openldap-devel
yum -y install libxslt-devel # libxslt相关组件
yum install -y perl*(以上仍报错,用这个,此命令包1600左右)
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
make && make install
配置相关php.ini配置
首先我们需要配置的是php.ini这个文件
安装目录有2个文件:php.ini-development和php.ini-production
php.ini-production 线上版本使用
php.ini-development 开发版本使用
我们选择development进行配置
cp php.ini-development /usr/local/php/lib/php.ini
php-fpm配置
拷贝php-fpm配置文件
cp -R ./sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
4. 设置php-fpm脚本启动并且开机自启动
将php给我们准备好的init.d.php-fpm。
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
将php-fpm服务添加到chkconfig列表
chkconfig --add php-fpm
设置开机自启动
chkconfig php-fpm on
以后重启和停止php的方式为
service php-fpm start
service php-fpm stop
service php-fpm restart
service php-fpm reload
5. 配置httpd添加php模块
cat /etc/httpd/conf/httpd.conf
1> ServerName开启
ServerName www.example.com:80 #根据需求开启
2> 将Require all denied 改为Require all granted
AllowOverride none
Require all granted
3> 增加一行AddType application/x-httpd-php .php
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
4> 增加索引页index.php
在DirectoryIndex index.html后面 增加索引页index.php
DirectoryIndex index.html index.php
重启httpd
6. 测试php安装效果
cat > /var/www/html/phpinfo.php <
EOF
curl http://localhost/phpinfo.php
或者浏览器访问公网ip
#############################################################################################
附加 nginx-php 配置
nginx主配置文件
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
nginx主目录
server {
listen 80;
server_name localhost;
location / {
#root html;
root /var/www/html;
index index.html index.htm
}
}
然后重启nginx,并测试