How to install PHP on CentOS

本文提供了一套详细的指南,教你如何在Linux环境下安装PHP,并进行基本的配置优化以提升其性能。包括增加脚本内存限制、调整最大执行时间、设置上传文件大小限制等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PHP

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.  For more information on PHP, visit their website atwww.php.net (link is external).

Version

This documentation was written for PHP 5.1.6 but may be usefull with other versions.

How to install PHP

  1. Run the yum install command
yum install php
yum install php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml php-pdo


How to configure PHP

  1. Increase PHP script memory limit
    In the /etc/php.ini file replace memory_limit = 16M withmemory_limit = 128M
  2. Increase PHP script max execution time
    In the /etc/php.ini file replace max_execution_time = 30 withmax_execution_time = 120
  3. Increase PHP script max upload size
    In the /etc/php.ini file replace max_upload_size = 2M withmax_upload_size = 50M
    In the /etc/php.ini file replace post_max_size = 8M withpost_max_size = 50M
  4. Create the /usr/share/phpinfo folder
    mkdir /usr/share/phpinfo
  5. Create the /usr/share/phpinfo/index.php file with the following text:
    <?php
      phpinfo();
    ?>
  6. Change permissions on the index.php file
    chmod 0755 /usr/share/phpinfo/index.php
  7. Create the /etc/httpd/conf.d/phpinfo.conf file with the following text:
    # phpinfo - PHP utility function for displaying php configuration
    #
    # Allows only localhost by default

    Alias /phpinfo /usr/share/phpinfo
    <Directory /usr/share/phpinfo/>
       order deny,allow
       deny from all
       allow from 127.0.0.1
    </Directory>
  8. Restart Apache Server
    service httpd restart

Test

Visit localhost/phpinfo in your web browser. You should see the infamous phpinfo output. If the address bar changes to somthing other thanhttp://localhost/phpinfo/ (link is external), than somthing went wrong while following the instructions and your browser has interpreted this as a search. Try following the instruction again. If it still doesn't work, send me an email via my contact page and let me know somthing isn't working right. If it did work, you have successfully installed PHP.



http://dev.antoinesolutions.com/php

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值