Home >Backend Development >PHP Problem >How to install php environment variable configuration on mac

How to install php environment variable configuration on mac

藏色散人
藏色散人Original
2021-09-19 09:14:234438browse

How to install the php environment on mac: 1. Open the terminal and enter "$ sudo apachectl start" to start Apache; 2. Copy the "index.html.en" file in the root directory of Apache and rename it to info. php; 3. Install MySql and test the environment.

How to install php environment variable configuration on mac

The operating environment of this article: macOS10.12.5 system, PHP5.6, macbook pro 2020 computer.

How to install php environment variable configuration on mac?

Mac Quickly Configure PHP Running Environment

Directory

  • Start Apache (Mac has built-in Apache service, just start Apache directly Yes)
  • Run PHP (in lay terms, the relationship between Apache and PHP)
  • Configure MySql
  • Use phpMyAdmin (phpMyAdmin is a program developed with PHP to manage MySql)

Start Apache

1. Open the terminal and enter

$ sudo apachectl start

2. You will be prompted to enter the password. Just enter the computer password, and then you can check the Apache version. Enter

$ sudo apachectl -v

3. The version information of Apache will be displayed.

Server version: Apache/2.4.25 (Unix)
Server built:   Feb  6 2017 20:02:10

At this time, enter http://localhost in the browser, and It works! page, indicating that Apache has been started.

Finally, other Apache commands are attached:

$ sudo apachectl stop #关闭Apache服务
$ sudo apachectl restart #重启Apache服务

Note: Apache HTTP Server (referred to as Apache) is a web server software, It can run on almost all widely used computer platforms and is widely used due to its cross-platform and security. It is one of the most popular web server-side software.

Run PHP

1. In the directory /etc/apache2/, find the Apache configuration file httpd.conf file. Use Document Editing to open.

# 终端命令快速进入文件目录 /etc/apache2/
$ open /etc/apache2/

2. Click the Command F shortcut key to search in the document.

#LoadModule php5_module libexec/apache2/libphp5.so

3. Delete the previous comment symbol #.

4. Restart Apache and enter

$ sudo apachectl restart

5 in the terminal. Copy the index.html.en file in the root directory of Apache and rename it to info.php

sudo cp /Library/WebServer/Documents/index.html.en /Library/WebServer/Documents/info.php

6 , open info.php

  • add code
  
      <h1>It works! </h1>
      <?php  phpinfo(); ?> 
  
  • and then restart Apache again
$ sudo apachectl restart
  • Finally enter
http://localhost/info.php
  • in the browser, a page showing php information will appear, which indicates that PHP is ready to use

How to install php environment variable configuration on mac

php information page

Configuring MySql

1. Download and install MySql, double-click to install

How to install php environment variable configuration on mac

MySql

2. Note that a prompt will pop up when the installation is successful. MySql assigns a random password## to your account root. #, write down this password or take a screenshot, it will be used later.

How to install php environment variable configuration on mac

When the installation is successful, the password prompted for me is
3. Start the MySql service

Shortcut key

command Space key, search MySql through Spotlight, then open and start the service

How to install php environment variable configuration on mac

4. Check the MySQL version

$ mysql --version
Two situations may occur here:

    If the installation goes smoothly, the version information of the currently installed MySql will appear

How to install php environment variable configuration on mac

MySql version information

    If it prompts
  • command not found, it is because the default access path of the command is incorrect , so you need to add mysql to the system environment variables.
    Check whether there is
  1. mysql in the /usr/local/mysql/bin directory File
  2. $ open /usr/local/mysql/bin
    Two ways to open the environment variable configuration file (if the following command reports an error, it may be that your Mac does not have this configuration file, you need to create one, the specific operation is Baidu or Google)
  1. $ open ~/.bash_profile 
    或
    $ vim ~/.bash_profile
    Add new environment variable
  1. /usr/local/mysql/bin directory to the configuration file
  2. $ PATH=$PATH:/usr/local/mysql/bin
    After adding the new environment variable, there are two ways to save the configuration file and compile it
  1. 快捷键"command + s" ,此方法对应上面提到的"open ~/.bash_profile"编辑环境变量的方式
    $ souce ~/.bash_profile    # 编译文件
    或
    先按一下 "esc" 键 ,结束编辑。此方法对应上面提到的"vim ~/.bash_profile"编辑环境变量的方式
    $ :wq   # 并输入 ":wq"  保存
    $ souce ~/.bash_profile    # 编译文件

How to install php environment variable configuration on mac

5. Modification password

$ mysql -u root -p # Log in to mysql. After pressing enter in this command, you need to enter the password (this password is prompted when installing MySql.

The above is the detailed content of How to install php environment variable configuration on mac. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn