LAMP之mysql+php

Jun 20, 2016 pm 12:32 PM

接上篇:http://wskfnso.blog.51cto.com/4025557/1761877

二:安装mariadb10.0.24

1:安装mariadb,获取源程序、解压、创建软连接

[root@master1 ~]# tar xf mariadb-10.0.24-linux-x86_64.tar.gz -C /usr/local/

[root@master1 ~]# cd /usr/local/

[root@master1 local]# ln -sv mariadb-10.0.24-linux-x86_64 mysql
`mysql' -> `mariadb-10.0.24-linux-x86_64'

2:创建mysql系统用户和组

[root@master1 local]# groupadd -r mysql
[root@master1 local]# useradd -r -g mysql mysql -s /sbin/nologin

3:建立数据目录 存放数据,并把数据目录改为mysql用户和组

[root@master1 local]# mkdir -pv /mydata/data
[root@master1 local]# chown -R mysql.mysql /mydata/data/

4:安装数据库

[root@master1 mysql]# scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql --basedir=/usr/local/mysql/

5:为mysql 提供配置文件,并修改如下

[root@master1 mysql]# cp support-files/my-large.cnf /etc/my.cnf 

thread_concurrency = 2      //改成cpu的两倍

basedir = /usr/local/mysql   //数据库安装目录
datadir = /mydata/data      //数据目录
innodb_file_per_table = on   //打开innodb引擎
skip_name_resolve = on     //跳过DNS解析

6:提供启动脚本,并使其开机自启动

[root@master1 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

[root@master1 mysql]# chkconfig --add mysqld

[root@master1 mysql]# chkconfig --list mysqld
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off

7:启动mysql

[root@master1 mysql]# service mysqld start

8:修改头文件和库文件

    (1):输出mysql的头文件至系统头文件路径/usr/include:

       # ln -sv /usr/local/mysql/include  /usr/include/mysql

    (2):输出mysql的库文件给系统库查找路径:

       # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf

      而后让系统重新载入系统库:

      # ldconfig

      # ldconfig -p | grep 'mysql'

    (3):修改PATH环境变量,让系统可以直接使用mysql的相关命令

       在/etc/profile.d/目录下建立mysql.sh文件! 写入如下内容:

       export PATH=/usr/local/mysql/bin:$PATH

      # source mysql.sh

 

      # touch /etc/profile.d/mysql.sh

      # echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh

      # source mysql.sh

9:删除密码用户:

mysql> drop user ''@'localhost';

Query OK, 0 rows affected (0.00 sec)


mysql> drop user ''@'localhost.localdomain';

Query OK, 0 rows affected (0.00 sec)


mysql> drop user 'root'@'localhost.localdomain';

Query OK, 0 rows affected (0.00 sec)


mysql> drop user 'root'@'::1';

Query OK, 0 rows affected (0.00 sec)


mysql> set password for 'root'@'localhost'=password('123456');

Query OK, 0 rows affected (0.00 sec)


mysql> set password for 'root'@'127.0.0.1'=password('123456');

Query OK, 0 rows affected (0.00 sec)


三:安装php5.6

说明:

 --enable-maintainer-zts

(1):为了支持apache的worker或event这2个MPM,编译时使用 --enable-maintainer-zts

 (2):如果使用php5.3以上版本,为了连接mysql数据库,可以指定mysqlnd,这样本机就不需要先安装MYSQL或MYSQL开始包了。mysqlnd从php5.3开始可用,可以编译时绑定到它。(而不会和其它具体数据库形成依赖)。

       从php5.4开始就是默认设置。

      # ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqld --with-mysqli=mysqld


LAMP:注意要点:

 apache使用3种方式连接PHP

  (1)module模块方式:使用prefork进程时只用的是libphp5.so模块。如是是工作在work,event线程时用是是libphp5-zts.so

  (2)GGI

   (3):FastCgi  套接字通讯php-fpm


1:安装php

[root@master1 ~]# tar xf php-5.6.18.tar.gz
[root@master1 ~]# cd php-5.6.18

[root@master1 php-5.6.18]# ./configure --prefix=/usr/local/php  --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/httpd/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts

[root@master1 php-5.6.18]# make && make install


2:为php提供配置文件

[root@master1 php-5.6.18]# cp php.ini-production /etc/php.ini

3:编辑apache配置文件httpd.conf.以支持php

    # vim /etc/httpd/httpd.conf

    添加如下内容:

    AddType application/x-httpd-php .php

    AddType application/x-httpd-php-source .phps

4:定为到DirectoryIndex index.html  添加index.php支持php


四:安装 xcache为php加速

1:安装xcache

root@master1 ~]# tar xf xcache-3.2.0.tar.gz

[root@master1 ~]# cd xcache-3.2.0

[root@master1 xcache-3.2.0]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
[root@master1 xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

[root@master1 xcache-3.2.0]# make && make install


安装结束时,会出现类似如下行:

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20131226/


2:整合xcache和php,首先将xcache提供的样例配置导入php.ini

# mkdir /etc/php.d

# cp xcache.ini /etc/php.d 

说明:xcache.ini文件在xcache的源码目录中。


3:接下来编辑/etc/php.d/xcache.ini,找到类似zend_extension开头的行,修改为如下行:

extension = /usr/local/php/lib/php/extensions/no-debug-zts-20131226/xcache.so

注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位

4:httpd 重启载入模块







 


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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1243
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

Explain the difference between self::, parent::, and static:: in PHP OOP. Explain the difference between self::, parent::, and static:: in PHP OOP. Apr 09, 2025 am 12:04 AM

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles