Ubuntu - installing Apache and PHP5 with MySQL support

An Apache install is easy:

apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert

done!

Now that we have Apache installed, we can move onto installing PHP. If you don’t require PHP then please feel free to skip.

PHP5 Install

In this example, I’m not going to install all the modules available. Just some common ones.

To see what modules are available try a:

apt-get search php5-

Note the ‘-’ at the end of ‘php5′. This will show any packages that start with ‘php5-’ and shows the available modules.

Due to using apt-get to install PHP5, any dependencies are taken care of:

This will install php with mysql support:

apt-get install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd \

php5-imagick php5-mcrypt php5-memcache php5-mhash php5-mysql php5-pspell php5-snmp \

php5-sqlite php5-xml php5-xsl

Once done, do a quick Apache reload:

/etc/init.d/apache2 reload

Done!

9 Replies

Nice and quick tutorial, thank you.

Just a couple of corrections:

@routermods:

apt-get search php5-
That should be apt-cache search php5-

@routermods:

php5-xml
That should be php5-xmlrpc

And unless you'll be connecting to an external MySQL server, it's probably a good idea to include apt-get install mysql-server mysql-client in your tutorial as well. Most newbies are going to need it anyway. Perhaps even apt-get install phpmyadmin (but only if you want to keep your web root at /var/www, because that's where Ubuntu installs phpmyadmin by default.)

If you include the following in your apache2.conf you can overcome the problem of placing it in your /var/www:

phpMyAdmin default Apache configuration

Alias /phpmyadmin /usr/share/phpmyadmin

Options Indexes FollowSymLinks

DirectoryIndex index.php

Authorize for setup

# For Apache 1.3 and 2.0

AuthType Basic

AuthName "phpMyAdmin Setup"

AuthUserFile /etc/phpmyadmin/htpasswd.setup

For Apache 2.2

AuthType Basic

AuthName "phpMyAdmin Setup"

AuthUserFile /etc/phpmyadmin/htpasswd.setup

Require valid-user

AddType application/x-httpd-php .php

phpflag magicquotes_gpc Off

phpflag trackvars On

phpflag registerglobals Off

phpvalue includepath .

AddType application/x-httpd-php .php

phpflag magicquotes_gpc Off

phpflag trackvars On

phpflag registerglobals Off

phpvalue includepath .

I do however suggest changing the alias from phpmyadmin to anything else…..(security)

There's also PEAR, which provides some really useful tools.

Install it with sudo apt-get install php-pear If you don't like binaries, you can always get the latest version of the PEAR extensions here and compile it yourself.

One more thing, if you are running anything more than a simple, low-traffic site you should consider caching. I prefer APC (Alternative PHP cache). APC comes with PECL, the sister of the PEAR I've mentioned above.

After installing PECL, you can install APC with sudo pecl install apc

My site http://www.routermods.com it is a blog, I take modest traffic how much would caching speed up wp (wordpress)……also what would it affect: posttime, etc…….can you specify caching time like in ASP or .net?

I have never used asp or .net but I guess (I haven't tested it myself) the posting time shouldn't be affected with a properly configured APC.

So can you configure the caching time?

Among other things, yes you can. You can read more about it here.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct