Home >Backend Development >PHP Problem >How to install php environment variable configuration on mac
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.
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
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 itscross-platform
andsecurity
. It is one of the most popular web server-side software.
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
<h1>It works! </h1> <?php phpinfo(); ?>
$ sudo apachectl restart
http://localhost/info.php
1. Download and install MySql, double-click to install
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.
When the installation is successful, the password prompted for me is3. Start the MySql service
Shortcut key4. Check the MySQL versioncommand Space
key, search MySql through Spotlight, then open and start the service
$ mysql --versionTwo situations may occur here:
MySql version information
, it is because the default access path of the command is incorrect , so you need to add mysql to the system environment variables.
5. Modification passwordCheck whether there is
- mysql
in the
/usr/local/mysql/bindirectory
File$ open /usr/local/mysql/binTwo 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)
$ open ~/.bash_profile 或 $ vim ~/.bash_profileAdd new environment variable
- /usr/local/mysql/bin
directory to the configuration file
$ PATH=$PATH:/usr/local/mysql/binAfter adding the new environment variable, there are two ways to save the configuration file and compile it
快捷键"command + s" ,此方法对应上面提到的"open ~/.bash_profile"编辑环境变量的方式 $ souce ~/.bash_profile # 编译文件 或 先按一下 "esc" 键 ,结束编辑。此方法对应上面提到的"vim ~/.bash_profile"编辑环境变量的方式 $ :wq # 并输入 ":wq" 保存 $ souce ~/.bash_profile # 编译文件
$ 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!