How to build a PHP development environment under Linux: first install apache and start it; then install PHP's dependent software; then install PHP through the command "make && make install"; and finally restart apache.
Recommended: "PHP Video Tutorial"
Complete Tutorial on Building a PHP Development Environment under Linux
Before getting into the topic, let’s popularize some basic knowledge. In a Linux environment, errors may occur when we install software through the command line. When an error occurs, how do we undo the previous steps and reinstall the software? The solution is as follows
(1) The configure operation has been executed
Solution: Reconfigure according to the correct parameters
(2) The configure and make operations have been executed
Solution: Delete the decompressed file directory, re-decompress, configure, make
(3) Configure, make, make install operations have been executed
Solution: First delete the installed files (If you specify the installation directory /usr/local/http2), then delete the decompressed directory, and finally re-decompress, configure, make, and make install. Okay, let’s get down to business.
1. Install apache
1. Configuration (apache installation configuration) Remember to switch to root before installation, otherwise the installation will fail due to permission issues
./configure --prefix=/usr/local/http2 \ --enable-modules=all \ --enable-mods-shared=all \ --enable-so
// -- enable-mods-shared=all module sharing type, compile all modules into apache at one time
Execute ./configure --help to view the default configuration and configuration help information, such as installation directory--prefix, etc.
2. Installation
Execute make && make install to complete the installation
3. Start apache
Enter the installation directory/usr/local/http2/bin
Execute the command ./apachectl start to start apache
When starting apache, you may be prompted Could not reliably determine the server's fully...
In fact, this is not an error , can be ignored, or you can solve this problem by modifying the configuration file,
Enter the installation directory, /usr/local/http2/conf/, find httpd.conf, and search for ServerName in the file,
Just remove the # sign in front of it.
4. Visit
After the installation is completed, enter the local IP address in the browser to access the apache default page
For example, enter the local IP address: 192.168 .0.141
2. Install php dependent software
Now you need to install some software that php depends on (xml, gd, jpeg, png, freetype), and then you can install php.
1. Install xml dependencies
Download libxml2, and then install it
Configuration before installation: ./configure --prefix=/usr/local/libxml2 --without-zlib
Then make&&make install
2. Install jpeg8
Configure before installation./configure --prefix=/usr/local/jpeg --enable-share --enable- static
Then make && make install
--enable-share compiles all the function library programs required by jpeg into the software, so that the function calling speed is fast, but the software itself is relatively large
--enable-static static introduction method, so that when a function that has not yet been introduced needs to be called, it will be included immediately. In this way, the software itself is smaller, but the function calling speed is slow
3. Install libpng
./configure && make && make install
4. Install the freetype library (font library)
./configure --prefix=/usr/local/freetype make && make install
5. Install the GD library
gd library download address: https://bitbucket.org/libgd/gd -libgd/downloads
./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg/ --with-png --with-zlib --with-freetype=/usr/local/freetype make && make install
6. Install libXpm-3.5.10
// 有的系统可能没安装这个,要自己安装
Just use the default configuration
./configure make && make instsall
3. Install and configure php
1. Install php
Parameter analysis:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/http2/bin/apxs
apache support, function: generate php module for apache; modify the configuration file of /usr/local/http2/conf/httpd.conf, so that The introduction of the php module
mysqlnd means activating and using the mysql driver of php itself. Since we have not installed mysql ourselves, the default mysql can be used.
--enable-mbstring=all Wide byte function library support for php
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/http2/bin/apxs --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir=/usr/local/freetype --with-gd=/usr/local/gd --with-zlib --with-libxml-dir=/usr/local/libxml2 --with-jpeg-dir=/usr/local/jpeg --with-png-dir --with-xpm-dir=/usr/local/libxpm --enable-mbstring=all --enable-mbregex --enable-shared
After the configuration is completed, install make && make install
After the installation is successful, there will be As shown below
License: This software is subject to the PHP License, ... at this point. +---------------------------------------------------------------+ Thank you for using PHP.
After the PHP installation is completed, /usr/local/http2/conf/httpd.conf will introduce the corresponding php module, such as
LoadModule php5_module modules/libphp5.so
.... ...
2. After the installation is complete, make relevant settings
Extract the php.ini configuration file in the php directory to the specified directory
cp php.ini-development /usr/local/php/lib/php.ini
3. Configure Apache to support php
vim /usr/local/http2/conf/httpd.conf
(1) Add
AddType application/x-httpd-php .php
Enable apache to know how to call the php module to parse when encountering a php file
(2) Set the time zone
Modify the php.ini configuration file in /usr/local/php/lib and set Time zone
data.timezone = PRC (remember to remove the previous ones)
After the setting is completed, restart the apache server
/usr/local/http2/bin/apachectl restart
至此所有安装步骤完成,在 apache 的目录下(/usr/local/apache2/htdocs)写个测试文件如 test.php
内容:
<?php phpinfo(); ?>
然后在浏览器中访问:192.168.0.141/test.php
如果访问成功,说明安装配置成功
注意:在使用 ThinkPHP 的时候,可能会出现下面这个问题
thinkphp开发的项目访问的时候出现了 页面错误!请稍后再试~ 排查了很多原因,最终是这样的解决的:
开启debug模式。在入口文件处加上 define(‘APP_DEBUG‘, true); 就ok了
此外,在系统目录下创建的文件夹,没有写权限,要修改文件夹权限才能写入,才能正常访问,如
chmod -R 777 thinkphp(即让该文件夹及其所有子文件夹可读可写可执行)
四、安装配置 mysql
1. 安装 cmake(更先进的 configure)
解压后执行配置命令 ./bootstrap,配置完成后 make && make install,要以 root 权限安装 。
2. 安装 mysql
tar zxvf mysql**** cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
(安装目录, 数据存储目录, 默认的字符集, 校对字符集 )
然后 make && make install
在进行 mysql 的 configure 操作的时候,可能会提示软件依赖错误,依赖文件 libncurses5-dev
解决方法:安装 ncurses-devel
rpm -ivh ncurses-devel-5.7-3.200090208.el6.i686.rpm(现在可能不是这个文件名了,自己 google 吧)
依赖解决好后要删除 CMakeCache.txt 文件。
3. 配置 mysql
(1)给 mysql 复制一个配置文件
在 mysql 我解压目录下,有个 support-files 文件夹,进入这个文件夹,执行复制命令
cp my-medium.cnf /etc/my.cnf
(2)useradd mysql(添加用户)
(3)chmod +x /home/lion/storm/web-php/install/mysql5.5/install
(4)chown -R mysql.mysql /home/lion/storm/web-php/install/mysql5.5/install
(5)初始化 mysql 数据库
/home/lion/storm/web-php/install/mysql5.5/install/scripts/mysql_install_db --user=mysql --basedir=/home/lion/storm/web-php/install/mysql5.5/install --datadir=/home/lion/storm/web-php/install/mysql5.5/install/data &
(6)把 mysql 安装文件(除了 data 之外)的主人都改为 root,避免数据库恢复为出厂设置
chown -R root /home/lion/storm/web-php/install/mysql5.5/install chown -R mysql /home/lion/storm/web-php/install/mysql5.5/install/data
(7)后台运行 mysql 服务
/home/lion/storm/web-php/install/mysql5.5/install/bin/mysqld_safe --user=mysql &
查看 mysql 是否有启动
ps -A | grep mysql
如果启动成功,则显示以下信息
------ mysqld_safe ------ mysqld
(8)进入 mysql 操作终端的执行程序(在 /home/lion/storm/web-php/install/mysql5.5/install/bin 目录下)
执行命令 ./mysql 就可以运往 mysql 了。
(9)设置 mysql 用户和密码
为了数据库安全,把 localhost 之外的用户全部删除掉,并为 localhost 设置密码,设置密码时调用加密函数给密码加密;
mysql 的所有用户信息都放在 mysql 数据库中,而且这也是 mysql 的核心数据库 。所以要到这个数据库中进行用户管理操作,执行命令
use mysql
切换到这个数据库,执行下面的操作:
mysql> delete from user where Host != 'localhost'; mysql> select Host, User, Password form user; mysql> update user set Password=password(123456); mysql> select Host, User, Password from user; mysql> flush privileges;(刷新,使对权限的修改立即生效)
(10)设置完成后,执行 flush privileges; 命令,使设置立即生效 。设置完成后,以后不要随便操作 mysql 中的 mysql 数据库了 。
(11)执行 exit 命令退出当前 mysql,然后重新登录 mysql
./mysql -uroot -p123456
(12)通过 php 中访问 mysql,在 apache 的 htdocs 目录下,创建一个 data.php 文件,来访问 mysql 。
<?php $link = mysql_connect('localhost', 'root', '123456'); mysql_select_db('test', $link); mysql_query('set name utf8'); $sql = "select * from goods"; $qry = mysql_query($sql); while($rst = mysql_fetch_assoc($qry)) { print_r($rst); echo "<br />"; }
The above is the detailed content of How to set up a php development environment under linux. For more information, please follow other related articles on the PHP Chinese website!