How to build a PHP development environment under Linux: first obtain the PHP, Apache and MySQL installation packages; then compile, install and modify the configuration file; then set the environment variables and start automatically at boot; finally test whether PHP is successfully installed. Can.
Recommended: "PHP Video Tutorial"
LAMP is a very popular web development environment at the moment. Many developers will encounter various problems in the process of building LAMP. Thinking of these problems, their heads are about to explode. Today, I specially took the time to record the process of building a PHP development environment for everyone's reference. If you find any problems, I hope you can correct them.
1. Obtain the installation package
- PHP download address: http://cn.php.net/distributions/php-7.1.10.tar.gz
- Apache download address: http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.28.tar.gz
- MySQL download address: https://dev.mysql .com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
2. Install Apache
1. Dependencies Package installation
1) Install compiler gcc, gcc-c
yum install -y gcc gcc-c++2) Install dependency packages expat-devel, zlib-devel, openssl-devel
yum install -y expat-devel zlib-devel openssl-devel2) Install dependency package apr
wget http://mirror.bit.edu.cn/apache//apr/apr-1.6.2.tar.gz tar zxvf apr-1.6.2.tar.gz cd apr-1.6.2 ./configure --prefix=/usr/local/apr make && make install3) Install dependency package apr-util
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.0.tar.gz tar zxvf apr-util-1.6.0.tar.gz cd apr-util-1.6.0 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install4) Install dependency package pcre
wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz tar zxvf pcre-8.41.tar.gz cd pcre-8.41 ./configure --prefix=/usr/local/pcre make && make installNote: Copy the apr and apr-util installation packages to the srclib directory of the Apache installation package
Name them apr, apr-util respectively, without the subsequent version number
2. Installation process
1) Unzip the Apache installation package
tar zxvf httpd-2.4.28.tar.gz2) Compile and install
cd httpd-2.4.28 ./configure --prefix=/usr/local/server/apache \ --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr-util \ --with-pcre=/usr/local/pcre \ --enable-so \ --enable-ssl \ --enable-deflate \ --enable-rewrite \ --enable-headers \ --enable-expires \ --disable-cgid\ --disable-cgi make && make install
3. Modify the configuration file httpd.conf
vim /usr/local/server/apache/conf/httpd.confRemove
# in front of ServerName and change the URL after ServerName to localhost:80
4. Add httpd to the system service and set it to start automatically at boot
1) Add httpd to the system service
cp /usr/local/server/apache/bin/apachectl /etc/init.d/httpd2) Modify /etc/init.d/httpd and add the following content to line 3
# chkconfig: 345 85 15 # description: Activates/Deactivates Apache Web ServerNote: The # in the code cannot be removed
3) Set the system service to start automatically at boot
systemctl enable httpd4) Start Apache
service httpd start
3. Install MySQL
1. Preparation before installation
1) Unzip the installation package
tar zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz mv mysql-5.7.19-linux-glibc2.12-x86_64 /usr/local/server/mysql2) Create users and user groups and assign corresponding permissions
groupadd mysql useradd -r -g mysql mysql -s /sbin/nologin3) Install dependencies
yum -y install numactl.x86_64
2. Initialize mysql and make basic configuration
1) Initialize mysql
cd /usr/local/server/mysql bin/mysqld \ --initialize \ --user=mysql \ --basedir=/usr/local/server/mysql \ --datadir=/usr/local/server/mysql/data \2) Configure mysql
vim my.cnf # 创建配置文件This example only ensures that mysql can run normally. For more configuration, please refer to the official documentation
[mysqld] skip-grant-tables basedir = /usr/local/server/mysql datadir = /usr/local/server/mysql/data socket = /usr/local/server/mysql/data/mysql.sock log-error = /usr/local/server/mysql/log/error.log port = 3306 [mysql_safe] pid-file = /var/run/mysql/mysqld.pid log-error = /usr/local/server/mysql/log/error.log [client] port = 3306 socket = /usr/local/server/mysql/data/mysql.sockSoft link the configuration file to the /etc/ directory
ln -s /usr/local/server/mysql/my.cnf /etc/my.cnfNote: If you are prompted that the file exists when creating a soft link, you can delete /etc/my.cnf and then create a soft link
3) Create a database to store information Required Directories and Files
mkdir /usr/local/server/mysql/data mkdir /usr/local/server/mysql/log mkdir /var/run/mysql touch /usr/local/server/mysql/log/error.log4) Set directory owner
chown -R mysql:mysql /usr/local/server/mysql/ chown -R mysql:mysql /var/run/mysql/
3. Set environment variables and auto-start at boot
1) Set environment variables
Edit profile file
vim /etc/profileAdd the following information to the end of profile
export PATH=$PATH:/usr/local/server/mysql/binMake environment variables take effect immediately
source /etc/profile2) Set up auto-start at boot
cp support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on
4. Firewall settings
CentOS has the firewall enabled by default. Below we use firewall to open the 3306l port
1) Before we enable it First check whether port 3306 is open
firewall-cmd --query-port=3306/tcp2) If it is not turned on, turn on the firewall firewall
systemctl start firewalld.service3) We can choose to temporarily open or permanently open port 3306
firewall-cmd --add-port=3306/tcp # 临时开启3306端口 firewall-cmd --permanent --zone=public --add-port=3306/tcp # 永久开启3306端口4) Restart firewall
firewall-cmd --reload
5. Start mysql and set the root user password
1) Start mysql
/usr/local/server/mysql/support-files/mysql.server start # 启动MySQL /usr/local/server/mysql/bin/mysql -uroot -p # 这里直接回车,无须输入密码2) Set root user password
use mysql; update user set authentication_string=password('root') where user='root'; exit;Note 1: After successfully changing the password, log out of skip-grant-tables in the configuration file
Restart mysql and log in again using the root user, and then execute the following code
set password=password('root');Note 2: It is a system requirement to reset the password for the second time, otherwise the database cannot be operated
6. Remote access
1) Give access to any host mysql permissions
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;2) Make permission modification take effect
FLUSH PRIVILEGES;
4. Install PHP
1. Installation steps
1) Install the dependency package libxml-devel
yum -y install libxml2-devel2) Unzip the PHP installation package
tar zxvf php-7.1.10.tar.gz3) Compile and install
cd php-7.1.10 ./configure --prefix=/usr/local/server/php \ --with-apxs2=/usr/local/server/apache/bin/apxs \ --with-config-file-path=/usr/local/server/php \ --with-pdo-mysql make && make install
2. Configure php.ini
1) Copy the configuration file to the PHP installation directory
cp php.ini-* /usr/local/server/php/2) Generate php.ini
cp php.ini-development /usr/local/server/php/php.ini
3. Modify httpd.conf
载入PHP模块,如httpd.conf中有下列代码则直接去掉前面#即可,没有则加入
LoadModule php7_module modules/libphp7.so在底部加入以下代码使得Apache可以解析php文件
<ifmodule> AddType application/x-httpd-php .php </ifmodule>找到如下代码,在index.html后面加入index.php
<ifmodule> DirectoryIndex index.html </ifmodule>重启Apache
service httpd restart
4. 测试PHP是否成功安装
创建/usr/local/server/apache/htdocs/index.php
vim /usr/local/server/apache/htdocs/index.php在index.php中编写以下代码
<?php phpinfo(); ?>如果出现以下页面则安装成功
The above is the detailed content of Setting up PHP development environment under Linux. For more information, please follow other related articles on the PHP Chinese website!

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。

手机远程linux工具有:1、JuiceSSH,是一款功能强大的安卓SSH客户端应用,可直接对linux服务进行管理;2、Termius,可以利用手机来连接Linux服务器;3、Termux,一个强大的远程终端工具;4、向日葵远程控制等等。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool