美文网首页我爱编程
服务器开发之路五:PHP环境搭建

服务器开发之路五:PHP环境搭建

作者: 冯文议 | 来源:发表于2018-05-23 17:15 被阅读55次

    我一直觉得PHP代码写起来还是很简单,但因为与服务器,数据库耦合度太高,环境搭建还是挺麻烦的,不管是在Window系统还是Linux系统。还好有集成化工具,不过还是会出现一些问题。

    这里仅做记录。

    XAMPP

    官网网址:https://www.apachefriends.org/index.html

    1、安装:
    ./xampp-linux-XXX.run

    在安装过程中会让你选择安装位置,默认在/opt目录下

    2、进入主目录:
    cd /opt/lampp

    3、运行命令

    服务

    ./lampp start | stop | status | restart

    mysql

    ./lampp startmysql | stopmysql

    4、安全

    设置密码

    ./lampp security

    XAMPP: Quick security check...
    
    XAMPP: MySQL is accessable via network.
    
    XAMPP: Normaly that's not recommended. Do you want me to turn it off? [yes] yes
    
    XAMPP: Turned off.
    
    XAMPP: Stopping MySQL...
    
    XAMPP: Starting MySQL...
    
    XAMPP: The MySQL/phpMyAdmin user pma has no password set!!!
    
    XAMPP: Do you want to set a password? [yes] yes
    
    XAMPP: Password: ******
    
    XAMPP: Password (again): ******
    
    XAMPP: Setting new MySQL pma password.
    
    XAMPP: Setting phpMyAdmin's pma password to the new one.
    
    XAMPP: MySQL has no root passwort set!!!
    
    XAMPP: Do you want to set a password? [yes] yes
    
    XAMPP: Write the passworde somewhere down to make sure you won't forget it!!!
    
    XAMPP: Password: ******
    
    XAMPP: Password (again): ******
    
    XAMPP: Setting new MySQL root password.
    
    XAMPP: Setting phpMyAdmin's root password to the new one.
    
    XAMPP: The FTP password for user 'nobody' is still set to 'lampp'.
    
    XAMPP: Do you want to change the password? [yes] yes
    
    XAMPP: Password: ******
    
    XAMPP: Password (again): ******
    
    XAMPP: Reload ProFTPD...
    
    XAMPP: Done.
    

    5、让局域网访问

    Require local 注释掉,添加 Require all granted

    6、mysql 远程访问

    use mysql

    grant all privileges on . to root@'%' identified by "password";
    // 你也可以修改表

    flush privileges;

    7、浏览技巧

    /dashboard/faq.html
    常见问题介绍,相当于快速入门

    /dashboard/howto.html
    专项问题解读,比如数据,虚拟主机,在这里面,你能找到详细答案

    8、问题

    我的问题主要在mysql这一块,PHP可以连接mysql,但是其他不行,也没有开启3306这个端口

    不用它的mysql,安装其他mysql,PHP又不能用。

    phpstudy

    最开始用他最大的原因是可以外网访问。

    phpstudy for linux版环境安装
    本文主要和大家分享PHP环境安装-phpstudy for linux版,希望能帮助到大家。
    
    下载地址:
    
    下载版:http://lamp.phpstudy.net/phpstudy.bin
    
    完整版:http://lamp.phpstudy.net/phpstudy-all.bin
    
    PHP环境支持:
    
    解释:Apache/Nginx/Tengine/Lighttpd
    
    PHP版本:支持php5.2/5.3/5.4/5.5切换
    
    操作系统:已经在centos-6.5,debian-7.4.,ubuntu-13.10测试成功
    
    安装方法:
    
    下载好 .bin 文件
    
    cd到下载目录
    
    chmod +x ./phpstudy.bin 给权限
    
    然后在终端中运行 ./phpstudy.bin
    
    等待编译完成
    
    使用方法
    
    在终端中使用sudo 或者 使用管理员账号运行 phpstudy start 开启
    
    命令列表:
    
    phpstudy start | stop | restart 开启 | 停止 | 重启
    
    phpstudy add | del | list 添加虚拟主机 | 删除虚拟主机 | 查看虚拟主机列表
    
    注:添加或删除过虚拟主机域名,需要重新修改host文件配置,(sudo vim /etc/hosts)
    
    phpstudy ftp add | del | list
    
    配置文件地址
    
    apache配置文件:/phpstudy/server/httpd/conf/httpd.conf
    
    PHP配置文件:/phpstudy/server/php/etc/php.ini
    
    打开Mysql控制台
    
    /phpstudy/mysql/bin/mysql -uroot -proot
    

    手动搭建LAMP环境

    安装Apache

    1、通过yum源安装以httpd开头的命名的软件包,在命令行下输入:

    yum install httpd

    2、然后根据提示输入相应的命令进行安装操作

    3、一些命令

    #启动apache
    systemctl start httpd.service 
    
    #停止apache
    systemctl stop httpd.service 
    
    #重启apache
    systemctl restart httpd.service 
    
    #设置apache开机启动
    systemctl enable httpd.service 
    
    • 安装MariaDB

    1、命令行下输入:yum install mariadb mariadb-server

    2、依旧是根据提示输入相关命令进行安装操作

    3、一些命令

    systemctl start mariadb.service #启动MariaDB
    
    systemctl stop mariadb.service #停止MariaDB
    
    systemctl restart mariadb.service #重启MariaDB
    
    systemctl enable mariadb.service #设置开机启动
    

    4、拷贝配置文件:

    cp /usr/share/mysql/my-huge.cnf /etc/my.cnf

    5、为root账户设置密码

    输入:

    mysql_secure_installation

    根据提示输入Y,输入2次密码,根据提示一路输入Y,最后出现:Thanks for using MySQL!

    MySql密码设置完成,重新启动 MySQL:

    重启MariaDB输入:

    systemctl restart mariadb.service

    • 安装PHP

    1、命令行下输入

    yum install php

    回车开始安装

    2、安装PHP组件,使PHP支持 MariaDB

    命令行下输入:

    yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

    3、然后你需要重启

    #重启MariaDB
    systemctl restart mariadb.service 
    
    #重启apache
    systemctl restart httpd.service 
    

    资料

    1、CentOS 7.0 如何安装LAMP服务器方法

    相关文章

      网友评论

        本文标题:服务器开发之路五:PHP环境搭建

        本文链接:https://www.haomeiwen.com/subject/troljftx.html