Table of Contents
Welcome to Apache!!
Home php教程 php手册 Linux下Apache+Mysql+PHP的安装与配置

Linux下Apache+Mysql+PHP的安装与配置

Jun 06, 2016 pm 07:45 PM
a linux Install Configuration

(1)Apache的安装与配置 思路:首先在官网下载APACHE源码,本系统下载版本为httpd-2.2.17.tar.gz,下面几步为在终端的配置命令 tar zxvf httpd-2.2.17.tar.gz cd httpd-2.2.17 ./configure --prefix=/usr/local/apache make make install service httpd sta

(1)       Apache的安装与配置

思路:首先在官网下载APACHE源码,本系统下载版本为httpd-2.2.17.tar.gz,下面几步为在终端的配置命令

tar zxvf httpd-2.2.17.tar.gz

cd httpd-2.2.17

./configure --prefix=/usr/local/apache

make

make install

service httpd start

如果出现:

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 222.31.76.227 for ServerName

                                                           [  OK  ]

 

 

 

 说明安装成功!

 

如果希望apache开机自启动的话,可以通过以下命令在/etc/rc.d/rc.local加入自启动命令:

echo "service httpd start">>/etc/rc.d/rc.local

 

测试Apache

/var/www/html目录下建立index.html文件

Welcome to Apache!!

 

 


保存后,在浏览器上输入http://XXX.XXX.XXX.XXX(Web服务器的IP)查看结果

注意:iptables必须关闭或者将80端口加到iptables

 

 

 

 

 

 

 

 

 

(2)       Mysql-client的安装与配置

思路:由于MYSQL没有源码包可以下载,所以本系统使用MYSQL的二进制安装包,使用版本为mysql-5.5.10-linux2.6-x86_64.tar.gz,下面几步为在终端的配置命令(可直接粘贴)

tar zxvf mysql-5.5.10-linux2.6-x86_64.tar.gz

cd /usr/local

ln -s /home/software/mysql-5.5.10-linux2.6-x86_64 mysql

cd mysql/

vi INSTALL-BINARY

看到以下部分为安装步骤

To install and use a MySQL binary distribution, the basic command

sequence looks like this:

shell> groupadd mysql

shell> useradd -r -g mysql mysql

shell> cd /usr/local

shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz

shell> ln -s full-path-to-mysql-VERSION-OS mysql

shell> cd mysql

shell> chown -R mysql .

shell> chgrp -R mysql .

shell> scripts/mysql_install_db --user=mysql

shell> chown -R root .

shell> chown -R mysql data

# Next command is optional

shell> cp support-files/my-medium.cnf /etc/my.cnf

shell> bin/mysqld_safe --user=mysql &

# Next command is optional

shell> cp support-files/mysql.server /etc/init.d/mysql.server   //开机自启动(后面还需几步)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


如果已经安装在安装操作系统时已经安装过MYSQL,那么前6步(高亮部分)目前已经完成

(需要注意的是 data目录下存放的就是一个又一个数据库,所以,必须将权限设置为mysql,否则,mysql本身进不去,配置就会失败)

chown -R mysql.mysql .

scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/

chown -R root .

chown -R mysql data

cp support-files/my-medium.cnf /etc/my.cnf

bin/mysqld_safe --user=mysql &

service mysqld start

若显示:

Starting MySQL..                                           [  OK  ]

则说明mysql已成功启用!

 

使用  mysql_install_db --user=mysql  创建新的MySQL授权表,使用者为mysql

使用 mysqld_safe --user=mysql &     以用户名user_name或数字用户ID user_id运行mysqld服务器。(本文中的“用户”指系统登录账户,而不是 授权表中的MySQL用户)

 

MYSQL自启动

cp support-files/mysql.server /etc/init.d/mysqld

chmod 700 /etc/init.d/mysqld

chkconfig --add mysqld

如果遇到以下问题:

启动MYSQL出错,提示:
Starting mysqld daemon with databases from /usr/local/mysql/data
STOPPING server from pid file /usr/local/mysql/data/xmcncn.pid
061103 15:25:32  mysqld ended
解决方法:
vi /etc/my.cnf
看看[mysqld]下有没有
port  = 3306
添加上就可以了
touch /tmp/mysql.sock
killall -9 mysqld
/usr/local/mysql/bin/mysqld_safe -user=mysql &
成功启动

 

 

 

 

 

 

 

 

 

 

 

 

  

(3)php的安装与配置

首先,安装php前,以下包可能会需要安装:zlib-1.2.3.tar.gz、libpng-1.2.24.tar.gz、freetype-2.3.11.tar.gz、libtool-2.4.tar.gz、jpegsrc.v6b.tar.gz、autoconf-2.61.tar.gz、gd-2.0.35.tar.gz、libxml2-2.7.3.tar.gz

 

在官网下载php源码,本系统下载版本为php-5.3.6.tar,下面几步为在终端的配置命令(可直接粘贴)

cd /home/software/

tar -xvf php-5.3.6.tar

cd php-5.3.6

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-openssl-dir=/usr/lib/openssl --with-openssl

配置后若如下显示License,则说明成功,否侧可能还缺少上述的包。

checking whether -lc should be explicitly linked in... no

checking dynamic linker characteristics... GNU/Linux ld.so

checking how to hardcode library paths into programs... immediate

checking whether stripping libraries is possible... yes

creating libtool

appending configuration tag "CXX" to libtool

 

Generating files

updating cache ./config.cache

creating ./config.status

creating main/internal_functions.c

creating main/internal_functions_cli.c

+----------------------------------------------------------------------------------------+

| License:                                              |

| This software is subject to the PHP License, available in this     |

| distribution in the file LICENSE.  By continuing this installation  |

| process, you are bound by the terms of this license agreement.  |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                        |

+-----------------------------------------------------------------------------------------+

 

Thank you for using PHP.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


make

make test  //可以不做

make install

cp php.ini-development /etc/php.ini

vi /usr/local/apache/conf/httpd.conf

加入一句话:

AddType application/x-httpd-php .php

 

 


cd /var/www/html

vi index.php

新建php测试代码为:

phpinfo();

?>

 

 

 

 

重启apache,重启前要先修改/etc/selinux/config,将SELINUX=enforcing 改成SELINUX=disabled:

vi /etc/selinux/config

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#       enforcing - SELinux security policy is enforced.

#       permissive - SELinux prints warnings instead of enforcing.

#       disabled - SELinux is fully disabled.

SELINUX=disabled

# SELINUXTYPE= type of policy in use. Possible values are:

#       targeted - Only targeted network daemons are protected.

#       strict - Full SELinux protection.

SELINUXTYPE=targeted

 

 

 

 

 

 

 

 

 

 

 


service httpd restart

出现以下语句说明重启成功:

Stopping httpd:                                            [  OK ]

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 222.31.76.227 for ServerName

                                                         [  OK ]

 

 

 

 

 


在浏览器输入http://XXX.XXX.XXX.XXX/index.php,若显示phpinfo信息说明php配置成功。

 

 

 

若能显示phpinfo信息,但发现无法连接数据库(没有MYSQL的信息),说明phpmysql相连的模块包没有安装成功,可尝试下载安装php-mysqlrpm(php-mysql-5.1.6-27.el5.x86_64.rpm),安装它还需先安装php-pdorpm(php-pdo-5.1.6-27.el5.x86_64.rpm)pdo就是专门用于连接phpmysql的。

在以后的web端配置安装时,若phpinfo的基本信息能正常显示,但缺少某个模块功能,可单独下载其对应的rpm包,安装即可。

 

在/var/www/html下新建一个test.php,用于测试连接远程数据库:

Web2

echo "Hello World!";

$db=mysql_connect("远程服务器IP","用户名","password") or die ("mysql connected failed! ");

mysql_select_db("数据库名",$db);

$sql="select * from users";

$result=mysql_fetch_row(mysql_query($sql));

print_r($result);

?>

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

How to install deepseek How to install deepseek Feb 19, 2025 pm 05:48 PM

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

Ouyi okx installation package is directly included Ouyi okx installation package is directly included Feb 21, 2025 pm 08:00 PM

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

Get the gate.io installation package for free Get the gate.io installation package for free Feb 21, 2025 pm 08:21 PM

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

BITGet official website installation (2025 beginner's guide) BITGet official website installation (2025 beginner's guide) Feb 21, 2025 pm 08:42 PM

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Top 10 virtual currency trading app platforms 2025 Top 10 virtual currency trading app platforms latest list Top 10 virtual currency trading app platforms 2025 Top 10 virtual currency trading app platforms latest list Mar 06, 2025 pm 04:21 PM

The top ten virtual currency trading app platforms in 2025 are: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. MEXC Global. The ranking considers factors such as market share, user experience, security, transaction fees, etc., but is for reference only.

Ouyi Exchange Download Official Portal Ouyi Exchange Download Official Portal Feb 21, 2025 pm 07:51 PM

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

See all articles