扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
这篇文章主要讲解了“Centos环境怎么安装lamp-php”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Centos环境怎么安装lamp-php”吧!
创新互联是专业的城固网站建设公司,城固接单;提供网站建设、网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行城固网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!一. 环境准备
桥接模式
能访问外网
#ping www.baidu.com
ping得通则能到外网
关闭防火墙
#systemctl disable firewalld //禁用防火墙 #systemctl stop firewalld //关闭防火墙
关闭selinux
#vim /etc/selinux/config
改为:
selinux=disabled
配置yum源
# cd /etc/yum.repos.d/ # mkdir repo_bak //创建备份源文件夹 # mv *.repo repo_bak/ //将源文件都放到备份文件夹 # wget http://mirrors.aliyun.com/repo/centos-7.repo //配置阿里源 # wget http://mirrors.163.com/.help/centos7-base-163.repo //配置网易源 # ls //列出/etc/yum.repos.d/目录下的文件 centos-7.repo centos-base-163.repo repo.bak # yum clean all //清除系统所有yum缓存 # yum makecache //生成yum缓存 # yum list | grep epel-release //查看epel源列表 # yum install -y epel-release //安装epel源 # ls //epel源安装成功,比原来多了一个epel.repo和epel-testing.repo文件 centos-7.repo centos-base-163.repo epel.repo epel-testing.repo repo.bak # wget -o /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo //下载阿里源的epel源 # ls centos7-base-163.repo centos-7.repo epel-7.repo epel.repo epel-testing.repo repo_bak # yum clean all //再次清除系统yum缓存 # yum makecache //重新生成新的yum缓存 # yum repolist enabled //查看系统可用的yum源 # yum repolist all //查看所有yum源
删除旧版本
# yum -y remove php
二. apache
1. 安装apache
# yum install httpd
2. 配置apache
# vim /etc/httpd/conf/httpd.conf //搜索 # addtype application/x-gzip .gz .tgz //然后在后面添加 # addtype application/x-httpd-php .php //搜索 # ifmodule dir_module //在directoryindex下面添加 index.php //修改#servername www.example.com:80 # servername localhost:80
修改默认web站点目录
找到: documentroot "/var/www/html"
修改为: documentroot "/var/www"
找到:
修改为:
3. 启动apache服务
# systemctl start httpd
4. 查看httpd状态
systemctl status httpd
三. php 7.0.7
1. 下载好对应版本的centos的php源码包
php-7.0.7.tar.gz
2. 解压源码包
# tar zxvf php-7.0.7.tar.gz
3. 进入解压包编译安装php所需要的依赖包
# yum install -y gcc gcc-c++ make automake autoconf gd file bison patch mlocate flex diffutils zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers openldap-devellibxslt-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel gmp-devel icu libxslt libxslt-devel php-devel # yum -y install libxslt-devel* # yum -y install perl* # yum -y install httpd-devel # find / -name apxs //得到的路径是:/usr/bin/apxs 编译参数的时候用到,是配置apache支持php的关键参数
4. 编译参数
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--with-gd \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--with-apsx2 \
--disable-fileinfo
6. 编译并安装
# make && make install
7. 安装完查看php版本
# /usr/local/php/bin/php -v
8. 编辑 /etc/profil 添加环境变量
# vim /etc/profil
添加进去
path=$path:/usr/local/php/bin export path
9. 更新环境变量
# source /etc/profile
10. 查看环境变量
# echo $path
11. 查看php版本
# php -v
12. 配置php配置文件php-fpm
# cp php.ini-production /etc/php.ini # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf # cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf # cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm # chmod +x /etc/init.d/php-fpm # vim /usr/local/php/etc/php-fpm.conf # 配置错误日志: # # error_log = /usr/local/php/var/php-fpm.log # # 配置pid文件: # # pid = /usr/local/php/var/run/php-fpm.pid # # 保存退出 # cd /usr/local/src/php-7.2.4 # cp ./sapi/fpm/php-fpm.service 到 /usr/lib/systemd/system/下
13. 启动php-fpm
配置开机启动php-fpm:
# systemctl enable php-fpm
启动php-fpm
# systemctl start php-fpm
查看状态
# systemctl status php-fpm ● php-fpm.service – the php fastcgi process manager loaded: error (reason: invalid argument) active: inactive (dead) dec 13 14:37:27 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/php-fpm.service:7] not an absolute path, ignoring: ${prefix}/va…fpm.pid dec 13 14:37:27 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/php-fpm.service:8] executable path is not absolute, ignoring: $…pm.conf dec 13 14:37:27 localhost.localdomain systemd[1]: php-fpm.service lacks both execstart= and execstop= setting. refusing. dec 13 14:37:27 localhost.localdomain systemd[1]: cannot add dependency job for unit php-fpm.service, ignoring: unit is not loaded properl…gument. hint: some lines were ellipsized, use -l to show in full.
14. 测试php-fpm的配置
#测试php-fpm配置 /usr/local/php/sbin/php-fpm -t /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf -t #启动php-fpm /usr/local/php/sbin/php-fpm /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf #关闭php-fpm kill -int `cat /usr/local/php/var/run/php-fpm.pid` #重启php-fpm kill -usr2 `cat /usr/local/php/var/run/php-fpm.pid`
15. 解决办法
# vim /usr/lib/systemd/system/php-fpm.service
将其中的${prefix}和${exec_prefix}改成/usr/local/php然后保存
//重新启动系统 # reboot
16. 重启apache和php-fpm
# systcl restart httpd # systcl restart php-fpm
17. 安装 对应的xdebug
#复制phpinfo.php整个网页内容,粘贴到https://xdebug.org/wizard.php 确定xdebug版本
根据提示文档进行操作安装
18. yum安装phpmyadmin
# yum install phpmyadmin
修改配置文件
# vi /etc/httpd/conf.d/phpmyadmin.conf
adddefaultcharset utf-8 # apache 2.4 # require ip 127.0.0.1 #注释掉 # require ip ::1 #注释掉 require all granted #新添加 # apache 2.2 order deny,allow deny from all allow from 127.0.0.1 allow from ::1 # apache 2.4 #require ip 127.0.0.1 #注释掉 #require ip ::1 #注释掉 require all granted #新添加 # apache 2.2 order deny,allow deny from all allow from 127.0.0.1 allow from ::1
修改phpmyadmin配置文件
# vi /etc/phpmyadmin/config.inc.php //修改如下内容 # $cfg['servers'][$i]['host'] = '127.0.0.1'; # $cfg['servers'][$i]['user'] = 'root'; # $cfg['servers'][$i]['password'] = '123456';
重启apache
# systemctl restart httpd
安装完mysql后测试
# 浏览器地址栏输入: 服务器ip/phpmyadmin
四. 安装mysql 5.7
1. 安装源
# rpm -uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
2. yum安装mysql
# yum install mysql-community-server
3. 启动mysql
# systemctl start mysqld # systemctl enable mysqld //开机自启
4. 在更改root默认密码前,可以根据需要,关闭密码策略。 如果没有关闭密码策略,则新密码要求是大小写字母+数字+字符的组合。
# vim /etc/my.cnf [mysqld] validate_password = off //重启,使修改后的密码策略生效 # systemctl restart mysqld
5. 修改mysql的root默认密码
//查看默认密码 # grep 'temporary password' /var/log/mysqld.log //默认密码是: )u4fb:kw!evf # 2018-12-18 a temporary password is generated for root@localhost: )u4fb:kw!evf
运行安全设置向导,并修改默认密码
mysql_secure_installation //输入root默认密码 enter password for user root: *** //设置新密码 new password:*** re-enter new password: *** //是否更改root密码 change the password for root ? ((press y|y for yes, any other key for no) ://直接回车,表示no //是否删除匿名用户 remove anonymous users? (press y|y for yes, any other key for no) : y //禁止root远程登录 disallow root login remotely? (press y|y for yes, any other key for no) : y //删除test数据库 remove test database and access to it? (press y|y for yes, any other key for no) : y //重新加载权限表 reload privilege tables now? (press y|y for yes, any other key for no) : y
//也可以使用mysql直接更改root密码 mysql -uroot -p alter user 'root'@'localhost' identified by '新密码'; exit;
//为安全root仅限本地登录,根据需要可以新建一个有管理员权限的远程用户 mysql -uroot -p grant all privileges on *.* to '用户名'@'%' identified by '登录密码' with grant option; flush privileges; exit;
感谢各位的阅读,以上就是“Centos环境怎么安装lamp-php”的内容了,经过本文的学习后,相信大家对Centos环境怎么安装lamp-php这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联网站建设公司,,小编将为大家推送更多相关知识点的文章,欢迎关注!
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流